@voltkit-rtc/client 0.2.0
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/CHANGELOG.md +38 -0
- package/LICENSE +21 -0
- package/README.md +296 -0
- package/dist/cjs/broadcast.d.ts +130 -0
- package/dist/cjs/broadcast.d.ts.map +1 -0
- package/dist/cjs/broadcast.js +320 -0
- package/dist/cjs/broadcast.js.map +1 -0
- package/dist/cjs/chat.d.ts +138 -0
- package/dist/cjs/chat.d.ts.map +1 -0
- package/dist/cjs/chat.js +267 -0
- package/dist/cjs/chat.js.map +1 -0
- package/dist/cjs/index.d.ts +285 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +798 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/music.d.ts +76 -0
- package/dist/cjs/music.d.ts.map +1 -0
- package/dist/cjs/music.js +176 -0
- package/dist/cjs/music.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/broadcast.d.ts +130 -0
- package/dist/esm/broadcast.d.ts.map +1 -0
- package/dist/esm/broadcast.js +313 -0
- package/dist/esm/broadcast.js.map +1 -0
- package/dist/esm/chat.d.ts +138 -0
- package/dist/esm/chat.d.ts.map +1 -0
- package/dist/esm/chat.js +262 -0
- package/dist/esm/chat.js.map +1 -0
- package/dist/esm/index.d.ts +285 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +785 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/music.d.ts +76 -0
- package/dist/esm/music.d.ts.map +1 -0
- package/dist/esm/music.js +171 -0
- package/dist/esm/music.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/package.json +60 -0
- package/src/broadcast.ts +352 -0
- package/src/chat.ts +352 -0
- package/src/index.ts +945 -0
- package/src/music.ts +200 -0
package/dist/cjs/chat.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChatClient = exports.ChatRpcError = void 0;
|
|
4
|
+
/** An error returned by the server, carrying its machine-readable code. */
|
|
5
|
+
class ChatRpcError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
constructor(code, message) {
|
|
8
|
+
super(`${code}: ${message}`);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.name = 'ChatRpcError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ChatRpcError = ChatRpcError;
|
|
14
|
+
const RPC_TIMEOUT_MS = 15_000;
|
|
15
|
+
const MAX_RECONNECT_ATTEMPTS = 8;
|
|
16
|
+
/** A token that is wrong will be wrong next time too; retrying only adds noise. */
|
|
17
|
+
const TERMINAL_JOIN_ERRORS = new Set([
|
|
18
|
+
'bad-token',
|
|
19
|
+
'no-token',
|
|
20
|
+
// The account cannot use the service until it is topped up or restored.
|
|
21
|
+
'quota-exhausted',
|
|
22
|
+
'daily-limit-reached',
|
|
23
|
+
'monthly-limit-reached',
|
|
24
|
+
'tenant-suspended',
|
|
25
|
+
]);
|
|
26
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
27
|
+
/**
|
|
28
|
+
* A chat-only connection. Takes the `wsUrl` and `token` returned by
|
|
29
|
+
* `POST /v1/chat/{channel}/tokens`.
|
|
30
|
+
*/
|
|
31
|
+
class ChatClient {
|
|
32
|
+
wsUrl;
|
|
33
|
+
ws = null;
|
|
34
|
+
pending = new Map();
|
|
35
|
+
listeners = new Map();
|
|
36
|
+
nextId = 1;
|
|
37
|
+
token;
|
|
38
|
+
joinResult = null;
|
|
39
|
+
closedByUs = false;
|
|
40
|
+
reconnecting = false;
|
|
41
|
+
reconnectAttempt = 0;
|
|
42
|
+
constructor(wsUrl, token) {
|
|
43
|
+
this.wsUrl = wsUrl;
|
|
44
|
+
this.token = token;
|
|
45
|
+
}
|
|
46
|
+
on(event, fn) {
|
|
47
|
+
let set = this.listeners.get(event);
|
|
48
|
+
if (!set) {
|
|
49
|
+
set = new Set();
|
|
50
|
+
this.listeners.set(event, set);
|
|
51
|
+
}
|
|
52
|
+
set.add(fn);
|
|
53
|
+
return () => set.delete(fn);
|
|
54
|
+
}
|
|
55
|
+
emit(event, ...args) {
|
|
56
|
+
for (const fn of this.listeners.get(event) ?? []) {
|
|
57
|
+
try {
|
|
58
|
+
fn(...args);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
console.error(`listener for ${event} threw`, err);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** What join returned, including the history the channel had at that moment. */
|
|
66
|
+
get info() {
|
|
67
|
+
return this.joinResult;
|
|
68
|
+
}
|
|
69
|
+
async connect() {
|
|
70
|
+
await this.openSocket();
|
|
71
|
+
const result = (await this.rpc('join', { token: this.token }));
|
|
72
|
+
this.joinResult = result;
|
|
73
|
+
this.emit('joined', result);
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
openSocket() {
|
|
77
|
+
this.detachSocket();
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
const url = new URL(this.wsUrl);
|
|
80
|
+
url.searchParams.set('token', this.token);
|
|
81
|
+
const ws = new WebSocket(url.toString());
|
|
82
|
+
this.ws = ws;
|
|
83
|
+
const onError = () => reject(new Error('websocket failed to open'));
|
|
84
|
+
ws.addEventListener('open', () => {
|
|
85
|
+
this.reconnectAttempt = 0;
|
|
86
|
+
this.emit('connected');
|
|
87
|
+
resolve();
|
|
88
|
+
}, { once: true });
|
|
89
|
+
ws.addEventListener('error', onError, { once: true });
|
|
90
|
+
ws.addEventListener('message', (ev) => {
|
|
91
|
+
if (this.ws === ws)
|
|
92
|
+
this.onMessage(ev.data);
|
|
93
|
+
});
|
|
94
|
+
ws.addEventListener('close', (ev) => {
|
|
95
|
+
ws.removeEventListener('error', onError);
|
|
96
|
+
// Only the socket we currently consider ours may drive reconnection.
|
|
97
|
+
if (this.ws !== ws)
|
|
98
|
+
return;
|
|
99
|
+
this.ws = null;
|
|
100
|
+
this.failAllPending(new Error(`socket closed (${ev.code})`));
|
|
101
|
+
this.emit('disconnected', ev.reason || String(ev.code));
|
|
102
|
+
if (ev.code === 4003 && !this.closedByUs) {
|
|
103
|
+
// Ended by the server after telling us why (usageLimit). Final.
|
|
104
|
+
this.closedByUs = true;
|
|
105
|
+
this.emit('closed', 'ended');
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (!this.closedByUs)
|
|
109
|
+
void this.scheduleReconnect();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
detachSocket() {
|
|
114
|
+
const ws = this.ws;
|
|
115
|
+
this.ws = null;
|
|
116
|
+
if (ws && ws.readyState <= WebSocket.OPEN) {
|
|
117
|
+
try {
|
|
118
|
+
ws.close(1000, 'superseded');
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
/* already closing */
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** Single-flight, with backoff: the same shape as the room client's. */
|
|
126
|
+
async scheduleReconnect() {
|
|
127
|
+
if (this.reconnecting || this.closedByUs)
|
|
128
|
+
return;
|
|
129
|
+
this.reconnecting = true;
|
|
130
|
+
try {
|
|
131
|
+
while (!this.closedByUs) {
|
|
132
|
+
this.reconnectAttempt += 1;
|
|
133
|
+
if (this.reconnectAttempt > MAX_RECONNECT_ATTEMPTS) {
|
|
134
|
+
this.emit('error', new Error(`gave up after ${MAX_RECONNECT_ATTEMPTS} reconnect attempts`));
|
|
135
|
+
this.closedByUs = true;
|
|
136
|
+
this.emit('closed', 'gave-up');
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const backoff = Math.min(500 * 2 ** (this.reconnectAttempt - 1), 15_000);
|
|
140
|
+
await sleep(backoff + Math.random() * 400);
|
|
141
|
+
if (this.closedByUs)
|
|
142
|
+
return;
|
|
143
|
+
try {
|
|
144
|
+
await this.connect();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
this.emit('error', err);
|
|
149
|
+
if (err instanceof ChatRpcError && TERMINAL_JOIN_ERRORS.has(err.code)) {
|
|
150
|
+
this.closedByUs = true;
|
|
151
|
+
this.emit('closed', 'gave-up');
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
this.reconnecting = false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
close() {
|
|
162
|
+
if (this.closedByUs)
|
|
163
|
+
return;
|
|
164
|
+
this.closedByUs = true;
|
|
165
|
+
const ws = this.ws;
|
|
166
|
+
this.ws = null;
|
|
167
|
+
ws?.close(1000, 'client closed');
|
|
168
|
+
this.emit('closed', 'left');
|
|
169
|
+
}
|
|
170
|
+
rpc(method, params = {}) {
|
|
171
|
+
return new Promise((resolve, reject) => {
|
|
172
|
+
if (this.ws?.readyState !== WebSocket.OPEN) {
|
|
173
|
+
reject(new Error('socket is not open'));
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const id = this.nextId++;
|
|
177
|
+
const timer = setTimeout(() => {
|
|
178
|
+
this.pending.delete(id);
|
|
179
|
+
reject(new Error(`${method} timed out`));
|
|
180
|
+
}, RPC_TIMEOUT_MS);
|
|
181
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
182
|
+
this.ws.send(JSON.stringify({ id, method, params }));
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
failAllPending(err) {
|
|
186
|
+
for (const p of this.pending.values()) {
|
|
187
|
+
clearTimeout(p.timer);
|
|
188
|
+
p.reject(err);
|
|
189
|
+
}
|
|
190
|
+
this.pending.clear();
|
|
191
|
+
}
|
|
192
|
+
onMessage(raw) {
|
|
193
|
+
let msg;
|
|
194
|
+
try {
|
|
195
|
+
msg = JSON.parse(raw);
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (typeof msg.id === 'number') {
|
|
201
|
+
const p = this.pending.get(msg.id);
|
|
202
|
+
if (!p)
|
|
203
|
+
return;
|
|
204
|
+
clearTimeout(p.timer);
|
|
205
|
+
this.pending.delete(msg.id);
|
|
206
|
+
if (msg.ok)
|
|
207
|
+
p.resolve(msg.result);
|
|
208
|
+
else {
|
|
209
|
+
const e = msg.error;
|
|
210
|
+
p.reject(new ChatRpcError(e?.code ?? 'error', e?.message ?? 'unknown'));
|
|
211
|
+
}
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
switch (msg.event) {
|
|
215
|
+
case 'message':
|
|
216
|
+
this.emit('message', msg.data);
|
|
217
|
+
break;
|
|
218
|
+
case 'messageDeleted':
|
|
219
|
+
this.emit('messageDeleted', msg.data);
|
|
220
|
+
break;
|
|
221
|
+
case 'chatMuted':
|
|
222
|
+
this.emit('chatMuted', msg.data);
|
|
223
|
+
break;
|
|
224
|
+
case 'typing':
|
|
225
|
+
this.emit('typing', msg.data);
|
|
226
|
+
break;
|
|
227
|
+
case 'usageLimit':
|
|
228
|
+
this.emit('usageLimit', msg.data);
|
|
229
|
+
break;
|
|
230
|
+
case 'tokenRefreshed': {
|
|
231
|
+
// A channel outlives its join token many times over. The server hands
|
|
232
|
+
// out a fresh one periodically so a reconnect at any point still works.
|
|
233
|
+
const e = msg.data;
|
|
234
|
+
if (e.token)
|
|
235
|
+
this.token = e.token;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
default:
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
sendMessage(text, opts = {}) {
|
|
243
|
+
return this.rpc('sendMessage', { text, ...opts });
|
|
244
|
+
}
|
|
245
|
+
/** Older messages, oldest first. Pass the oldest id you hold as `before`. */
|
|
246
|
+
async getMessages(opts = {}) {
|
|
247
|
+
const res = (await this.rpc('getMessages', opts));
|
|
248
|
+
return res.messages;
|
|
249
|
+
}
|
|
250
|
+
/** Your own message, or anyone's if you are a moderator. */
|
|
251
|
+
deleteMessage(messageId) {
|
|
252
|
+
return this.rpc('deleteMessage', { messageId });
|
|
253
|
+
}
|
|
254
|
+
/** Moderators only. A mute outlasts the muted socket reconnecting. */
|
|
255
|
+
muteChat(identity, muted = true) {
|
|
256
|
+
return this.rpc('muteChat', { identity, muted });
|
|
257
|
+
}
|
|
258
|
+
/** Advisory, and throttled by the server; safe to call on every keystroke. */
|
|
259
|
+
setTyping(typing) {
|
|
260
|
+
return this.rpc('setTyping', { typing });
|
|
261
|
+
}
|
|
262
|
+
getChatState() {
|
|
263
|
+
return this.rpc('getChatState');
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
exports.ChatClient = ChatClient;
|
|
267
|
+
//# sourceMappingURL=chat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/chat.ts"],"names":[],"mappings":";;;AA+EA,2EAA2E;AAC3E,MAAa,YAAa,SAAQ,KAAK;IAChB;IAArB,YAAqB,IAAY,EAAE,OAAe;QAChD,KAAK,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QADV,SAAI,GAAJ,IAAI,CAAQ;QAE/B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AALD,oCAKC;AAUD,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC,mFAAmF;AACnF,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,WAAW;IACX,UAAU;IACV,wEAAwE;IACxE,iBAAiB;IACjB,qBAAqB;IACrB,uBAAuB;IACvB,kBAAkB;CACnB,CAAC,CAAC;AAEH,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,C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AAC;IAED,4DAA4D;IAC5D,aAAa,CAAC,SAAiB;QAC7B,OAAO,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,sEAAsE;IACtE,QAAQ,CAAC,QAAgB,EAAE,KAAK,GAAG,IAAI;QACrC,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,8EAA8E;IAC9E,SAAS,CAAC,MAAe;QACvB,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,GAAG,CAAC,cAAc,CAAuB,CAAC;IACxD,CAAC;CACF;AA7OD,gCA6OC"}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin client SDK over the orchestrator's signaling protocol.
|
|
3
|
+
*
|
|
4
|
+
* The point of shipping this is that consuming projects never touch
|
|
5
|
+
* mediasoup-client directly -- otherwise every project re-implements transport
|
|
6
|
+
* setup, consumer resume ordering and reconnection, each slightly wrong.
|
|
7
|
+
*/
|
|
8
|
+
import { type types as ms } from 'mediasoup-client';
|
|
9
|
+
type RtpCapabilities = ms.RtpCapabilities;
|
|
10
|
+
import type { ChatEvents, ChatMessage, ChatState, SendMessageOptions } from './chat.js';
|
|
11
|
+
import { type MusicInput, type MusicOptions, type TrackSource } from './music.js';
|
|
12
|
+
export { BroadcastPublisher, WhipError, whipEnd, whipOffer } from './broadcast.js';
|
|
13
|
+
export { AudioMixer, MusicSource } from './music.js';
|
|
14
|
+
export type { MusicInput, MusicOptions, TrackSource } from './music.js';
|
|
15
|
+
export type { BroadcastEvents, BroadcastStartOptions, BroadcastState } from './broadcast.js';
|
|
16
|
+
export { ChatClient, ChatRpcError } from './chat.js';
|
|
17
|
+
export type { ChatClientEvents, ChatEvents, ChatJoinResult, ChatMessage, ChatState, SendMessageOptions, } from './chat.js';
|
|
18
|
+
export type Role = 'host' | 'cohost' | 'moderator' | 'viewer';
|
|
19
|
+
/** Sent when the account behind a session can no longer be used. */
|
|
20
|
+
export interface UsageLimitNotice {
|
|
21
|
+
reason: 'quota-exhausted' | 'daily-limit-reached' | 'monthly-limit-reached' | 'suspended' | string;
|
|
22
|
+
graceSeconds: number;
|
|
23
|
+
/** When the session will be ended, in ms since the epoch. */
|
|
24
|
+
endsAt: number;
|
|
25
|
+
}
|
|
26
|
+
export interface JoinResult {
|
|
27
|
+
roomId: string;
|
|
28
|
+
identity: string;
|
|
29
|
+
role: Role;
|
|
30
|
+
nodeId: string;
|
|
31
|
+
isOrigin: boolean;
|
|
32
|
+
routerRtpCapabilities: RtpCapabilities;
|
|
33
|
+
participants: ParticipantInfo[];
|
|
34
|
+
producers: RemoteProducer[];
|
|
35
|
+
iceServers: RTCIceServer[];
|
|
36
|
+
/** Room metadata set by your backend or a moderator's setRoomMetadata. */
|
|
37
|
+
metadata?: unknown;
|
|
38
|
+
/** Exclusive slots (seats) and who holds them, to seed a seat board. */
|
|
39
|
+
claims?: SlotClaim[];
|
|
40
|
+
/** Slots a moderator has locked. */
|
|
41
|
+
blockedSlots?: string[];
|
|
42
|
+
}
|
|
43
|
+
export interface SlotClaim {
|
|
44
|
+
key: string;
|
|
45
|
+
identity: string;
|
|
46
|
+
/** `away`: the holder's connection dropped and the seat is kept for them. */
|
|
47
|
+
state: 'held' | 'away';
|
|
48
|
+
/** When an `away` claim expires, in unix milliseconds. */
|
|
49
|
+
awayUntil?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface ParticipantInfo {
|
|
52
|
+
identity: string;
|
|
53
|
+
role: Role;
|
|
54
|
+
handRaised: boolean;
|
|
55
|
+
muted: boolean;
|
|
56
|
+
metadata?: unknown;
|
|
57
|
+
}
|
|
58
|
+
export interface RemoteProducer {
|
|
59
|
+
producerId: string;
|
|
60
|
+
identity: string;
|
|
61
|
+
kind: 'audio' | 'video';
|
|
62
|
+
paused: boolean;
|
|
63
|
+
/** What the track carries. A host playing music publishes two audio tracks: `mic` and `music`. */
|
|
64
|
+
source?: TrackSource;
|
|
65
|
+
}
|
|
66
|
+
export interface ClientEvents extends ChatEvents {
|
|
67
|
+
connected: () => void;
|
|
68
|
+
disconnected: (reason: string) => void;
|
|
69
|
+
joined: (result: JoinResult) => void;
|
|
70
|
+
track: (info: {
|
|
71
|
+
identity: string;
|
|
72
|
+
kind: 'audio' | 'video';
|
|
73
|
+
track: MediaStreamTrack;
|
|
74
|
+
producerId: string;
|
|
75
|
+
/** `music` is a host's in-app music. Play it through its own element to give viewers a music switch. */
|
|
76
|
+
source: TrackSource;
|
|
77
|
+
}) => void;
|
|
78
|
+
trackEnded: (info: {
|
|
79
|
+
producerId: string;
|
|
80
|
+
identity: string;
|
|
81
|
+
}) => void;
|
|
82
|
+
/** Someone paused or resumed one of their tracks: muted their mic, turned their music off. */
|
|
83
|
+
trackMuted: (info: {
|
|
84
|
+
identity: string;
|
|
85
|
+
kind: 'audio' | 'video';
|
|
86
|
+
source: TrackSource;
|
|
87
|
+
producerId: string;
|
|
88
|
+
paused: boolean;
|
|
89
|
+
}) => void;
|
|
90
|
+
participantJoined: (p: ParticipantInfo) => void;
|
|
91
|
+
participantLeft: (p: {
|
|
92
|
+
identity: string;
|
|
93
|
+
reason?: string;
|
|
94
|
+
}) => void;
|
|
95
|
+
roleChanged: (e: {
|
|
96
|
+
identity: string;
|
|
97
|
+
role: Role;
|
|
98
|
+
}) => void;
|
|
99
|
+
handRaised: (e: {
|
|
100
|
+
identity: string;
|
|
101
|
+
handRaised: boolean;
|
|
102
|
+
}) => void;
|
|
103
|
+
/**
|
|
104
|
+
* A moderator switched your microphone (`audio`), camera (`video`) or both
|
|
105
|
+
* (no kind) off, or released it (`paused: false`). While paused you cannot
|
|
106
|
+
* switch it back on.
|
|
107
|
+
*/
|
|
108
|
+
forceMuted: (e: {
|
|
109
|
+
by: string;
|
|
110
|
+
kind?: 'audio' | 'video' | '';
|
|
111
|
+
paused: boolean;
|
|
112
|
+
}) => void;
|
|
113
|
+
mustReconnect: (e: {
|
|
114
|
+
reason: string;
|
|
115
|
+
token?: string;
|
|
116
|
+
retry: boolean;
|
|
117
|
+
}) => void;
|
|
118
|
+
roomClosed: (e: {
|
|
119
|
+
reason: string;
|
|
120
|
+
}) => void;
|
|
121
|
+
kicked: (e: {
|
|
122
|
+
by: string;
|
|
123
|
+
reason?: string;
|
|
124
|
+
}) => void;
|
|
125
|
+
error: (err: Error) => void;
|
|
126
|
+
localMediaChanged: (state: {
|
|
127
|
+
micEnabled: boolean;
|
|
128
|
+
camEnabled: boolean;
|
|
129
|
+
musicEnabled: boolean;
|
|
130
|
+
}) => void;
|
|
131
|
+
/** The local stream was replaced, typically after reacquiring devices on a reconnect. */
|
|
132
|
+
localStreamChanged: (stream: MediaStream | null) => void;
|
|
133
|
+
/** Media stopped arriving but the connection is intact -- the publisher is reconnecting. */
|
|
134
|
+
streamInterrupted: (e: {
|
|
135
|
+
reason: string;
|
|
136
|
+
}) => void;
|
|
137
|
+
/** The session ended and will not recover. Nothing further will be emitted. */
|
|
138
|
+
closed: (reason: 'replaced' | 'kicked' | 'room-closed' | 'gave-up' | 'left') => void;
|
|
139
|
+
/**
|
|
140
|
+
* The account behind this session ran out of minutes or reached a usage
|
|
141
|
+
* limit. The session ends at `endsAt` (after `graceSeconds`) unless the
|
|
142
|
+
* account is topped up first -- tell the user, and stop asking them to wait.
|
|
143
|
+
*/
|
|
144
|
+
usageLimit: (e: UsageLimitNotice) => void;
|
|
145
|
+
}
|
|
146
|
+
/** An error returned by the server, carrying its machine-readable code. */
|
|
147
|
+
export declare class RpcError extends Error {
|
|
148
|
+
readonly code: string;
|
|
149
|
+
constructor(code: string, message: string);
|
|
150
|
+
}
|
|
151
|
+
export declare class StreamClient {
|
|
152
|
+
private readonly wsUrl;
|
|
153
|
+
private ws;
|
|
154
|
+
private device;
|
|
155
|
+
private sendTransport;
|
|
156
|
+
private recvTransport;
|
|
157
|
+
private sendTransportPending;
|
|
158
|
+
private recvTransportPending;
|
|
159
|
+
private readonly pending;
|
|
160
|
+
private readonly listeners;
|
|
161
|
+
private readonly consumers;
|
|
162
|
+
private readonly producers;
|
|
163
|
+
private nextId;
|
|
164
|
+
private token;
|
|
165
|
+
private joinResult;
|
|
166
|
+
private localStream;
|
|
167
|
+
private wasPublishing;
|
|
168
|
+
private publishConstraints;
|
|
169
|
+
/** In-app music being published, kept across reconnects so it can be published again. */
|
|
170
|
+
private music;
|
|
171
|
+
private musicProducerId;
|
|
172
|
+
/** What each remote producer carries, so a pause can say "music" rather than just "audio". */
|
|
173
|
+
private readonly remoteSources;
|
|
174
|
+
private closedByUs;
|
|
175
|
+
private reconnecting;
|
|
176
|
+
private reconnectAttempt;
|
|
177
|
+
constructor(wsUrl: string, token: string);
|
|
178
|
+
on<K extends keyof ClientEvents>(event: K, fn: ClientEvents[K]): () => void;
|
|
179
|
+
private emit;
|
|
180
|
+
connect(): Promise<JoinResult>;
|
|
181
|
+
private openSocket;
|
|
182
|
+
private detachSocket;
|
|
183
|
+
/**
|
|
184
|
+
* Reconnection is mandatory, not optional: nodes get drained, relays die and
|
|
185
|
+
* promotions move you to a different node. Always re-ask the orchestrator
|
|
186
|
+
* where to connect -- never assume the same node.
|
|
187
|
+
*/
|
|
188
|
+
private scheduleReconnect;
|
|
189
|
+
close(): void;
|
|
190
|
+
private teardownMedia;
|
|
191
|
+
/** Everything currently known about the room, for rendering. */
|
|
192
|
+
get info(): JoinResult | null;
|
|
193
|
+
private rpc;
|
|
194
|
+
private failAllPending;
|
|
195
|
+
private onMessage;
|
|
196
|
+
private onEvent;
|
|
197
|
+
private ensureSendTransport;
|
|
198
|
+
private createSendTransport;
|
|
199
|
+
private ensureRecvTransport;
|
|
200
|
+
private createRecvTransport;
|
|
201
|
+
/**
|
|
202
|
+
* Publish local camera + mic. Only host/cohost may; others get a server error.
|
|
203
|
+
*
|
|
204
|
+
* Pass the constraints used to obtain the stream and they will be reused to
|
|
205
|
+
* reacquire the devices if a reconnect finds the tracks have ended.
|
|
206
|
+
*/
|
|
207
|
+
publish(stream: MediaStream, constraints?: MediaStreamConstraints): Promise<void>;
|
|
208
|
+
/**
|
|
209
|
+
* Re-establish this client's broadcast after a reconnect.
|
|
210
|
+
*
|
|
211
|
+
* Reuses the existing tracks when they are still live -- the common case, and
|
|
212
|
+
* it avoids a second camera permission prompt. Only reacquires the devices
|
|
213
|
+
* when the tracks have genuinely ended.
|
|
214
|
+
*/
|
|
215
|
+
private republish;
|
|
216
|
+
/**
|
|
217
|
+
* Publish music playing inside the page, as its own track.
|
|
218
|
+
*
|
|
219
|
+
* The audience gets it clean -- it never passes through the microphone --
|
|
220
|
+
* and it has its own switch: `setMusicEnabled(false)` silences the music and
|
|
221
|
+
* leaves the host talking, `setMicEnabled(false)` does the opposite.
|
|
222
|
+
*
|
|
223
|
+
* Call it from a click. Browsers will not start audio processing for a page
|
|
224
|
+
* the user has not interacted with.
|
|
225
|
+
*/
|
|
226
|
+
publishMusic(input: MusicInput, options?: MusicOptions): Promise<void>;
|
|
227
|
+
private produceMusic;
|
|
228
|
+
/** True while music is published, whether or not it is switched on. */
|
|
229
|
+
get musicPublishing(): boolean;
|
|
230
|
+
get musicEnabled(): boolean;
|
|
231
|
+
/** 0 to 1, for the audience. The host's own listening level is the element's. */
|
|
232
|
+
setMusicVolume(volume: number): void;
|
|
233
|
+
/** Switch the music off or on for the audience. The microphone is untouched. */
|
|
234
|
+
setMusicEnabled(enabled: boolean): Promise<void>;
|
|
235
|
+
/** Stop publishing music. The element or stream it came from is left as it was. */
|
|
236
|
+
stopMusic(): Promise<void>;
|
|
237
|
+
private emitLocalMedia;
|
|
238
|
+
private consume;
|
|
239
|
+
/** True once this client has at least one live producer. */
|
|
240
|
+
get publishing(): boolean;
|
|
241
|
+
get micEnabled(): boolean;
|
|
242
|
+
get camEnabled(): boolean;
|
|
243
|
+
private trackEnabled;
|
|
244
|
+
/**
|
|
245
|
+
* Pausing the producer stops RTP at the source, so it costs nothing on the
|
|
246
|
+
* SFU and every viewer is told. Muting only the local track would keep
|
|
247
|
+
* sending silence and leave viewers showing you as unmuted.
|
|
248
|
+
*/
|
|
249
|
+
setMicEnabled(enabled: boolean): Promise<void>;
|
|
250
|
+
setCamEnabled(enabled: boolean): Promise<void>;
|
|
251
|
+
private setKindEnabled;
|
|
252
|
+
/** Stop publishing entirely and release the local devices. */
|
|
253
|
+
unpublish(): Promise<void>;
|
|
254
|
+
get local(): MediaStream | null;
|
|
255
|
+
raiseHand(): Promise<unknown>;
|
|
256
|
+
lowerHand(): Promise<unknown>;
|
|
257
|
+
muteParticipant(identity: string): Promise<unknown>;
|
|
258
|
+
/**
|
|
259
|
+
* Moderating roles: switch someone's microphone (`audio`), camera (`video`)
|
|
260
|
+
* or both (no kind) off at the server, where they cannot switch it back on.
|
|
261
|
+
* `paused: false` releases it; they then turn it on themselves.
|
|
262
|
+
*/
|
|
263
|
+
forceMute(identity: string, kind?: 'audio' | 'video', paused?: boolean): Promise<unknown>;
|
|
264
|
+
promote(identity: string, role: Role): Promise<unknown>;
|
|
265
|
+
kick(identity: string, reason?: string): Promise<unknown>;
|
|
266
|
+
endRoom(): Promise<unknown>;
|
|
267
|
+
getRoomState(): Promise<unknown>;
|
|
268
|
+
sendMessage(text: string, opts?: SendMessageOptions): Promise<{
|
|
269
|
+
id: string;
|
|
270
|
+
ts: number;
|
|
271
|
+
}>;
|
|
272
|
+
/** Older messages, oldest first. Pass the oldest id you hold as `before`. */
|
|
273
|
+
getMessages(opts?: {
|
|
274
|
+
limit?: number;
|
|
275
|
+
before?: string;
|
|
276
|
+
}): Promise<ChatMessage[]>;
|
|
277
|
+
/** Your own message, or anyone's if you are a moderator. */
|
|
278
|
+
deleteMessage(messageId: string): Promise<unknown>;
|
|
279
|
+
/** Moderators only. A mute outlasts the muted socket reconnecting. */
|
|
280
|
+
muteChat(identity: string, muted?: boolean): Promise<unknown>;
|
|
281
|
+
/** Advisory, and throttled by the server; safe to call on every keystroke. */
|
|
282
|
+
setTyping(typing: boolean): Promise<unknown>;
|
|
283
|
+
getChatState(): Promise<ChatState>;
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAU,KAAK,KAAK,IAAI,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAO5D,KAAK,eAAe,GAAG,EAAE,CAAC,eAAe,CAAC;AAI1C,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACxF,OAAO,EAAe,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE/F,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACrD,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACxE,YAAY,EAAE,eAAe,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACrD,YAAY,EACV,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,WAAW,EACX,SAAS,EACT,kBAAkB,GACnB,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE9D,oEAAoE;AACpE,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,iBAAiB,GAAG,qBAAqB,G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