@reactoo/watchtogether-sdk-js 2.5.73 → 2.5.75
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/dist/watchtogether-sdk.js +4 -4
- package/dist/watchtogether-sdk.min.js +2 -2
- package/example/bulk_join_room/bulk_join_room.html +1 -1
- package/example/index.html +10 -6
- package/package.json +1 -1
- package/src/models/auth.js +5 -0
- package/src/modules/wt-auth.js +2 -2
- package/src/modules/wt-iot-worker.js +245 -0
- package/src/modules/wt-room.js +3 -3
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
function joinRoom(participantData) {
|
|
186
|
-
return participantData.sdkInstance.auth.deviceLogin(participantData.id)
|
|
186
|
+
return participantData.sdkInstance.auth.deviceLogin(false, participantData.id)
|
|
187
187
|
.then(() => participantData.sdkInstance.room.createSession({roomId, pinHash}))
|
|
188
188
|
.then(session => {
|
|
189
189
|
participantData.session = session;
|
package/example/index.html
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
<button onclick="unpublish()">unpublish</button>
|
|
18
18
|
<button onclick="toggleVideo()">toggle video</button>
|
|
19
19
|
<button onclick="toggleAudio()">toggle audio</button>
|
|
20
|
+
<button onclick="hento()">sign to goole</button>
|
|
20
21
|
</div>
|
|
21
22
|
|
|
22
23
|
</div>
|
|
@@ -41,6 +42,14 @@
|
|
|
41
42
|
// });
|
|
42
43
|
// }
|
|
43
44
|
|
|
45
|
+
function hento() {
|
|
46
|
+
Instance.auth.socialAuth({provider: 'youtube', action: 'generateAuthUrl'})
|
|
47
|
+
.then(r => {
|
|
48
|
+
window.open(r.data.redirectUrl);
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
44
53
|
function createParticipant(data, isRemote = false) {
|
|
45
54
|
|
|
46
55
|
let id = `part_${data.id}`;
|
|
@@ -97,7 +106,7 @@
|
|
|
97
106
|
Instance.room.getSessionByConstructId(constructId).toggleAudio()
|
|
98
107
|
}
|
|
99
108
|
|
|
100
|
-
let Instance = WatchTogetherSDK({debug:true, apiUrl: 'https://api.reactoo.com/
|
|
109
|
+
let Instance = WatchTogetherSDK({debug:true, apiUrl: 'https://api.reactoo.com/stefan/swagger.json'})({instanceType:'reactooDemo'});
|
|
101
110
|
|
|
102
111
|
Instance.auth.$on('login', () => {
|
|
103
112
|
console.log('We are in');
|
|
@@ -122,9 +131,7 @@
|
|
|
122
131
|
Instance.auth.deviceLogin(true) // login as browser
|
|
123
132
|
.then(r => Instance.iot.iotLogin()) // login to mqtt
|
|
124
133
|
.then(r => {
|
|
125
|
-
|
|
126
134
|
if(roomId) {
|
|
127
|
-
console.log(roomId);
|
|
128
135
|
return Instance.room.getRoomById(roomId, pinHash).then((r) => {
|
|
129
136
|
Instance.iot?.subscribe(r.data.iotTopic);
|
|
130
137
|
return {roomId, pinHash}
|
|
@@ -136,9 +143,6 @@
|
|
|
136
143
|
.then(r => r.data.items.length ? r.data.items[0] : Instance.room.createRoom({title:'Demo Room'}).then(r => r.data))
|
|
137
144
|
.then(r => Instance.room.getInviteUrl(r._id)) // getting info about invite params
|
|
138
145
|
.then((r) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
146
|
roomId = r.data.roomId;
|
|
143
147
|
|
|
144
148
|
console.log('-----------------------------------------------------');
|
package/package.json
CHANGED
package/src/models/auth.js
CHANGED
|
@@ -90,6 +90,11 @@ let auth = function () {
|
|
|
90
90
|
.then(client => client.apis.auth.confirmForgotPassword({},{requestBody:{password, confirmationCode, username}}))
|
|
91
91
|
},
|
|
92
92
|
|
|
93
|
+
socialAuth: (data = {}) => {
|
|
94
|
+
return this.__privates.auth.__client
|
|
95
|
+
.then(client => client.apis.auth.socialAuth(data))
|
|
96
|
+
},
|
|
97
|
+
|
|
93
98
|
$on: (key, callback, that) => {
|
|
94
99
|
return this.__privates.auth.on(key, callback, that || this);
|
|
95
100
|
},
|
package/src/modules/wt-auth.js
CHANGED
|
@@ -109,12 +109,12 @@ class Auth {
|
|
|
109
109
|
this.emit(this.__isLogged ? 'login' : 'logout', {
|
|
110
110
|
client,
|
|
111
111
|
isInitialEvent,
|
|
112
|
+
isReauth,
|
|
112
113
|
isLoggedInAsDevice: this.isLoggedInAs(this.__parsedJwt, 'device'),
|
|
113
114
|
isLoggedInAsObserver: this.isLoggedInAs(this.__parsedJwt, 'observer'),
|
|
114
115
|
isLoggedInAsInstanceAdmin: this.isLoggedInAs(this.__parsedJwt, 'instanceAdmin'),
|
|
115
116
|
isLoggedInAsAdmin: this.isLoggedInAs(this.__parsedJwt, 'admin'),
|
|
116
|
-
domain: this.getDomain(this.__parsedJwt)
|
|
117
|
-
isReauth
|
|
117
|
+
domain: this.getDomain(this.__parsedJwt)
|
|
118
118
|
});
|
|
119
119
|
return client;
|
|
120
120
|
})
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
|
|
2
|
+
import {device} from 'aws-iot-device-sdk';
|
|
3
|
+
import emitter from './wt-emitter';
|
|
4
|
+
import {decodeJanusDisplay} from "./wt-utils";
|
|
5
|
+
|
|
6
|
+
class Iot {
|
|
7
|
+
|
|
8
|
+
constructor(enableDebugFlag) {
|
|
9
|
+
Object.assign(this, emitter());
|
|
10
|
+
this.device = null;
|
|
11
|
+
this.decoder = new TextDecoder('utf-8');
|
|
12
|
+
this.connectionActive = false;
|
|
13
|
+
this.log = Iot.noop;
|
|
14
|
+
this.debugFlag = enableDebugFlag;
|
|
15
|
+
this.credentialsExpirationCheckIntervalId = null;
|
|
16
|
+
this.currentCredentialsExpirationStamp = null
|
|
17
|
+
if(enableDebugFlag) {
|
|
18
|
+
this.enableDebug();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static noop() {}
|
|
23
|
+
|
|
24
|
+
enableDebug() {
|
|
25
|
+
this.log = console.log.bind(console);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
startCredentialsExpirationCheck(expiration) {
|
|
29
|
+
this.stopCredentialsExpirationCheck();
|
|
30
|
+
this.currentCredentialsExpirationStamp = new Date(expiration).getTime();
|
|
31
|
+
this.credentialsExpirationCheckIntervalId = setInterval(() => {
|
|
32
|
+
const curentTimeStamp = new Date().getTime();
|
|
33
|
+
if(this.currentCredentialsExpirationStamp - curentTimeStamp <= 300000) {
|
|
34
|
+
this.emit('updateCredentials');
|
|
35
|
+
}
|
|
36
|
+
}, 5000);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
stopCredentialsExpirationCheck() {
|
|
40
|
+
clearInterval(this.credentialsExpirationCheckIntervalId);
|
|
41
|
+
this.credentialsExpirationCheckIntervalId = null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
updateWebSocketCredentials(accessKeyId, secretAccessKey, sessionToken, expiration) {
|
|
45
|
+
if(this.device) {
|
|
46
|
+
this.device.updateWebSocketCredentials(accessKeyId, secretAccessKey, sessionToken);
|
|
47
|
+
this.startCredentialsExpirationCheck(expiration);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
connect(apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken, expiration, forceDisconnect = false) {
|
|
52
|
+
return this.disconnect(forceDisconnect).then(() => {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
this.device = device({
|
|
55
|
+
protocol:'wss',
|
|
56
|
+
clientId: apiMqttClientId,
|
|
57
|
+
region,
|
|
58
|
+
host: apiMqttUrl,
|
|
59
|
+
accessKeyId: accessKeyId,
|
|
60
|
+
secretKey: secretAccessKey,
|
|
61
|
+
sessionToken: sessionToken,
|
|
62
|
+
keepalive: 15,
|
|
63
|
+
maximumReconnectTimeMs: 8000,
|
|
64
|
+
enableMetrics: false,
|
|
65
|
+
debug: this.debugFlag,
|
|
66
|
+
autoResubscribe: true
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
this.startCredentialsExpirationCheck(expiration);
|
|
70
|
+
|
|
71
|
+
let __s = () => {
|
|
72
|
+
this.device?.off('connect', __s);
|
|
73
|
+
this.device?.off('error', __e);
|
|
74
|
+
resolve(this.device)
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
let __e = (e) => {
|
|
78
|
+
this.device?.off('connect', __s);
|
|
79
|
+
this.device?.off('error', __e);
|
|
80
|
+
reject(e);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
this.device.once('connect', __s);
|
|
84
|
+
this.device.once('error', __e);
|
|
85
|
+
|
|
86
|
+
this.device.on('message', this.__messageCb.bind(this));
|
|
87
|
+
this.device.on('connect', this.__connectCb.bind(this));
|
|
88
|
+
this.device.on('reconnect', this.__reconnectCb.bind(this));
|
|
89
|
+
this.device.on('error', this.__failureCb.bind(this));
|
|
90
|
+
this.device.on('close', this.__closeCb.bind(this));
|
|
91
|
+
this.device.on('offline', this.__offlineCb.bind(this));
|
|
92
|
+
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
disconnect(force = false) {
|
|
99
|
+
|
|
100
|
+
this.stopCredentialsExpirationCheck();
|
|
101
|
+
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
if(!this.device) {
|
|
104
|
+
resolve();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
let __i = null;
|
|
108
|
+
let __c = () => {
|
|
109
|
+
clearTimeout(__i);
|
|
110
|
+
this.device = null;
|
|
111
|
+
resolve();
|
|
112
|
+
};
|
|
113
|
+
__i = setTimeout(__c, 4000);
|
|
114
|
+
this.device.off('message', this.__messageCb.bind(this));
|
|
115
|
+
this.device.off('connect', this.__connectCb.bind(this));
|
|
116
|
+
this.device.off('reconnect', this.__reconnectCb.bind(this));
|
|
117
|
+
this.device.off('error', this.__failureCb.bind(this));
|
|
118
|
+
this.device.off('close', this.__closeCb.bind(this));
|
|
119
|
+
this.device.off('offline', this.__offlineCb.bind(this));
|
|
120
|
+
this.device.end(force, __c);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
isConnected() {
|
|
125
|
+
return this.connectionActive;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
subscribe(topic) {
|
|
129
|
+
return this.device && this.device.subscribe(topic);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
unsubscribe(topic) {
|
|
133
|
+
return this.device && this.device.unsubscribe(topic);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
send(topic, message) {
|
|
137
|
+
let msg = typeof message === 'object' ? JSON.stringify(message) : message;
|
|
138
|
+
return this.device && this.device.publish(topic, msg);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
__reconnectCb() {
|
|
142
|
+
this.emit('reconnect');
|
|
143
|
+
}
|
|
144
|
+
__connectCb() {
|
|
145
|
+
this.connectionActive = true;
|
|
146
|
+
this.emit('connect');
|
|
147
|
+
}
|
|
148
|
+
__failureCb(err) {
|
|
149
|
+
this.emit('error', err);
|
|
150
|
+
}
|
|
151
|
+
__closeCb(responseObject) {
|
|
152
|
+
this.connectionActive = false;
|
|
153
|
+
this.emit('close');
|
|
154
|
+
}
|
|
155
|
+
__offlineCb(responseObject) {
|
|
156
|
+
this.emit('offline');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
__messageCb(t, message, packet) {
|
|
160
|
+
const topic = t.split('/');
|
|
161
|
+
let payload = JSON.parse(this.decoder.decode(message));
|
|
162
|
+
|
|
163
|
+
if(payload.display) {
|
|
164
|
+
const decodedDisplay = decodeJanusDisplay(payload.display);
|
|
165
|
+
if(decodedDisplay.userId) {
|
|
166
|
+
payload = {...payload, userId: decodedDisplay.userId, role: decodedDisplay.role, start: decodedDisplay.start};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if(topic[0] === 'user') { // user
|
|
171
|
+
const userId = topic[1].replace("_", ':');
|
|
172
|
+
this.emit('message', {userId, ...payload, event: payload.event ? `user:${payload.event}` : 'user'});
|
|
173
|
+
} else if(topic[0] === 'wt') {
|
|
174
|
+
const event = payload.event;
|
|
175
|
+
const roomId = topic[2];
|
|
176
|
+
if(topic[1] === 'room') { // room
|
|
177
|
+
if(
|
|
178
|
+
event === 'message' ||
|
|
179
|
+
event === 'template_updated' ||
|
|
180
|
+
event === 'record_start' ||
|
|
181
|
+
event === 'record_stop' ||
|
|
182
|
+
event === 'record_configured' ||
|
|
183
|
+
event === 'record_livestream_available' ||
|
|
184
|
+
event === 'record_livestream_kick' ||
|
|
185
|
+
event === 'user_update_displayname' ||
|
|
186
|
+
event === 'user_update_avatar' ||
|
|
187
|
+
event === 'user_update_customattributes' ||
|
|
188
|
+
event === 'user_update_privateattributes' ||
|
|
189
|
+
event === 'channel_changed' ||
|
|
190
|
+
event === "instance_homepage_changed" ||
|
|
191
|
+
event === "instance_settings_changed" ||
|
|
192
|
+
event === "externalmix_changed" ||
|
|
193
|
+
event === "video_uploaded" ||
|
|
194
|
+
event === "change_user_devices" ||
|
|
195
|
+
event === "queue" ||
|
|
196
|
+
event === "title_changed"
|
|
197
|
+
) {
|
|
198
|
+
this.emit('message', {event, ...payload, roomId})
|
|
199
|
+
}
|
|
200
|
+
else if(event === 'joined' || event === 'leaving') {
|
|
201
|
+
this.emit('message', {event, ...payload, isObserver:!!payload.isObserver, roomId});
|
|
202
|
+
}
|
|
203
|
+
else if(
|
|
204
|
+
event === 'left' || //user removed room a.k.a. left the room
|
|
205
|
+
event === 'kicked' ||
|
|
206
|
+
event === 'banned' ||
|
|
207
|
+
event === 'unbanned' ||
|
|
208
|
+
event === 'approved' ||
|
|
209
|
+
event === 'muted' ||
|
|
210
|
+
event === 'unmuted' ||
|
|
211
|
+
event === 'messageRemoved' ||
|
|
212
|
+
event === 'messageReported' ||
|
|
213
|
+
event === 'chatClear' ||
|
|
214
|
+
event === 'handRaised' || event === 'handLowered' || event === 'handsCleared'
|
|
215
|
+
) {
|
|
216
|
+
this.emit('message', {event, ...payload});
|
|
217
|
+
}
|
|
218
|
+
else if(event === 'volume_set') {
|
|
219
|
+
this.emit('message', {event, ...payload});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else if(topic[1] === 'instanceroom') { // instance
|
|
223
|
+
if(event === 'add_room' || event === 'remove_room' || event === 'set_room' || event === "instance_homepage_changed" || event === 'instance_settings_changed') {
|
|
224
|
+
this.emit('message', {event, ...payload});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else if(topic[1] === 'externalmix') {
|
|
228
|
+
const event = payload.event;
|
|
229
|
+
this.emit('message', {event, ...payload});
|
|
230
|
+
}
|
|
231
|
+
} else if(topic[0] === 'wtr') {
|
|
232
|
+
const recorderId = topic[1];
|
|
233
|
+
const sessionId = topic[2];
|
|
234
|
+
if(topic[3] === 'control') {
|
|
235
|
+
this.emit('message', {event: 'recorder_control', ...payload, recorderId, sessionId});
|
|
236
|
+
} // recorder control
|
|
237
|
+
else if(topic[3] === 'monitor') {
|
|
238
|
+
this.emit('message', {event: 'recorder_monitor', ...payload, recorderId, sessionId});
|
|
239
|
+
} // recorder monitor
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
export default Iot;
|
package/src/modules/wt-room.js
CHANGED
|
@@ -2027,7 +2027,7 @@ class RoomSession {
|
|
|
2027
2027
|
tid: generateUUID(),
|
|
2028
2028
|
id: handle.handleId,
|
|
2029
2029
|
userId: decodeJanusDisplay(handle.userId)?.userId,
|
|
2030
|
-
role: decodeJanusDisplay(
|
|
2030
|
+
role: decodeJanusDisplay(this.display)?.role,
|
|
2031
2031
|
track,
|
|
2032
2032
|
stream: config.stream,
|
|
2033
2033
|
adding: true,
|
|
@@ -2041,7 +2041,7 @@ class RoomSession {
|
|
|
2041
2041
|
tid:generateUUID(),
|
|
2042
2042
|
id: handle.handleId,
|
|
2043
2043
|
userId: decodeJanusDisplay(handle.userId)?.userId,
|
|
2044
|
-
role: decodeJanusDisplay(
|
|
2044
|
+
role: decodeJanusDisplay(this.display)?.role,
|
|
2045
2045
|
track: ev.target,
|
|
2046
2046
|
stream: config.stream,
|
|
2047
2047
|
adding: false,
|
|
@@ -2059,7 +2059,7 @@ class RoomSession {
|
|
|
2059
2059
|
tid: generateUUID(),
|
|
2060
2060
|
id: handle.handleId,
|
|
2061
2061
|
userId: decodeJanusDisplay(handle.userId)?.userId,
|
|
2062
|
-
role: decodeJanusDisplay(
|
|
2062
|
+
role: decodeJanusDisplay(this.display)?.role,
|
|
2063
2063
|
stream: null,
|
|
2064
2064
|
adding: false,
|
|
2065
2065
|
constructId: this.constructId,
|