@pmate/chat-sdk 0.6.1 → 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.
@@ -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;
@@ -53,11 +53,16 @@ export class CallClient {
53
53
  clearInterval(this.heartbeat);
54
54
  const active = !["idle", "ended"].includes(this.state.phase);
55
55
  this.release();
56
- 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" });
57
57
  if (!this.closed && event.code !== 1008)
58
58
  this.reconnect = setTimeout(() => this.connect(), 3000);
59
59
  };
60
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
+ }
61
66
  async start(peerId) {
62
67
  if (!this.state.ready || !["idle", "ended"].includes(this.state.phase))
63
68
  return;
@@ -208,10 +213,17 @@ export class CallClient {
208
213
  async receive(message) {
209
214
  if (message.type === "ready") {
210
215
  this.update({ ready: true, error: undefined });
216
+ if (this.state.watchedPeerId)
217
+ this.send({ type: "presence.watch", peerId: this.state.watchedPeerId });
211
218
  clearInterval(this.heartbeat);
212
219
  this.heartbeat = setInterval(() => this.send({ type: "ping" }), 20000);
213
220
  return;
214
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
+ }
215
227
  if (message.type === "pong")
216
228
  return;
217
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.1",
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",