@reactoo/watchtogether-sdk-js 2.8.1 → 2.8.4
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/example/index.html
CHANGED
package/package.json
CHANGED
|
@@ -57,6 +57,9 @@ let roomSession = function ({roomId, pinHash, role, options = {}}, room, wt) {
|
|
|
57
57
|
room.on('data', (data) => {
|
|
58
58
|
___.__parseDataEvents(data);
|
|
59
59
|
});
|
|
60
|
+
room.on('dataMessage', (data) => {
|
|
61
|
+
___.__parseDataMessageEvents(data);
|
|
62
|
+
})
|
|
60
63
|
|
|
61
64
|
return (___ = {
|
|
62
65
|
|
|
@@ -189,8 +192,12 @@ let roomSession = function ({roomId, pinHash, role, options = {}}, room, wt) {
|
|
|
189
192
|
|
|
190
193
|
},
|
|
191
194
|
|
|
195
|
+
__parseDataMessageEvents: function(msg = {}) {
|
|
196
|
+
emitter.emit('dataMessage', msg);
|
|
197
|
+
},
|
|
192
198
|
|
|
193
199
|
__parseDataEvents: function (msg = {}) {
|
|
200
|
+
|
|
194
201
|
if (msg.videoroom === 'message') {
|
|
195
202
|
if (msg.action === 'pending_shutdown' || msg.action === 'shutting_down') {
|
|
196
203
|
emitter.emit('scaling');
|
|
@@ -422,6 +429,10 @@ let roomSession = function ({roomId, pinHash, role, options = {}}, room, wt) {
|
|
|
422
429
|
});
|
|
423
430
|
},
|
|
424
431
|
|
|
432
|
+
sendMessageViaDataChannel: (label, data) => {
|
|
433
|
+
room.sendMessageViaDataChannel(label, data);
|
|
434
|
+
},
|
|
435
|
+
|
|
425
436
|
__requestMuteStatus: function () {
|
|
426
437
|
this.sendSystemMessage('remote_muted_request');
|
|
427
438
|
},
|
|
@@ -313,6 +313,7 @@ class RoomSession {
|
|
|
313
313
|
this.#enableDebug();
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
|
|
316
317
|
}
|
|
317
318
|
|
|
318
319
|
#httpAPICall = function(url, options) {
|
|
@@ -882,6 +883,23 @@ class RoomSession {
|
|
|
882
883
|
}
|
|
883
884
|
}
|
|
884
885
|
|
|
886
|
+
sendMessageViaDataChannel(label = this.defaultDataChannelLabel, data) {
|
|
887
|
+
if(this.#publisherHandle) {
|
|
888
|
+
if(label === null) {
|
|
889
|
+
Object.keys(this.#publisherHandle.webrtcStuff.dataChannel).forEach((key) => {
|
|
890
|
+
const channel = this.#publisherHandle.webrtcStuff.dataChannel[key];
|
|
891
|
+
channel.send(JSON.stringify(data));
|
|
892
|
+
})
|
|
893
|
+
}
|
|
894
|
+
else {
|
|
895
|
+
const channel = this.#publisherHandle.webrtcStuff.dataChannel[label];
|
|
896
|
+
if(channel) {
|
|
897
|
+
channel.send(JSON.stringify(data));
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
885
903
|
async sendMessage(handleId, message = {body: 'Example Body'}, dontWait = false, dontResolveOnAck = false, retry = 0) {
|
|
886
904
|
return this.#send({
|
|
887
905
|
"janus": "message",
|
|
@@ -1041,7 +1059,7 @@ class RoomSession {
|
|
|
1041
1059
|
this.#reconnect()
|
|
1042
1060
|
.catch(e => {
|
|
1043
1061
|
if(e.type !== 'warning') {
|
|
1044
|
-
this.disconnect();
|
|
1062
|
+
this.disconnect().catch(() => {});
|
|
1045
1063
|
}
|
|
1046
1064
|
this.emit('error', e)
|
|
1047
1065
|
});
|
|
@@ -1380,8 +1398,6 @@ class RoomSession {
|
|
|
1380
1398
|
config.dataChannelOpen = this.defaultDataChannelLabel === data?.label && data?.state === 'open';
|
|
1381
1399
|
}
|
|
1382
1400
|
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
1401
|
if (handleId === this.handleId && this.defaultDataChannelLabel === data?.label) {
|
|
1386
1402
|
this._isDataChannelOpen = data?.state === 'open';
|
|
1387
1403
|
this.emit('dataChannel', data?.state === 'open');
|
|
@@ -1394,19 +1410,8 @@ class RoomSession {
|
|
|
1394
1410
|
type: 'warning',
|
|
1395
1411
|
id: 12,
|
|
1396
1412
|
message: 'data event warning',
|
|
1397
|
-
data: [handleId, data]
|
|
1413
|
+
data: [handleId, data, data.error?.message, data.error?.errorDetail]
|
|
1398
1414
|
});
|
|
1399
|
-
|
|
1400
|
-
if (handle) {
|
|
1401
|
-
let config = handle.webrtcStuff;
|
|
1402
|
-
if(this.defaultDataChannelLabel === data.label) {
|
|
1403
|
-
config.dataChannelOpen = false;
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
if (handleId === this.handleId && this.defaultDataChannelLabel === data.label) {
|
|
1407
|
-
this._isDataChannelOpen = false;
|
|
1408
|
-
this.emit('dataChannel', false);
|
|
1409
|
-
}
|
|
1410
1415
|
}
|
|
1411
1416
|
|
|
1412
1417
|
if (handleId === this.handleId && type === 'message') {
|
|
@@ -1422,6 +1427,18 @@ class RoomSession {
|
|
|
1422
1427
|
this.emit('data', d);
|
|
1423
1428
|
}
|
|
1424
1429
|
|
|
1430
|
+
if(handleId !== this.handleId && type === 'message') {
|
|
1431
|
+
let d = null;
|
|
1432
|
+
|
|
1433
|
+
try {
|
|
1434
|
+
d = JSON.parse(data)
|
|
1435
|
+
} catch (e) {
|
|
1436
|
+
this.emit('error', {type: 'warning', id: 45, message: 'data message parse error', data: [handleId, e]});
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
this.emit('dataMessage', d);
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1425
1442
|
}
|
|
1426
1443
|
|
|
1427
1444
|
async #createHandle() {
|
|
@@ -1977,7 +1994,10 @@ class RoomSession {
|
|
|
1977
1994
|
this.#wipeListeners();
|
|
1978
1995
|
|
|
1979
1996
|
if(!this.useWebsockets) {
|
|
1980
|
-
|
|
1997
|
+
|
|
1998
|
+
if(this.token) {
|
|
1999
|
+
await this.#send({"janus": "destroy"}, true);
|
|
2000
|
+
}
|
|
1981
2001
|
}
|
|
1982
2002
|
|
|
1983
2003
|
else if (this.ws && this.ws.readyState === 1) {
|
|
@@ -1986,7 +2006,18 @@ class RoomSession {
|
|
|
1986
2006
|
}
|
|
1987
2007
|
|
|
1988
2008
|
this.#subscriberJoinPromise = null;
|
|
2009
|
+
|
|
1989
2010
|
this.sessionId = null;
|
|
2011
|
+
this.server = null;
|
|
2012
|
+
this.protocol = null;
|
|
2013
|
+
this.iceServers = null;
|
|
2014
|
+
this.token = null;
|
|
2015
|
+
this.roomId = null;
|
|
2016
|
+
this.pin = null;
|
|
2017
|
+
this.id = null;
|
|
2018
|
+
this.display = null;
|
|
2019
|
+
this.userId = null;
|
|
2020
|
+
|
|
1990
2021
|
this.isPublished = false;
|
|
1991
2022
|
this.isConnected = false;
|
|
1992
2023
|
this.isDisconnecting = false;
|