Skip to content

Commit 3f31680

Browse files
authored
Update DataStreams API (#1393)
1 parent 6aab185 commit 3f31680

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

examples/demo/demo.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
ConnectionState,
1515
DisconnectReason,
1616
ExternalE2EEKeyProvider,
17-
LocalAudioTrack,
1817
LogLevel,
1918
MediaDeviceFailure,
2019
Participant,
@@ -247,7 +246,7 @@ const appActions = {
247246
);
248247
});
249248

250-
room.setTextStreamHandler(async (reader, participant) => {
249+
room.registerTextStreamHandler('chat', async (reader, participant) => {
251250
const info = reader.info;
252251
if (info.size) {
253252
handleChatMessage(
@@ -272,9 +271,9 @@ const appActions = {
272271
appendLog('text stream finished');
273272
}
274273
console.log('final info including close extensions', reader.info);
275-
}, 'chat');
274+
});
276275

277-
room.setByteStreamHandler(async (reader, participant) => {
276+
room.registerByteStreamHandler('files', async (reader, participant) => {
278277
const info = reader.info;
279278

280279
appendLog(`started to receive a file called "${info.name}" from ${participant?.identity}`);
@@ -340,7 +339,7 @@ const appActions = {
340339
downloadLink.style.display = 'block';
341340
$('chat-area').after(downloadLink);
342341
}
343-
}, 'files');
342+
});
344343

345344
try {
346345
// read and set current key from input

src/room/Room.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,25 +278,25 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
278278
}
279279
}
280280

281-
setTextStreamHandler(callback: TextStreamHandler, topic: string = '') {
281+
registerTextStreamHandler(topic: string, callback: TextStreamHandler) {
282282
if (this.textStreamHandlers.has(topic)) {
283283
throw new TypeError(`A text stream handler for topic "${topic}" has already been set.`);
284284
}
285285
this.textStreamHandlers.set(topic, callback);
286286
}
287287

288-
removeTextStreamHandler(topic: string = '') {
288+
unregisterTextStreamHandler(topic: string) {
289289
this.textStreamHandlers.delete(topic);
290290
}
291291

292-
setByteStreamHandler(callback: ByteStreamHandler, topic: string = '') {
292+
registerByteStreamHandler(topic: string, callback: ByteStreamHandler) {
293293
if (this.byteStreamHandlers.has(topic)) {
294294
throw new TypeError(`A byte stream handler for topic "${topic}" has already been set.`);
295295
}
296296
this.byteStreamHandlers.set(topic, callback);
297297
}
298298

299-
removeByteStreamHandler(topic: string = '') {
299+
unregisterByteStreamHandler(topic: string) {
300300
this.byteStreamHandlers.delete(topic);
301301
}
302302

0 commit comments

Comments
 (0)