@kokimoki/app 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kokimoki-client.d.ts +10 -3
- package/dist/kokimoki-client.js +64 -1
- package/dist/types/events.d.ts +4 -0
- package/dist/types/events.js +1 -0
- package/package.json +1 -1
|
@@ -3,9 +3,7 @@ import type TypedEmitter from "typed-emitter";
|
|
|
3
3
|
import type { SyncedStore } from "./synced-store";
|
|
4
4
|
import type { DocTypeDescription } from "@syncedstore/core/types/doc";
|
|
5
5
|
import type { UploadedMedia } from "./types/api";
|
|
6
|
-
|
|
7
|
-
stateless: (room: string, from: string, data: T) => void;
|
|
8
|
-
};
|
|
6
|
+
import type { KokimokiClientEvents } from "./types/events";
|
|
9
7
|
declare const KokimokiClient_base: new <T>() => TypedEmitter<KokimokiClientEvents<T>>;
|
|
10
8
|
export declare class KokimokiClient<StatelessDataT = any> extends KokimokiClient_base<StatelessDataT> {
|
|
11
9
|
readonly appId: string;
|
|
@@ -26,5 +24,14 @@ export declare class KokimokiClient<StatelessDataT = any> extends KokimokiClient
|
|
|
26
24
|
sendStatelessToClient(room: string, clientId: string, data: StatelessDataT): void;
|
|
27
25
|
sendStatelessToRoom(room: string, data: StatelessDataT, self?: boolean): void;
|
|
28
26
|
mediaUpload(blob: Blob): Promise<UploadedMedia>;
|
|
27
|
+
private _facingMode;
|
|
28
|
+
private _stream;
|
|
29
|
+
private _mediaRequests;
|
|
30
|
+
requestMediaStream(): void;
|
|
31
|
+
releaseMediaStream(): void;
|
|
32
|
+
private closeMediaStream;
|
|
33
|
+
private updateMediaStream;
|
|
34
|
+
setFacingMode(facingMode: "user" | "environment"): void;
|
|
35
|
+
toggleFacingMode(): void;
|
|
29
36
|
}
|
|
30
37
|
export {};
|
package/dist/kokimoki-client.js
CHANGED
|
@@ -46,7 +46,6 @@ export class KokimokiClient extends EventEmitter {
|
|
|
46
46
|
this._token = appToken;
|
|
47
47
|
this.serverTimeOffset = Date.now() - serverTime - ping;
|
|
48
48
|
localStorage.setItem("KM_TOKEN", token);
|
|
49
|
-
console.log("READY!", token);
|
|
50
49
|
}
|
|
51
50
|
async setProvider(name, store) {
|
|
52
51
|
const provider = new HocuspocusProvider({
|
|
@@ -113,4 +112,68 @@ export class KokimokiClient extends EventEmitter {
|
|
|
113
112
|
throw new Error(`Error while uploading media: ${errorMessage(error)}`);
|
|
114
113
|
}
|
|
115
114
|
}
|
|
115
|
+
// User media
|
|
116
|
+
_facingMode = "environment";
|
|
117
|
+
_stream = null;
|
|
118
|
+
_mediaRequests = 0;
|
|
119
|
+
requestMediaStream() {
|
|
120
|
+
this._mediaRequests++;
|
|
121
|
+
this.updateMediaStream();
|
|
122
|
+
}
|
|
123
|
+
releaseMediaStream() {
|
|
124
|
+
this._mediaRequests--;
|
|
125
|
+
if (this._mediaRequests <= 0) {
|
|
126
|
+
this.closeMediaStream();
|
|
127
|
+
this._mediaRequests = 0;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
closeMediaStream() {
|
|
131
|
+
if (!this._stream) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
// @ts-ignore
|
|
135
|
+
this.emit("media-stream", {
|
|
136
|
+
error: null,
|
|
137
|
+
facingMode: this._facingMode,
|
|
138
|
+
stream: null,
|
|
139
|
+
});
|
|
140
|
+
this._stream.getTracks().forEach((track) => track.stop());
|
|
141
|
+
this._stream = null;
|
|
142
|
+
}
|
|
143
|
+
async updateMediaStream() {
|
|
144
|
+
this.closeMediaStream();
|
|
145
|
+
try {
|
|
146
|
+
this._stream = await navigator.mediaDevices.getUserMedia({
|
|
147
|
+
video: {
|
|
148
|
+
facingMode: this._facingMode,
|
|
149
|
+
frameRate: { ideal: 24, max: 30 },
|
|
150
|
+
},
|
|
151
|
+
audio: true,
|
|
152
|
+
});
|
|
153
|
+
this.emit("media-stream", null, this._facingMode, this._stream);
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
this._stream = null;
|
|
157
|
+
if ((err + "").match(/^NotReadableError/)) {
|
|
158
|
+
await new Promise((resolve) => {
|
|
159
|
+
setTimeout(async () => {
|
|
160
|
+
await this.updateMediaStream();
|
|
161
|
+
resolve();
|
|
162
|
+
}, 1000);
|
|
163
|
+
});
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
this.emit("media-stream", err + "", this._facingMode, null);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
setFacingMode(facingMode) {
|
|
170
|
+
if (this._facingMode === facingMode) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
this._facingMode = facingMode;
|
|
174
|
+
this.updateMediaStream();
|
|
175
|
+
}
|
|
176
|
+
toggleFacingMode() {
|
|
177
|
+
this.setFacingMode(this._facingMode === "user" ? "environment" : "user");
|
|
178
|
+
}
|
|
116
179
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|