@pmate/chat-sdk 0.6.0 → 0.6.2
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/lib/runtime/call.d.ts +3 -0
- package/lib/runtime/call.js +27 -3
- package/package.json +2 -3
- package/dist/assets/ChatInput.stories-BQcIQDVE.js +0 -1852
- package/dist/assets/Color-AVL7NMMY-Q9rY0eHd.js +0 -1
- package/dist/assets/DocsRenderer-PQXLIZUC-B5DlnesB.js +0 -1243
- package/dist/assets/client-DTiYOHAb.js +0 -9
- package/dist/assets/iframe-1QrxCBqr.js +0 -1071
- package/dist/assets/iframe-4FbYaDjf.css +0 -1
- package/dist/assets/index-CkqBtKlT.js +0 -1
- package/dist/assets/preload-helper-PPVm8Dsz.js +0 -1
- package/dist/assets/react-18-6BKf31wF.js +0 -1
- package/dist/favicon-wrapper.svg +0 -46
- package/dist/favicon.svg +0 -1
- package/dist/iframe.html +0 -687
- package/dist/index.html +0 -148
- package/dist/index.json +0 -1
- package/dist/nunito-sans-bold-italic.woff2 +0 -0
- package/dist/nunito-sans-bold.woff2 +0 -0
- package/dist/nunito-sans-italic.woff2 +0 -0
- package/dist/nunito-sans-regular.woff2 +0 -0
- package/dist/project.json +0 -1
- package/dist/sb-addons/docs-1/manager-bundle.js +0 -151
- package/dist/sb-addons/docs-1/manager-bundle.js.LEGAL.txt +0 -0
- package/dist/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js +0 -971
- package/dist/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js.LEGAL.txt +0 -0
- package/dist/sb-common-assets/favicon-wrapper.svg +0 -46
- package/dist/sb-common-assets/favicon.svg +0 -1
- package/dist/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
- package/dist/sb-common-assets/nunito-sans-bold.woff2 +0 -0
- package/dist/sb-common-assets/nunito-sans-italic.woff2 +0 -0
- package/dist/sb-common-assets/nunito-sans-regular.woff2 +0 -0
- package/dist/sb-manager/globals-module-info.js +0 -799
- package/dist/sb-manager/globals-runtime.js +0 -69791
- package/dist/sb-manager/globals.js +0 -34
- package/dist/sb-manager/runtime.js +0 -13198
- package/dist/vite-inject-mocker-entry.js +0 -2
package/lib/runtime/call.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export type CallPhase = "idle" | "requesting" | "ringing" | "incoming" | "connec
|
|
|
2
2
|
export type CallSnapshot = {
|
|
3
3
|
phase: CallPhase;
|
|
4
4
|
ready: boolean;
|
|
5
|
+
watchedPeerId?: string;
|
|
6
|
+
peerOnline?: boolean;
|
|
5
7
|
callId?: string;
|
|
6
8
|
peerId?: string;
|
|
7
9
|
direction?: "incoming" | "outgoing";
|
|
@@ -54,6 +56,7 @@ export declare class CallClient {
|
|
|
54
56
|
snapshot(): CallSnapshot;
|
|
55
57
|
subscribe(listener: (state: CallSnapshot) => void): () => void;
|
|
56
58
|
connect(): void;
|
|
59
|
+
watchPeer(peerId?: string): void;
|
|
57
60
|
start(peerId: string): Promise<void>;
|
|
58
61
|
accept(): Promise<void>;
|
|
59
62
|
hangup(): void;
|
package/lib/runtime/call.js
CHANGED
|
@@ -32,8 +32,18 @@ export class CallClient {
|
|
|
32
32
|
ws.onmessage = event => {
|
|
33
33
|
if (this.ws !== ws)
|
|
34
34
|
return;
|
|
35
|
-
this.queue = this.queue.then(async () => {
|
|
36
|
-
|
|
35
|
+
this.queue = this.queue.then(async () => {
|
|
36
|
+
if (this.ws !== ws)
|
|
37
|
+
return;
|
|
38
|
+
const gen = this.generation;
|
|
39
|
+
try {
|
|
40
|
+
await this.receive(JSON.parse(String(event.data)));
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
if (gen === this.generation)
|
|
44
|
+
this.fail("CONNECTION_FAILED");
|
|
45
|
+
}
|
|
46
|
+
});
|
|
37
47
|
};
|
|
38
48
|
ws.onerror = () => { };
|
|
39
49
|
ws.onclose = event => {
|
|
@@ -43,11 +53,16 @@ export class CallClient {
|
|
|
43
53
|
clearInterval(this.heartbeat);
|
|
44
54
|
const active = !["idle", "ended"].includes(this.state.phase);
|
|
45
55
|
this.release();
|
|
46
|
-
this.update({ ready: false, phase: active ? "ended" : this.state.phase, error: event.code === 1008 ? "UNAUTHORIZED" : "DISCONNECTED" });
|
|
56
|
+
this.update({ ready: false, peerOnline: undefined, phase: active ? "ended" : this.state.phase, error: event.code === 1008 ? "UNAUTHORIZED" : "DISCONNECTED" });
|
|
47
57
|
if (!this.closed && event.code !== 1008)
|
|
48
58
|
this.reconnect = setTimeout(() => this.connect(), 3000);
|
|
49
59
|
};
|
|
50
60
|
}
|
|
61
|
+
watchPeer(peerId) {
|
|
62
|
+
this.update({ watchedPeerId: peerId, peerOnline: undefined });
|
|
63
|
+
if (this.state.ready)
|
|
64
|
+
this.send({ type: "presence.watch", peerId: peerId ?? "" });
|
|
65
|
+
}
|
|
51
66
|
async start(peerId) {
|
|
52
67
|
if (!this.state.ready || !["idle", "ended"].includes(this.state.phase))
|
|
53
68
|
return;
|
|
@@ -175,6 +190,8 @@ export class CallClient {
|
|
|
175
190
|
return false;
|
|
176
191
|
}
|
|
177
192
|
this.microphone = stream;
|
|
193
|
+
stream.getAudioTracks().forEach(track => { track.onended = () => { if (gen === this.generation)
|
|
194
|
+
this.fail("MICROPHONE_DENIED"); }; });
|
|
178
195
|
return true;
|
|
179
196
|
}
|
|
180
197
|
armTimeout(ms) { clearTimeout(this.timeout); this.timeout = setTimeout(() => this.fail("CONNECTION_TIMEOUT"), ms); }
|
|
@@ -196,10 +213,17 @@ export class CallClient {
|
|
|
196
213
|
async receive(message) {
|
|
197
214
|
if (message.type === "ready") {
|
|
198
215
|
this.update({ ready: true, error: undefined });
|
|
216
|
+
if (this.state.watchedPeerId)
|
|
217
|
+
this.send({ type: "presence.watch", peerId: this.state.watchedPeerId });
|
|
199
218
|
clearInterval(this.heartbeat);
|
|
200
219
|
this.heartbeat = setInterval(() => this.send({ type: "ping" }), 20000);
|
|
201
220
|
return;
|
|
202
221
|
}
|
|
222
|
+
if (message.type === "presence") {
|
|
223
|
+
if (message.peerId === this.state.watchedPeerId)
|
|
224
|
+
this.update({ peerOnline: typeof message.online === "boolean" ? message.online : undefined });
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
203
227
|
if (message.type === "pong")
|
|
204
228
|
return;
|
|
205
229
|
if (message.type === "error") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pmate/chat-sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Cross-platform PMate chat input components, voice input primitives, and ASR helpers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -11,8 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://github.com/parrot-mate/pmate-mono/tree/main/packages/chat-sdk",
|
|
13
13
|
"files": [
|
|
14
|
-
"lib"
|
|
15
|
-
"dist"
|
|
14
|
+
"lib"
|
|
16
15
|
],
|
|
17
16
|
"exports": {
|
|
18
17
|
".": {
|