@realsee/live 0.4.0-beta.6 → 0.4.0-beta.7
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/realsee-live.cjs.development.js +1168 -796
- package/dist/realsee-live.cjs.development.js.map +1 -1
- package/dist/realsee-live.cjs.production.js +1 -1
- package/dist/realsee-live.cjs.production.js.map +1 -1
- package/dist/realsee-live.esm.js +1169 -797
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +51277 -50905
- package/dist/realsee-live.umd.development.js.map +1 -1
- package/dist/realsee-live.umd.production.js +1 -1
- package/dist/realsee-live.umd.production.js.map +1 -1
- package/package.json +4 -3
|
@@ -13,7 +13,97 @@ var JSBridge__default = /*#__PURE__*/_interopDefaultLegacy(JSBridge);
|
|
|
13
13
|
var TRTC__default = /*#__PURE__*/_interopDefaultLegacy(TRTC);
|
|
14
14
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/******************************************************************************
|
|
17
|
+
Copyright (c) Microsoft Corporation.
|
|
18
|
+
|
|
19
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
20
|
+
purpose with or without fee is hereby granted.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
23
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
24
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
25
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
26
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
27
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
28
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
29
|
+
***************************************************************************** */
|
|
30
|
+
/* global Reflect, Promise */
|
|
31
|
+
|
|
32
|
+
var extendStatics = function(d, b) {
|
|
33
|
+
extendStatics = Object.setPrototypeOf ||
|
|
34
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
35
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
36
|
+
return extendStatics(d, b);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function __extends(d, b) {
|
|
40
|
+
if (typeof b !== "function" && b !== null)
|
|
41
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
42
|
+
extendStatics(d, b);
|
|
43
|
+
function __() { this.constructor = d; }
|
|
44
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var __assign = function() {
|
|
48
|
+
__assign = Object.assign || function __assign(t) {
|
|
49
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
50
|
+
s = arguments[i];
|
|
51
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
52
|
+
}
|
|
53
|
+
return t;
|
|
54
|
+
};
|
|
55
|
+
return __assign.apply(this, arguments);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
59
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
60
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
61
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
62
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
63
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
64
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function __generator(thisArg, body) {
|
|
69
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
70
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
71
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
72
|
+
function step(op) {
|
|
73
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
74
|
+
while (_) try {
|
|
75
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
76
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
77
|
+
switch (op[0]) {
|
|
78
|
+
case 0: case 1: t = op; break;
|
|
79
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
80
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
81
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
82
|
+
default:
|
|
83
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
84
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
85
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
86
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
87
|
+
if (t[2]) _.ops.pop();
|
|
88
|
+
_.trys.pop(); continue;
|
|
89
|
+
}
|
|
90
|
+
op = body.call(thisArg, _);
|
|
91
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
92
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function __spreadArray(to, from, pack) {
|
|
97
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
98
|
+
if (ar || !(i in from)) {
|
|
99
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
100
|
+
ar[i] = from[i];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
var EVENT_SYMBOL = Symbol('$$REALSEE_LIVE_EVENT$$');
|
|
17
107
|
function __generateEventIfNotExisted(instance) {
|
|
18
108
|
if (!instance[EVENT_SYMBOL]) {
|
|
19
109
|
instance[EVENT_SYMBOL] = {};
|
|
@@ -36,15 +126,17 @@ function __removeEventIfNotExisted(instance) {
|
|
|
36
126
|
* }>()
|
|
37
127
|
* ```
|
|
38
128
|
*/
|
|
39
|
-
|
|
129
|
+
var Subscribe = /** @class */ (function () {
|
|
130
|
+
function Subscribe() {
|
|
131
|
+
}
|
|
40
132
|
/**
|
|
41
133
|
* 判断是否注册了事件
|
|
42
134
|
* @param name 事件类型
|
|
43
135
|
*/
|
|
44
|
-
hasListener(name) {
|
|
45
|
-
|
|
136
|
+
Subscribe.prototype.hasListener = function (name) {
|
|
137
|
+
var events = __generateEventIfNotExisted(this);
|
|
46
138
|
return events && events[name] && events[name].length > 0;
|
|
47
|
-
}
|
|
139
|
+
};
|
|
48
140
|
/**
|
|
49
141
|
* 注册事件
|
|
50
142
|
* @param name 事件类型
|
|
@@ -54,13 +146,14 @@ class Subscribe {
|
|
|
54
146
|
* @template K 预设的监听事件名称
|
|
55
147
|
* @template C 回调函数函数上下文
|
|
56
148
|
*/
|
|
57
|
-
on(name, callback, once) {
|
|
58
|
-
|
|
149
|
+
Subscribe.prototype.on = function (name, callback, once) {
|
|
150
|
+
var _this = this;
|
|
151
|
+
var events = __generateEventIfNotExisted(this);
|
|
59
152
|
if (!events[name])
|
|
60
153
|
events[name] = [];
|
|
61
154
|
events[name].push([callback, once || false]);
|
|
62
|
-
return ()
|
|
63
|
-
}
|
|
155
|
+
return function () { return _this.off(name, callback); };
|
|
156
|
+
};
|
|
64
157
|
/**
|
|
65
158
|
* 注册事件(是否只执行一次)
|
|
66
159
|
* @param name 事件类型
|
|
@@ -69,9 +162,9 @@ class Subscribe {
|
|
|
69
162
|
* @template K 预设的监听事件名称
|
|
70
163
|
* @template C 回调函数函数上下文
|
|
71
164
|
*/
|
|
72
|
-
once(name, callback) {
|
|
165
|
+
Subscribe.prototype.once = function (name, callback) {
|
|
73
166
|
return this.on(name, callback, true);
|
|
74
|
-
}
|
|
167
|
+
};
|
|
75
168
|
/**
|
|
76
169
|
* 解除事件
|
|
77
170
|
*
|
|
@@ -81,19 +174,19 @@ class Subscribe {
|
|
|
81
174
|
* @param callback 事件回调函数
|
|
82
175
|
* @template K 预设的监听事件名称
|
|
83
176
|
*/
|
|
84
|
-
off(name, callback) {
|
|
177
|
+
Subscribe.prototype.off = function (name, callback) {
|
|
85
178
|
if (name === undefined) {
|
|
86
179
|
__removeEventIfNotExisted(this);
|
|
87
180
|
return;
|
|
88
181
|
}
|
|
89
|
-
|
|
182
|
+
var events = __generateEventIfNotExisted(this);
|
|
90
183
|
if (!events[name])
|
|
91
184
|
events[name] = [];
|
|
92
185
|
if (callback === undefined) {
|
|
93
186
|
events[name].length = 0;
|
|
94
187
|
return;
|
|
95
188
|
}
|
|
96
|
-
|
|
189
|
+
var index = 0;
|
|
97
190
|
for (; index < events[name].length; index++) {
|
|
98
191
|
if (events[name][index][0] === callback)
|
|
99
192
|
break;
|
|
@@ -101,7 +194,7 @@ class Subscribe {
|
|
|
101
194
|
if (index < events[name].length) {
|
|
102
195
|
events[name].splice(index, 1);
|
|
103
196
|
}
|
|
104
|
-
}
|
|
197
|
+
};
|
|
105
198
|
/**
|
|
106
199
|
* 触发事件
|
|
107
200
|
* @param name 事件类型
|
|
@@ -109,27 +202,38 @@ class Subscribe {
|
|
|
109
202
|
* @returns canceled 是否被触发取消
|
|
110
203
|
* @template K 预设的监听事件名称
|
|
111
204
|
*/
|
|
112
|
-
emit(name
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
205
|
+
Subscribe.prototype.emit = function (name) {
|
|
206
|
+
var data = [];
|
|
207
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
208
|
+
data[_i - 1] = arguments[_i];
|
|
209
|
+
}
|
|
210
|
+
var canceled = false;
|
|
211
|
+
var events = __generateEventIfNotExisted(this);
|
|
212
|
+
var event = events[name] || [];
|
|
213
|
+
for (var _a = 0, _b = event.slice(); _a < _b.length; _a++) {
|
|
214
|
+
var one = _b[_a];
|
|
215
|
+
var callback = one[0], _c = one[1], once = _c === void 0 ? false : _c;
|
|
216
|
+
var result = callback.apply(void 0, data);
|
|
119
217
|
if (once)
|
|
120
218
|
this.off(name, callback);
|
|
121
219
|
if (result === false)
|
|
122
220
|
canceled = true;
|
|
123
221
|
}
|
|
124
222
|
return canceled;
|
|
125
|
-
}
|
|
126
|
-
|
|
223
|
+
};
|
|
224
|
+
return Subscribe;
|
|
225
|
+
}());
|
|
127
226
|
|
|
128
227
|
/**
|
|
129
228
|
* rtc 基础抽象类
|
|
130
229
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
230
|
+
var CoreRTC = /** @class */ (function (_super) {
|
|
231
|
+
__extends(CoreRTC, _super);
|
|
232
|
+
function CoreRTC() {
|
|
233
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
234
|
+
}
|
|
235
|
+
return CoreRTC;
|
|
236
|
+
}(Subscribe));
|
|
133
237
|
|
|
134
238
|
/**
|
|
135
239
|
* rtc 类型
|
|
@@ -169,202 +273,231 @@ function uuid() {
|
|
|
169
273
|
S4()).toLowerCase();
|
|
170
274
|
}
|
|
171
275
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
276
|
+
var BrowserRTC = /** @class */ (function (_super) {
|
|
277
|
+
__extends(BrowserRTC, _super);
|
|
278
|
+
function BrowserRTC(options) {
|
|
279
|
+
var _this = _super.call(this) || this;
|
|
280
|
+
_this.type = exports.RTCType.RealseeBrowserRTC;
|
|
281
|
+
_this.joined = false;
|
|
282
|
+
_this.micro = false;
|
|
283
|
+
_this.voiceId = '';
|
|
284
|
+
_this._getVoiceSign = function () {
|
|
180
285
|
throw new Error('方法 getVoiceSign 未实现');
|
|
181
286
|
};
|
|
182
|
-
|
|
183
|
-
|
|
287
|
+
_this.$dom = document.createElement('div');
|
|
288
|
+
_this._trtc = {
|
|
184
289
|
client: null,
|
|
185
290
|
stream: null,
|
|
186
291
|
};
|
|
187
|
-
|
|
292
|
+
_this.join = function (options) { return __awaiter(_this, void 0, void 0, function () {
|
|
293
|
+
var createClientOptions, result;
|
|
294
|
+
var _this = this;
|
|
188
295
|
var _a;
|
|
189
|
-
this
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
296
|
+
return __generator(this, function (_b) {
|
|
297
|
+
switch (_b.label) {
|
|
298
|
+
case 0:
|
|
299
|
+
this.emit('joinWillStart');
|
|
300
|
+
return [4 /*yield*/, this._getVoiceSign({
|
|
301
|
+
voiceId: options.voiceId,
|
|
302
|
+
roomId: options.roomId,
|
|
303
|
+
userId: options.userId,
|
|
304
|
+
})];
|
|
305
|
+
case 1:
|
|
306
|
+
createClientOptions = _b.sent();
|
|
307
|
+
// 1. 创建client
|
|
308
|
+
this._trtc.client = TRTC__default["default"].createClient(__assign({ mode: 'rtc' }, createClientOptions));
|
|
309
|
+
(_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.enableAudioVolumeEvaluation();
|
|
310
|
+
// 2. 订阅事件
|
|
311
|
+
this._registerRtcEvent();
|
|
312
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
313
|
+
var _a;
|
|
314
|
+
(_a = _this._trtc.client) === null || _a === void 0 ? void 0 : _a.join({ roomId: Number(options.voiceId) }).then(function () { return resolve(true); }).catch(function () { return resolve(false); });
|
|
315
|
+
})];
|
|
316
|
+
case 2:
|
|
317
|
+
result = _b.sent();
|
|
318
|
+
this.joined = result;
|
|
319
|
+
if (!result)
|
|
320
|
+
return [2 /*return*/, false]; // 进房失败
|
|
321
|
+
// 4. 创建本地流
|
|
322
|
+
this._trtc.stream = TRTC__default["default"].createStream({
|
|
323
|
+
userId: createClientOptions.userId,
|
|
324
|
+
audio: true,
|
|
325
|
+
video: false,
|
|
326
|
+
});
|
|
327
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
328
|
+
var _a;
|
|
329
|
+
(_a = _this._trtc.stream) === null || _a === void 0 ? void 0 : _a.initialize().then(function () { return resolve(true); }).catch(function () { return resolve(false); });
|
|
330
|
+
})];
|
|
331
|
+
case 3:
|
|
332
|
+
// 5. 初始化本地流
|
|
333
|
+
result = _b.sent();
|
|
334
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
335
|
+
var _a;
|
|
336
|
+
(_a = _this._trtc.client) === null || _a === void 0 ? void 0 : _a.publish(_this._trtc.stream).then(function () { return resolve(true); }).catch(function () { return resolve(false); });
|
|
337
|
+
})];
|
|
338
|
+
case 4:
|
|
339
|
+
// 6. 发布本地流
|
|
340
|
+
result = _b.sent();
|
|
341
|
+
this.joined = result;
|
|
342
|
+
if (this.joined)
|
|
343
|
+
this.emit('joined');
|
|
344
|
+
return [2 /*return*/, result];
|
|
345
|
+
}
|
|
226
346
|
});
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
this.emit('joined');
|
|
230
|
-
return result;
|
|
231
|
-
};
|
|
232
|
-
this._handleStreamAdded = (event) => {
|
|
347
|
+
}); };
|
|
348
|
+
_this._handleStreamAdded = function (event) {
|
|
233
349
|
var _a;
|
|
234
|
-
|
|
350
|
+
var remoteStream = event.stream;
|
|
235
351
|
console.log('远端流增加: ' + remoteStream.getId());
|
|
236
352
|
//订阅远端流
|
|
237
|
-
(_a =
|
|
353
|
+
(_a = _this._trtc.client) === null || _a === void 0 ? void 0 : _a.subscribe(remoteStream);
|
|
238
354
|
};
|
|
239
|
-
|
|
240
|
-
|
|
355
|
+
_this._handleStreamSubscribed = function (event) {
|
|
356
|
+
var remoteStream = event.stream;
|
|
241
357
|
console.log('远端流订阅成功:' + remoteStream.getId());
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
358
|
+
var playId = remoteStream.getId();
|
|
359
|
+
var domId = "rs-rtc-remote_stream-".concat(playId);
|
|
360
|
+
var dom = document.createElement('div');
|
|
245
361
|
dom.id = domId;
|
|
246
|
-
|
|
362
|
+
_this.$dom.appendChild(dom);
|
|
247
363
|
// 播放远端流
|
|
248
364
|
remoteStream.play(domId);
|
|
249
365
|
};
|
|
250
|
-
|
|
251
|
-
|
|
366
|
+
_this._getVoiceSign = options.getVoiceSign;
|
|
367
|
+
_this._initParentDom();
|
|
368
|
+
return _this;
|
|
252
369
|
}
|
|
253
|
-
_initParentDom() {
|
|
254
|
-
this.$dom.id =
|
|
370
|
+
BrowserRTC.prototype._initParentDom = function () {
|
|
371
|
+
this.$dom.id = "rs-rtc-".concat(uuid());
|
|
255
372
|
this.$dom.style.display = 'none';
|
|
256
373
|
document.body.appendChild(this.$dom);
|
|
257
|
-
}
|
|
258
|
-
quit() {
|
|
259
|
-
|
|
374
|
+
};
|
|
375
|
+
BrowserRTC.prototype.quit = function () {
|
|
376
|
+
var _this = this;
|
|
377
|
+
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
|
|
378
|
+
var _this = this;
|
|
260
379
|
var _a, _b;
|
|
261
|
-
this
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
380
|
+
return __generator(this, function (_c) {
|
|
381
|
+
switch (_c.label) {
|
|
382
|
+
case 0:
|
|
383
|
+
this.joined = false;
|
|
384
|
+
if (!this._trtc.stream) return [3 /*break*/, 2];
|
|
385
|
+
return [4 /*yield*/, ((_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.unpublish(this._trtc.stream))];
|
|
386
|
+
case 1:
|
|
387
|
+
_c.sent();
|
|
388
|
+
this._trtc.stream.stop();
|
|
389
|
+
this._trtc.stream.close();
|
|
390
|
+
this._trtc.stream = null;
|
|
391
|
+
_c.label = 2;
|
|
392
|
+
case 2:
|
|
393
|
+
(_b = this._trtc.client) === null || _b === void 0 ? void 0 : _b.leave().then(function () { return (_this._trtc.client = null); }).then(function () { return resolve(true); }).catch(function () { return resolve(false); });
|
|
394
|
+
return [2 /*return*/];
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
}); });
|
|
398
|
+
};
|
|
399
|
+
BrowserRTC.prototype.detectMicro = function () {
|
|
400
|
+
return new Promise(function (resolve) {
|
|
401
|
+
var rule = { audio: true, video: false };
|
|
274
402
|
try {
|
|
275
403
|
navigator.mediaDevices
|
|
276
404
|
.getUserMedia(rule)
|
|
277
|
-
.then(()
|
|
278
|
-
.catch(()
|
|
405
|
+
.then(function () { return resolve(true); })
|
|
406
|
+
.catch(function () { return resolve(false); });
|
|
279
407
|
}
|
|
280
408
|
catch (e) {
|
|
281
409
|
console.error(e);
|
|
282
410
|
resolve(false);
|
|
283
411
|
}
|
|
284
412
|
});
|
|
285
|
-
}
|
|
286
|
-
toggleMicro(flag) {
|
|
413
|
+
};
|
|
414
|
+
BrowserRTC.prototype.toggleMicro = function (flag) {
|
|
287
415
|
var _a, _b, _c, _d;
|
|
288
416
|
return Promise.resolve((flag
|
|
289
417
|
? (_b = (_a = this._trtc) === null || _a === void 0 ? void 0 : _a.stream) === null || _b === void 0 ? void 0 : _b.unmuteAudio()
|
|
290
418
|
: (_d = (_c = this._trtc) === null || _c === void 0 ? void 0 : _c.stream) === null || _d === void 0 ? void 0 : _d.muteAudio()) || false);
|
|
291
|
-
}
|
|
292
|
-
shock() {
|
|
419
|
+
};
|
|
420
|
+
BrowserRTC.prototype.shock = function () {
|
|
293
421
|
throw new Error('Method not implemented.');
|
|
294
|
-
}
|
|
295
|
-
_registerRtcEvent() {
|
|
422
|
+
};
|
|
423
|
+
BrowserRTC.prototype._registerRtcEvent = function () {
|
|
424
|
+
var _this = this;
|
|
296
425
|
var _a, _b, _c, _d;
|
|
297
426
|
(_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.on('stream-added', this._handleStreamAdded);
|
|
298
427
|
(_b = this._trtc.client) === null || _b === void 0 ? void 0 : _b.on('stream-subscribed', this._handleStreamSubscribed);
|
|
299
|
-
(_c = this._trtc.client) === null || _c === void 0 ? void 0 : _c.on('audio-volume', (event)
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
428
|
+
(_c = this._trtc.client) === null || _c === void 0 ? void 0 : _c.on('audio-volume', function (event) {
|
|
429
|
+
return _this.emit('userVolumes', [
|
|
430
|
+
{ userId: event.userId, audioVolume: event.audioVolume },
|
|
431
|
+
]);
|
|
432
|
+
});
|
|
433
|
+
(_d = this._trtc.client) === null || _d === void 0 ? void 0 : _d.on('error', function (event) { return _this.emit('error', event); });
|
|
434
|
+
};
|
|
435
|
+
return BrowserRTC;
|
|
436
|
+
}(CoreRTC));
|
|
305
437
|
|
|
306
438
|
/**
|
|
307
439
|
* amazon-chime-sdk-js 适配的rtc实现
|
|
308
440
|
*/
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
441
|
+
var BrowserRTC4Chime = /** @class */ (function (_super) {
|
|
442
|
+
__extends(BrowserRTC4Chime, _super);
|
|
443
|
+
function BrowserRTC4Chime(options) {
|
|
444
|
+
var _this = _super.call(this) || this;
|
|
445
|
+
_this.type = exports.RTCType.RealseeBrowserChimeRTC;
|
|
446
|
+
_this.joined = false;
|
|
447
|
+
_this.micro = false;
|
|
448
|
+
_this.voiceId = '';
|
|
449
|
+
_this.userId = '';
|
|
450
|
+
_this.deviceChangeObserver = {};
|
|
451
|
+
_this.audioVideoObserver = {};
|
|
452
|
+
_this._getVoiceSign = function () {
|
|
320
453
|
throw new Error('方法 getVoiceSign 未实现');
|
|
321
454
|
};
|
|
322
|
-
|
|
323
|
-
|
|
455
|
+
_this.$dom = document.createElement('div');
|
|
456
|
+
_this.$audio = document.createElement('audio');
|
|
324
457
|
/**
|
|
325
458
|
* 对audio标签初始化
|
|
326
459
|
*/
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
document.body.appendChild(
|
|
460
|
+
_this._initDom = function () {
|
|
461
|
+
_this.$audio.id = "rs-rtc-".concat(uuid());
|
|
462
|
+
_this.$dom.id = "rs-rtc-".concat(uuid());
|
|
463
|
+
_this.$dom.appendChild(_this.$audio);
|
|
464
|
+
document.body.appendChild(_this.$dom);
|
|
332
465
|
};
|
|
333
466
|
/**
|
|
334
467
|
* 初始化事件监听器
|
|
335
468
|
*/
|
|
336
|
-
|
|
469
|
+
_this.initObservers = function () {
|
|
337
470
|
// 输入输出设备变化的监听器
|
|
338
|
-
|
|
339
|
-
audioInputsChanged: (freshAudioInputDeviceList)
|
|
471
|
+
_this.deviceChangeObserver = {
|
|
472
|
+
audioInputsChanged: function (freshAudioInputDeviceList) {
|
|
340
473
|
// An array of MediaDeviceInfo objects
|
|
341
|
-
freshAudioInputDeviceList === null || freshAudioInputDeviceList === void 0 ? void 0 : freshAudioInputDeviceList.forEach((mediaDeviceInfo)
|
|
342
|
-
|
|
474
|
+
freshAudioInputDeviceList === null || freshAudioInputDeviceList === void 0 ? void 0 : freshAudioInputDeviceList.forEach(function (mediaDeviceInfo) {
|
|
475
|
+
_this.logger.info("Device ID: ".concat(mediaDeviceInfo.deviceId, " Microphone: ").concat(mediaDeviceInfo.label));
|
|
343
476
|
});
|
|
344
477
|
},
|
|
345
|
-
audioOutputsChanged: (freshAudioOutputDeviceList)
|
|
346
|
-
|
|
478
|
+
audioOutputsChanged: function (freshAudioOutputDeviceList) {
|
|
479
|
+
_this.logger.info("Audio outputs updated: ".concat(freshAudioOutputDeviceList));
|
|
347
480
|
},
|
|
348
|
-
videoInputsChanged: (freshVideoInputDeviceList)
|
|
349
|
-
|
|
481
|
+
videoInputsChanged: function (freshVideoInputDeviceList) {
|
|
482
|
+
_this.logger.info("Video inputs updated: ".concat(freshVideoInputDeviceList));
|
|
350
483
|
},
|
|
351
|
-
audioInputMuteStateChanged: (device, muted)
|
|
352
|
-
|
|
484
|
+
audioInputMuteStateChanged: function (device, muted) {
|
|
485
|
+
_this.logger.info("Device ".concat(device.toString(), " ").concat(muted ? 'is muted in hardware' : 'is not muted'));
|
|
353
486
|
},
|
|
354
487
|
};
|
|
355
488
|
// 流变化监听器
|
|
356
|
-
|
|
357
|
-
audioVideoDidStart: ()
|
|
358
|
-
|
|
489
|
+
_this.audioVideoObserver = {
|
|
490
|
+
audioVideoDidStart: function () {
|
|
491
|
+
_this.logger.info('Started');
|
|
359
492
|
},
|
|
360
|
-
audioVideoDidStop: (sessionStatus)
|
|
493
|
+
audioVideoDidStop: function (sessionStatus) {
|
|
361
494
|
// See the "Stopping a session" section for details.
|
|
362
|
-
|
|
495
|
+
_this.logger.info("Stopped with a session status code: ".concat(sessionStatus.statusCode()));
|
|
363
496
|
},
|
|
364
|
-
audioVideoDidStartConnecting: (reconnecting)
|
|
497
|
+
audioVideoDidStartConnecting: function (reconnecting) {
|
|
365
498
|
if (reconnecting) {
|
|
366
499
|
// e.g. the WiFi connection is dropped.
|
|
367
|
-
|
|
500
|
+
_this.logger.info('Attempting to reconnect');
|
|
368
501
|
}
|
|
369
502
|
},
|
|
370
503
|
};
|
|
@@ -372,15 +505,15 @@ class BrowserRTC4Chime extends CoreRTC {
|
|
|
372
505
|
/**
|
|
373
506
|
* 注册rtc事件
|
|
374
507
|
*/
|
|
375
|
-
|
|
508
|
+
_this._registerRtcEvent = function () {
|
|
376
509
|
var _a, _b, _c, _d, _e, _f;
|
|
377
|
-
|
|
510
|
+
var presentAttendeeId = ((_c = (_b = (_a = _this.meetingSession) === null || _a === void 0 ? void 0 : _a.configuration) === null || _b === void 0 ? void 0 : _b.credentials) === null || _c === void 0 ? void 0 : _c.attendeeId) || '';
|
|
378
511
|
if (presentAttendeeId) {
|
|
379
512
|
// 处理音量变化
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
513
|
+
var roster_1 = new Map();
|
|
514
|
+
var getUserVolumes_1 = function () {
|
|
515
|
+
var result = [];
|
|
516
|
+
roster_1.forEach(function (v, k) {
|
|
384
517
|
result.push({
|
|
385
518
|
userId: v.userId,
|
|
386
519
|
volume: v.muted || v.signalStrength === 0 || !Boolean(v.volume)
|
|
@@ -390,177 +523,208 @@ class BrowserRTC4Chime extends CoreRTC {
|
|
|
390
523
|
});
|
|
391
524
|
return result;
|
|
392
525
|
};
|
|
393
|
-
(_d =
|
|
526
|
+
(_d = _this.meetingSession) === null || _d === void 0 ? void 0 : _d.audioVideo.realtimeSubscribeToAttendeeIdPresence(function (presentAttendeeId, present, externalUserId) {
|
|
394
527
|
var _a;
|
|
395
528
|
if (!present) {
|
|
396
|
-
|
|
397
|
-
|
|
529
|
+
roster_1.delete(presentAttendeeId);
|
|
530
|
+
_this.emit('userVolumes', getUserVolumes_1());
|
|
398
531
|
return;
|
|
399
532
|
}
|
|
400
|
-
(_a =
|
|
401
|
-
|
|
533
|
+
(_a = _this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.realtimeSubscribeToVolumeIndicator(presentAttendeeId, function (attendeeId, volume, muted, signalStrength) {
|
|
534
|
+
var baseAttendeeId = new amazonChimeSdkJs.DefaultModality(attendeeId).base();
|
|
402
535
|
if (baseAttendeeId !== attendeeId) {
|
|
403
536
|
// Optional: Do not include the content attendee (attendee-id#content) in the roster.
|
|
404
537
|
// See the "Screen and content share" section for details.
|
|
405
538
|
return;
|
|
406
539
|
}
|
|
407
|
-
|
|
540
|
+
roster_1.set(attendeeId, {
|
|
408
541
|
userId: externalUserId || attendeeId,
|
|
409
|
-
volume,
|
|
410
|
-
muted,
|
|
411
|
-
signalStrength,
|
|
542
|
+
volume: volume,
|
|
543
|
+
muted: muted,
|
|
544
|
+
signalStrength: signalStrength,
|
|
412
545
|
});
|
|
413
|
-
|
|
546
|
+
_this.emit('userVolumes', getUserVolumes_1());
|
|
414
547
|
});
|
|
415
548
|
});
|
|
416
549
|
// 弱网
|
|
417
|
-
(_e =
|
|
418
|
-
|
|
550
|
+
(_e = _this.meetingSession) === null || _e === void 0 ? void 0 : _e.audioVideo.realtimeSubscribeToVolumeIndicator(presentAttendeeId, function (attendeeId, volume, muted, signalStrength) {
|
|
551
|
+
var baseAttendeeId = new amazonChimeSdkJs.DefaultModality(attendeeId).base();
|
|
419
552
|
if (baseAttendeeId === attendeeId) {
|
|
420
553
|
if (signalStrength !== null && signalStrength !== 1) {
|
|
421
|
-
|
|
554
|
+
_this.emit('weakNetwork');
|
|
422
555
|
}
|
|
423
556
|
}
|
|
424
557
|
});
|
|
425
558
|
// 报错
|
|
426
|
-
(_f =
|
|
559
|
+
(_f = _this.meetingSession) === null || _f === void 0 ? void 0 : _f.audioVideo.realtimeSubscribeToFatalError(function (error) { return _this.emit('error', error); });
|
|
427
560
|
}
|
|
428
561
|
};
|
|
429
562
|
// 挂载签名钩子
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
563
|
+
_this._getVoiceSign = options.getVoiceSign;
|
|
564
|
+
_this._initDom();
|
|
565
|
+
_this.logger = new amazonChimeSdkJs.ConsoleLogger('WebRTCLogger', options.logLevel || amazonChimeSdkJs.LogLevel.OFF);
|
|
566
|
+
_this.deviceController = new amazonChimeSdkJs.DefaultDeviceController(_this.logger);
|
|
567
|
+
_this.initObservers();
|
|
568
|
+
return _this;
|
|
435
569
|
}
|
|
436
570
|
/**
|
|
437
571
|
* 加入语音会议
|
|
438
572
|
* @param options
|
|
439
573
|
* @returns
|
|
440
574
|
*/
|
|
441
|
-
|
|
442
|
-
return
|
|
443
|
-
var
|
|
444
|
-
this
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
575
|
+
BrowserRTC4Chime.prototype.join = function (options) {
|
|
576
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
577
|
+
var _this = this;
|
|
578
|
+
return __generator(this, function (_a) {
|
|
579
|
+
return [2 /*return*/, new Promise(function (success, fail) { return __awaiter(_this, void 0, void 0, function () {
|
|
580
|
+
var _a, userId, userSig, _b, attendence, vendor_wrapper, configuration, observer, audioInputDevices, defaultAudioInput, otherAudioInput, e_1;
|
|
581
|
+
var _this = this;
|
|
582
|
+
var _c;
|
|
583
|
+
return __generator(this, function (_d) {
|
|
584
|
+
switch (_d.label) {
|
|
585
|
+
case 0:
|
|
586
|
+
this.emit('joinWillStart');
|
|
587
|
+
_d.label = 1;
|
|
588
|
+
case 1:
|
|
589
|
+
_d.trys.push([1, 6, , 7]);
|
|
590
|
+
return [4 /*yield*/, this._getVoiceSign(__assign(__assign({}, options), { roomId: options.roomId || 0 }))];
|
|
591
|
+
case 2:
|
|
592
|
+
_a = _d.sent(), userId = _a.userId, userSig = _a.userSig;
|
|
593
|
+
this.userId = userId;
|
|
594
|
+
_b = JSON.parse(decodeURIComponent(userSig)), attendence = _b.attendence, vendor_wrapper = _b.vendor_wrapper;
|
|
595
|
+
configuration = new amazonChimeSdkJs.MeetingSessionConfiguration({
|
|
596
|
+
Meeting: vendor_wrapper,
|
|
597
|
+
}, {
|
|
598
|
+
Attendee: {
|
|
599
|
+
ExternalUserId: attendence.external_user_id,
|
|
600
|
+
AttendeeId: attendence.attendee_id,
|
|
601
|
+
JoinToken: attendence.join_token,
|
|
602
|
+
},
|
|
603
|
+
});
|
|
604
|
+
// 初始化会议会话
|
|
605
|
+
this.meetingSession = new amazonChimeSdkJs.DefaultMeetingSession(configuration, this.logger, this.deviceController);
|
|
606
|
+
// 注册事件
|
|
607
|
+
this._registerRtcEvent();
|
|
608
|
+
// 绑定监听器
|
|
609
|
+
this.meetingSession.audioVideo.addDeviceChangeObserver(this.deviceChangeObserver);
|
|
610
|
+
this.meetingSession.audioVideo.addObserver(this.audioVideoObserver);
|
|
611
|
+
// 绑定播放器
|
|
612
|
+
this.meetingSession.audioVideo.bindAudioElement(this.$audio);
|
|
613
|
+
observer = {
|
|
614
|
+
audioVideoDidStart: function () {
|
|
615
|
+
var _a;
|
|
616
|
+
(_a = _this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.realtimeMuteLocalAudio();
|
|
617
|
+
_this.joined = true;
|
|
618
|
+
_this.emit('joined');
|
|
619
|
+
success(true);
|
|
620
|
+
},
|
|
621
|
+
audioVideoDidStop: function () {
|
|
622
|
+
_this.joined = false;
|
|
623
|
+
success(false);
|
|
624
|
+
},
|
|
625
|
+
};
|
|
626
|
+
this.meetingSession.audioVideo.addObserver(observer);
|
|
627
|
+
return [4 /*yield*/, this.deviceController.listAudioInputDevices(true)];
|
|
628
|
+
case 3:
|
|
629
|
+
audioInputDevices = _d.sent();
|
|
630
|
+
defaultAudioInput = audioInputDevices.find(function (device) { return device.deviceId === 'default'; });
|
|
631
|
+
otherAudioInput = audioInputDevices.find(function (device) { return device.deviceId !== ''; });
|
|
632
|
+
this.audioInput = defaultAudioInput || otherAudioInput;
|
|
633
|
+
return [4 /*yield*/, this.meetingSession.audioVideo.chooseVideoInputDevice(null)];
|
|
634
|
+
case 4:
|
|
635
|
+
_d.sent();
|
|
636
|
+
return [4 /*yield*/, this.meetingSession.audioVideo.chooseAudioInputDevice(((_c = this.audioInput) === null || _c === void 0 ? void 0 : _c.deviceId) || 'default')];
|
|
637
|
+
case 5:
|
|
638
|
+
_d.sent();
|
|
639
|
+
this.meetingSession.audioVideo.start();
|
|
640
|
+
return [3 /*break*/, 7];
|
|
641
|
+
case 6:
|
|
642
|
+
e_1 = _d.sent();
|
|
643
|
+
this.emit('error', e_1);
|
|
644
|
+
this.logger.error(e_1.message);
|
|
645
|
+
success(false);
|
|
646
|
+
return [3 /*break*/, 7];
|
|
647
|
+
case 7: return [2 /*return*/];
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
}); })];
|
|
651
|
+
});
|
|
500
652
|
});
|
|
501
|
-
}
|
|
502
|
-
quit() {
|
|
653
|
+
};
|
|
654
|
+
BrowserRTC4Chime.prototype.quit = function () {
|
|
655
|
+
var _this = this;
|
|
503
656
|
if (!this.joined)
|
|
504
657
|
return Promise.resolve(true);
|
|
505
|
-
return new Promise((success, fail)
|
|
658
|
+
return new Promise(function (success, fail) {
|
|
506
659
|
var _a, _b;
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
audioVideoDidStop: (sessionStatus)
|
|
510
|
-
|
|
660
|
+
_this.joined = false;
|
|
661
|
+
var observer = {
|
|
662
|
+
audioVideoDidStop: function (sessionStatus) {
|
|
663
|
+
var sessionStatusCode = sessionStatus.statusCode();
|
|
511
664
|
if (sessionStatusCode === amazonChimeSdkJs.MeetingSessionStatusCode.Left) {
|
|
512
665
|
/*
|
|
513
666
|
- You called meetingSession.audioVideo.stop().
|
|
514
667
|
- When closing a browser window or page, Chime SDK attempts to leave the session.
|
|
515
668
|
*/
|
|
516
|
-
|
|
669
|
+
_this.logger.info('You left the session');
|
|
517
670
|
success(true);
|
|
518
671
|
}
|
|
519
672
|
else {
|
|
520
|
-
|
|
673
|
+
_this.logger.info("Stopped with a session status code: ".concat(sessionStatusCode));
|
|
521
674
|
success(true);
|
|
522
675
|
}
|
|
523
676
|
},
|
|
524
677
|
};
|
|
525
|
-
(_a =
|
|
526
|
-
(_b =
|
|
678
|
+
(_a = _this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.addObserver(observer);
|
|
679
|
+
(_b = _this.meetingSession) === null || _b === void 0 ? void 0 : _b.audioVideo.stop();
|
|
527
680
|
});
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
return
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
681
|
+
};
|
|
682
|
+
BrowserRTC4Chime.prototype.detectMicro = function () {
|
|
683
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
684
|
+
var _this = this;
|
|
685
|
+
return __generator(this, function (_a) {
|
|
686
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
687
|
+
var rule = { audio: true, video: false };
|
|
688
|
+
try {
|
|
689
|
+
navigator.mediaDevices
|
|
690
|
+
.getUserMedia(rule)
|
|
691
|
+
.then(function () { return resolve(true); })
|
|
692
|
+
.catch(function () { return resolve(false); });
|
|
693
|
+
}
|
|
694
|
+
catch (e) {
|
|
695
|
+
_this.logger.error(e.message);
|
|
696
|
+
resolve(false);
|
|
697
|
+
}
|
|
698
|
+
})];
|
|
699
|
+
});
|
|
542
700
|
});
|
|
543
|
-
}
|
|
544
|
-
|
|
701
|
+
};
|
|
702
|
+
BrowserRTC4Chime.prototype.toggleMicro = function (flag) {
|
|
545
703
|
var _a, _b, _c;
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
704
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
705
|
+
var muted;
|
|
706
|
+
return __generator(this, function (_d) {
|
|
707
|
+
if (flag) {
|
|
708
|
+
(_a = this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.realtimeUnmuteLocalAudio();
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
(_b = this.meetingSession) === null || _b === void 0 ? void 0 : _b.audioVideo.realtimeMuteLocalAudio();
|
|
712
|
+
}
|
|
713
|
+
muted = (_c = this.meetingSession) === null || _c === void 0 ? void 0 : _c.audioVideo.realtimeIsLocalAudioMuted();
|
|
714
|
+
if (muted !== undefined) {
|
|
715
|
+
return [2 /*return*/, flag !== muted];
|
|
716
|
+
}
|
|
717
|
+
else {
|
|
718
|
+
return [2 /*return*/, false];
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
};
|
|
723
|
+
BrowserRTC4Chime.prototype.shock = function () {
|
|
561
724
|
throw new Error('Method not implemented.');
|
|
562
|
-
}
|
|
563
|
-
|
|
725
|
+
};
|
|
726
|
+
return BrowserRTC4Chime;
|
|
727
|
+
}(CoreRTC));
|
|
564
728
|
|
|
565
729
|
/**
|
|
566
730
|
* rtc加入返回值code枚举
|
|
@@ -585,75 +749,122 @@ exports.RTCJoinedInfoCodeEnum = void 0;
|
|
|
585
749
|
RTCJoinedInfoCodeEnum[RTCJoinedInfoCodeEnum["NoMicroPermission"] = 3] = "NoMicroPermission";
|
|
586
750
|
})(exports.RTCJoinedInfoCodeEnum || (exports.RTCJoinedInfoCodeEnum = {}));
|
|
587
751
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
752
|
+
var VRWebViewRTC = /** @class */ (function (_super) {
|
|
753
|
+
__extends(VRWebViewRTC, _super);
|
|
754
|
+
function VRWebViewRTC(_a) {
|
|
755
|
+
var jsBridge = _a.jsBridge, getVoiceSign = _a.getVoiceSign;
|
|
756
|
+
var _this = _super.call(this) || this;
|
|
757
|
+
_this.type = exports.RTCType.RealseeVRWebViewRTC;
|
|
758
|
+
_this.joined = false;
|
|
759
|
+
_this.micro = false;
|
|
760
|
+
_this.voiceId = '';
|
|
761
|
+
_this.options = { jsBridge: jsBridge, getVoiceSign: getVoiceSign };
|
|
762
|
+
_this.jsBridge.callAndListen('live/userVolumes', function (userVolumes) {
|
|
763
|
+
_this.emit('userVolumes', userVolumes);
|
|
598
764
|
});
|
|
599
|
-
|
|
765
|
+
_this.jsBridge.callAndListen('live/weakNetwork', function (weakNetwork) {
|
|
600
766
|
if (weakNetwork)
|
|
601
|
-
|
|
767
|
+
_this.emit('weakNetwork');
|
|
602
768
|
});
|
|
769
|
+
return _this;
|
|
603
770
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
this
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
this
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
771
|
+
Object.defineProperty(VRWebViewRTC.prototype, "jsBridge", {
|
|
772
|
+
get: function () {
|
|
773
|
+
return this.options.jsBridge;
|
|
774
|
+
},
|
|
775
|
+
enumerable: false,
|
|
776
|
+
configurable: true
|
|
777
|
+
});
|
|
778
|
+
VRWebViewRTC.prototype.join = function (options) {
|
|
779
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
780
|
+
var _a, sdkAppId, userId, userSig, _b, res, error;
|
|
781
|
+
return __generator(this, function (_c) {
|
|
782
|
+
switch (_c.label) {
|
|
783
|
+
case 0:
|
|
784
|
+
this.emit('joinWillStart');
|
|
785
|
+
return [4 /*yield*/, this.options.getVoiceSign(options)];
|
|
786
|
+
case 1:
|
|
787
|
+
_a = _c.sent(), sdkAppId = _a.sdkAppId, userId = _a.userId, userSig = _a.userSig;
|
|
788
|
+
this.type = options.type;
|
|
789
|
+
return [4 /*yield*/, this.jsBridge.callAndBackfeed("live/join?sdkAppID=".concat(sdkAppId, "&userID=").concat(userId, "&roomID=").concat(Number(options.voiceId), "&userSig=").concat(userSig))];
|
|
790
|
+
case 2:
|
|
791
|
+
_b = _c.sent(), res = _b[0], error = _b[1];
|
|
792
|
+
if (!res) {
|
|
793
|
+
this.emit('error', error ? error : new Error('加入房间失败:未知异常。'));
|
|
794
|
+
this.joined = false;
|
|
795
|
+
}
|
|
796
|
+
else {
|
|
797
|
+
if (res.code === exports.RTCJoinedInfoCodeEnum.Success) {
|
|
798
|
+
this.emit('joined');
|
|
799
|
+
this.joined = true;
|
|
800
|
+
}
|
|
801
|
+
else {
|
|
802
|
+
this.emit('error', res);
|
|
803
|
+
this.joined = false;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return [2 /*return*/, this.joined];
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
});
|
|
810
|
+
};
|
|
811
|
+
VRWebViewRTC.prototype.quit = function () {
|
|
812
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
813
|
+
var _a, res, error;
|
|
814
|
+
return __generator(this, function (_b) {
|
|
815
|
+
switch (_b.label) {
|
|
816
|
+
case 0: return [4 /*yield*/, this.jsBridge.callAndBackfeed('live/quit')];
|
|
817
|
+
case 1:
|
|
818
|
+
_a = _b.sent(), res = _a[0], error = _a[1];
|
|
819
|
+
if (res === null) {
|
|
820
|
+
this.emit('error', error ? error : new Error('退出房间失败:未知异常。'));
|
|
821
|
+
}
|
|
822
|
+
this.joined = false;
|
|
823
|
+
return [2 /*return*/, !!res];
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
});
|
|
827
|
+
};
|
|
828
|
+
VRWebViewRTC.prototype.detectMicro = function () {
|
|
829
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
830
|
+
var _a, res, error;
|
|
831
|
+
return __generator(this, function (_b) {
|
|
832
|
+
switch (_b.label) {
|
|
833
|
+
case 0: return [4 /*yield*/, this.jsBridge.detectMicro()];
|
|
834
|
+
case 1:
|
|
835
|
+
_a = _b.sent(), res = _a[0], error = _a[1];
|
|
836
|
+
if (res === null) {
|
|
837
|
+
this.emit('error', error ? error : new Error('麦克风监测异常!'));
|
|
838
|
+
return [2 /*return*/, false];
|
|
839
|
+
}
|
|
840
|
+
return [2 /*return*/, res];
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
});
|
|
844
|
+
};
|
|
845
|
+
VRWebViewRTC.prototype.toggleMicro = function (flag) {
|
|
846
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
847
|
+
var _a, res, error;
|
|
848
|
+
return __generator(this, function (_b) {
|
|
849
|
+
switch (_b.label) {
|
|
850
|
+
case 0: return [4 /*yield*/, this.jsBridge.callAndBackfeed("live/toggleMicro?flag=".concat(!!flag ? 1 : 0))];
|
|
851
|
+
case 1:
|
|
852
|
+
_a = _b.sent(), res = _a[0], error = _a[1];
|
|
853
|
+
if (res === null) {
|
|
854
|
+
this.emit('error', error ? error : new Error('麦克风监测异常!'));
|
|
855
|
+
return [2 /*return*/, false];
|
|
856
|
+
}
|
|
857
|
+
this.micro = res;
|
|
858
|
+
return [2 /*return*/, res];
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
});
|
|
862
|
+
};
|
|
863
|
+
VRWebViewRTC.prototype.shock = function () {
|
|
654
864
|
this.jsBridge.shock(1);
|
|
655
|
-
}
|
|
656
|
-
|
|
865
|
+
};
|
|
866
|
+
return VRWebViewRTC;
|
|
867
|
+
}(CoreRTC));
|
|
657
868
|
|
|
658
869
|
/**
|
|
659
870
|
* WebSocket 通信指令
|
|
@@ -738,8 +949,8 @@ exports.MicroStatus = void 0;
|
|
|
738
949
|
*/
|
|
739
950
|
function parseLiveMsg(jsonTxt) {
|
|
740
951
|
try {
|
|
741
|
-
|
|
742
|
-
|
|
952
|
+
var msg = JSON.parse(jsonTxt);
|
|
953
|
+
var resMsg_1 = {
|
|
743
954
|
code: msg.code,
|
|
744
955
|
message: msg.message,
|
|
745
956
|
command: msg.command,
|
|
@@ -750,11 +961,11 @@ function parseLiveMsg(jsonTxt) {
|
|
|
750
961
|
triggerUserID: msg.trigger_user_id,
|
|
751
962
|
data: msg.data || {},
|
|
752
963
|
};
|
|
753
|
-
|
|
964
|
+
var undefinedKeys = Object.keys(resMsg_1).filter(function (key) { return resMsg_1[key] === undefined; });
|
|
754
965
|
if (undefinedKeys.length > 0) {
|
|
755
|
-
console.warn(
|
|
966
|
+
console.warn("\u63A8\u9001\u6570\u636E\u683C\u5F0F\u5F02\u5E38\uFF1A".concat(undefinedKeys.join(" "), " \u503C\u4E0D\u5B58\u5728\uFF01"));
|
|
756
967
|
}
|
|
757
|
-
return
|
|
968
|
+
return resMsg_1;
|
|
758
969
|
}
|
|
759
970
|
catch (error) {
|
|
760
971
|
// notcare? 过滤掉所有不符合规范的数据
|
|
@@ -892,16 +1103,19 @@ function parseWSClsErr(code) {
|
|
|
892
1103
|
}
|
|
893
1104
|
|
|
894
1105
|
function appendUri(uri, query) {
|
|
895
|
-
|
|
896
|
-
|
|
1106
|
+
if (query === void 0) { query = {}; }
|
|
1107
|
+
var hasQuery = uri.indexOf('?') !== -1;
|
|
1108
|
+
var newQuery = Object.keys(query).reduce(function (accu, curr, idx) {
|
|
1109
|
+
return "".concat(accu).concat((idx === 0 && !hasQuery) ? '?' : '&').concat(curr, "=").concat(query[curr]);
|
|
1110
|
+
}, '');
|
|
897
1111
|
return uri + newQuery;
|
|
898
1112
|
}
|
|
899
1113
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
1114
|
+
var userAgent = globalThis.navigator.userAgent;
|
|
1115
|
+
var isAndroid = /android/gi.test(userAgent);
|
|
1116
|
+
var isIOS = /iPhone|iPad\s+OS/gi.test(userAgent);
|
|
1117
|
+
var isWxMiniProgram = /MicroMessenger/gi.test(userAgent) && /miniProgram/gi.test(userAgent);
|
|
1118
|
+
var isRealseeVRWebview = /realsee/gi.test(userAgent);
|
|
905
1119
|
|
|
906
1120
|
/**
|
|
907
1121
|
* 判断是否是真实的对象类型
|
|
@@ -933,12 +1147,12 @@ function baseIsEqual(value, other) {
|
|
|
933
1147
|
* @returns
|
|
934
1148
|
*/
|
|
935
1149
|
function objEqualShallow(value, other) {
|
|
936
|
-
|
|
937
|
-
|
|
1150
|
+
var valueProps = Object.getOwnPropertyNames(value);
|
|
1151
|
+
var otherProps = Object.getOwnPropertyNames(other);
|
|
938
1152
|
if (valueProps.length !== otherProps.length)
|
|
939
1153
|
return false;
|
|
940
|
-
for (
|
|
941
|
-
|
|
1154
|
+
for (var i = 0, len = valueProps.length; i < len; i++) {
|
|
1155
|
+
var propName = valueProps[i];
|
|
942
1156
|
if (!baseIsEqual(value[propName], other[propName]))
|
|
943
1157
|
return false;
|
|
944
1158
|
}
|
|
@@ -953,7 +1167,7 @@ function objEqualShallow(value, other) {
|
|
|
953
1167
|
function arrayEqualShallow(value, other) {
|
|
954
1168
|
if (value.length !== other.length)
|
|
955
1169
|
return false;
|
|
956
|
-
for (
|
|
1170
|
+
for (var i = 0, len = value.length; i < len; i++) {
|
|
957
1171
|
if (!baseIsEqual(value[i], other[i]))
|
|
958
1172
|
return false;
|
|
959
1173
|
}
|
|
@@ -998,7 +1212,7 @@ function isDeepEqual(value, other) {
|
|
|
998
1212
|
function arrayEqualDeep(value, other) {
|
|
999
1213
|
if (value.length !== other.length)
|
|
1000
1214
|
return false;
|
|
1001
|
-
for (
|
|
1215
|
+
for (var i = 0, len = value.length; i < len; i++) {
|
|
1002
1216
|
if (!isDeepEqual(value[i], other[i]))
|
|
1003
1217
|
return false;
|
|
1004
1218
|
}
|
|
@@ -1011,12 +1225,12 @@ function arrayEqualDeep(value, other) {
|
|
|
1011
1225
|
* @returns
|
|
1012
1226
|
*/
|
|
1013
1227
|
function objEqualDeep(value, other) {
|
|
1014
|
-
|
|
1015
|
-
|
|
1228
|
+
var valueProps = Object.getOwnPropertyNames(value);
|
|
1229
|
+
var otherProps = Object.getOwnPropertyNames(other);
|
|
1016
1230
|
if (valueProps.length !== otherProps.length)
|
|
1017
1231
|
return false;
|
|
1018
|
-
for (
|
|
1019
|
-
|
|
1232
|
+
for (var i = 0, len = valueProps.length; i < len; i++) {
|
|
1233
|
+
var propName = valueProps[i];
|
|
1020
1234
|
if (!isDeepEqual(value[propName], other[propName]))
|
|
1021
1235
|
return false;
|
|
1022
1236
|
}
|
|
@@ -1030,13 +1244,15 @@ function objEqualDeep(value, other) {
|
|
|
1030
1244
|
* @returns {boolean} 是否相等。
|
|
1031
1245
|
*/
|
|
1032
1246
|
function equal(value, other, opt) {
|
|
1247
|
+
if (opt === void 0) { opt = { deep: false }; }
|
|
1033
1248
|
if (!opt.deep)
|
|
1034
1249
|
return isShallowEqual(value, other);
|
|
1035
1250
|
return isDeepEqual(value, other);
|
|
1036
1251
|
}
|
|
1037
1252
|
|
|
1038
|
-
|
|
1039
|
-
|
|
1253
|
+
var LiveController = /** @class */ (function () {
|
|
1254
|
+
function LiveController(options) {
|
|
1255
|
+
var _this = this;
|
|
1040
1256
|
this.readyState = exports.WebSocketState.NOTINITIALIZED;
|
|
1041
1257
|
this.canSync = true;
|
|
1042
1258
|
this.connecting = false;
|
|
@@ -1044,56 +1260,56 @@ class LiveController {
|
|
|
1044
1260
|
/**
|
|
1045
1261
|
* 检测 WebSocket.readyState 状态
|
|
1046
1262
|
*/
|
|
1047
|
-
this.checkReadyState = (live)
|
|
1263
|
+
this.checkReadyState = function (live) {
|
|
1048
1264
|
do {
|
|
1049
|
-
if (!
|
|
1050
|
-
if (
|
|
1051
|
-
|
|
1052
|
-
live.emit('ws.readyStateUpdate',
|
|
1265
|
+
if (!_this.webSocket) {
|
|
1266
|
+
if (_this.readyState !== exports.WebSocketState.NOTINITIALIZED) {
|
|
1267
|
+
_this.readyState = exports.WebSocketState.NOTINITIALIZED;
|
|
1268
|
+
live.emit('ws.readyStateUpdate', _this.readyState);
|
|
1053
1269
|
}
|
|
1054
1270
|
break;
|
|
1055
1271
|
}
|
|
1056
|
-
|
|
1057
|
-
if (readyState !==
|
|
1058
|
-
|
|
1059
|
-
live.emit('ws.readyStateUpdate',
|
|
1272
|
+
var readyState = _this.webSocket.readyState;
|
|
1273
|
+
if (readyState !== _this.readyState) {
|
|
1274
|
+
_this.readyState = readyState;
|
|
1275
|
+
live.emit('ws.readyStateUpdate', _this.readyState);
|
|
1060
1276
|
}
|
|
1061
1277
|
} while (false);
|
|
1062
|
-
return
|
|
1278
|
+
return _this.readyState;
|
|
1063
1279
|
};
|
|
1064
|
-
this.dispose = ()
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
if (
|
|
1068
|
-
clearInterval(
|
|
1069
|
-
|
|
1280
|
+
this.dispose = function () {
|
|
1281
|
+
_this.disposeWebSocket();
|
|
1282
|
+
_this.connecting = false;
|
|
1283
|
+
if (_this.healthCheckId) {
|
|
1284
|
+
clearInterval(_this.healthCheckId);
|
|
1285
|
+
_this.healthCheckId = undefined;
|
|
1070
1286
|
}
|
|
1071
1287
|
return true;
|
|
1072
1288
|
};
|
|
1073
1289
|
/**
|
|
1074
1290
|
* 销毁WebSocket相关依赖。
|
|
1075
1291
|
*/
|
|
1076
|
-
this.disposeWebSocket = ()
|
|
1077
|
-
if (!
|
|
1292
|
+
this.disposeWebSocket = function () {
|
|
1293
|
+
if (!_this.webSocket)
|
|
1078
1294
|
return;
|
|
1079
|
-
if (
|
|
1080
|
-
|
|
1081
|
-
|
|
1295
|
+
if (_this.onEvtOpnListener) {
|
|
1296
|
+
_this.webSocket.removeEventListener('open', _this.onEvtOpnListener);
|
|
1297
|
+
_this.onEvtOpnListener = undefined;
|
|
1082
1298
|
}
|
|
1083
|
-
if (
|
|
1084
|
-
|
|
1085
|
-
|
|
1299
|
+
if (_this.onEvtMsgListener) {
|
|
1300
|
+
_this.webSocket.removeEventListener('message', _this.onEvtMsgListener);
|
|
1301
|
+
_this.onEvtMsgListener = undefined;
|
|
1086
1302
|
}
|
|
1087
|
-
if (
|
|
1088
|
-
|
|
1089
|
-
|
|
1303
|
+
if (_this.onEvtErrListener) {
|
|
1304
|
+
_this.webSocket.removeEventListener('error', _this.onEvtErrListener);
|
|
1305
|
+
_this.onEvtErrListener = undefined;
|
|
1090
1306
|
}
|
|
1091
|
-
if (
|
|
1092
|
-
|
|
1093
|
-
|
|
1307
|
+
if (_this.onEvtCLEListener) {
|
|
1308
|
+
_this.webSocket.removeEventListener('close', _this.onEvtCLEListener);
|
|
1309
|
+
_this.onEvtCLEListener = undefined;
|
|
1094
1310
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1311
|
+
_this.webSocket.close();
|
|
1312
|
+
_this.webSocket = undefined;
|
|
1097
1313
|
return true;
|
|
1098
1314
|
};
|
|
1099
1315
|
this.options = Object.assign({ autoConnect: true, healthCheck: 3000 }, options);
|
|
@@ -1103,16 +1319,17 @@ class LiveController {
|
|
|
1103
1319
|
* @param liveMsg
|
|
1104
1320
|
* @param live
|
|
1105
1321
|
*/
|
|
1106
|
-
handleMessage(liveMsg, live) {
|
|
1322
|
+
LiveController.prototype.handleMessage = function (liveMsg, live) {
|
|
1323
|
+
var _this = this;
|
|
1107
1324
|
var _a, _b, _c;
|
|
1108
|
-
|
|
1325
|
+
var command = liveMsg.command, data = liveMsg.data, frontRequestId = liveMsg.frontRequestId, code = liveMsg.code;
|
|
1109
1326
|
if (code === 'SUCCESS') {
|
|
1110
1327
|
switch (command) {
|
|
1111
1328
|
/**
|
|
1112
1329
|
* 自己的状态变化
|
|
1113
1330
|
*/
|
|
1114
1331
|
case exports.Command.SelfUserInfo: {
|
|
1115
|
-
|
|
1332
|
+
var selfInfo = data;
|
|
1116
1333
|
if (equal(this.selfUserInfo, selfInfo, { deep: true }))
|
|
1117
1334
|
return;
|
|
1118
1335
|
this.selfUserInfo = selfInfo;
|
|
@@ -1123,7 +1340,7 @@ class LiveController {
|
|
|
1123
1340
|
* 房间信息变化
|
|
1124
1341
|
*/
|
|
1125
1342
|
case exports.Command.RoomInfo: {
|
|
1126
|
-
|
|
1343
|
+
var roomInfo = data;
|
|
1127
1344
|
this.roomInfo = Object.assign({}, roomInfo);
|
|
1128
1345
|
live.emit('readyKeyframeSync', (roomInfo.last_frame || {}));
|
|
1129
1346
|
break;
|
|
@@ -1132,16 +1349,16 @@ class LiveController {
|
|
|
1132
1349
|
* 语音信息变化
|
|
1133
1350
|
*/
|
|
1134
1351
|
case exports.Command.RTCInfo: {
|
|
1135
|
-
|
|
1352
|
+
var _d = data, voiceId = _d.voice_id, type = _d.type;
|
|
1136
1353
|
/* 如果已经进入语音房间,则不重复进入 --> "RTCInfo" 指令可能会下发多次 */
|
|
1137
1354
|
if (live.$RTC.joined) {
|
|
1138
1355
|
break;
|
|
1139
1356
|
}
|
|
1140
1357
|
live.$RTC.join({
|
|
1141
|
-
voiceId,
|
|
1358
|
+
voiceId: voiceId,
|
|
1142
1359
|
userId: ((_a = this.selfUserInfo) === null || _a === void 0 ? void 0 : _a.id) || '',
|
|
1143
1360
|
roomId: (_b = this.roomInfo) === null || _b === void 0 ? void 0 : _b.info.room_code,
|
|
1144
|
-
type,
|
|
1361
|
+
type: type,
|
|
1145
1362
|
});
|
|
1146
1363
|
// 加入房间后 麦克风默认就开启了:需要发个指令。
|
|
1147
1364
|
live.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
|
|
@@ -1153,7 +1370,7 @@ class LiveController {
|
|
|
1153
1370
|
* 房间用户列表变化
|
|
1154
1371
|
*/
|
|
1155
1372
|
case exports.Command.UserList: {
|
|
1156
|
-
|
|
1373
|
+
var userList = data;
|
|
1157
1374
|
this.userList = userList;
|
|
1158
1375
|
live.emit('userListUpdate', this.userList, frontRequestId);
|
|
1159
1376
|
break;
|
|
@@ -1162,7 +1379,7 @@ class LiveController {
|
|
|
1162
1379
|
* 自定义事件广播
|
|
1163
1380
|
*/
|
|
1164
1381
|
case exports.Command.CustomEvent: {
|
|
1165
|
-
|
|
1382
|
+
var evtMsg = data;
|
|
1166
1383
|
live.emit('broadcast', evtMsg, frontRequestId);
|
|
1167
1384
|
break;
|
|
1168
1385
|
}
|
|
@@ -1170,21 +1387,22 @@ class LiveController {
|
|
|
1170
1387
|
* 帧数据同步
|
|
1171
1388
|
*/
|
|
1172
1389
|
case exports.Command.KeyframeSync: {
|
|
1173
|
-
|
|
1390
|
+
var remoteKeyframes_1 = data;
|
|
1174
1391
|
// 此处做一层 diff,仅跟本地数据不一致的情况下才广播数据。
|
|
1175
|
-
|
|
1176
|
-
|
|
1392
|
+
var keyframes = Object.keys(remoteKeyframes_1).reduce(function (accu, curr) {
|
|
1393
|
+
var _a;
|
|
1394
|
+
if (equal(remoteKeyframes_1[curr], _this.keyframes[curr], { deep: true })) {
|
|
1177
1395
|
return accu;
|
|
1178
1396
|
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1397
|
+
var params = [
|
|
1398
|
+
remoteKeyframes_1[curr],
|
|
1399
|
+
_this.keyframes[curr],
|
|
1182
1400
|
frontRequestId,
|
|
1183
1401
|
];
|
|
1184
|
-
|
|
1185
|
-
live.keyframes.emit(evtName,
|
|
1186
|
-
|
|
1187
|
-
accu[curr] =
|
|
1402
|
+
var evtName = curr;
|
|
1403
|
+
(_a = live.keyframes).emit.apply(_a, __spreadArray([evtName], params, false));
|
|
1404
|
+
_this.keyframes[curr] = remoteKeyframes_1[curr];
|
|
1405
|
+
accu[curr] = remoteKeyframes_1[curr];
|
|
1188
1406
|
return accu;
|
|
1189
1407
|
}, {});
|
|
1190
1408
|
live.emit('keyframes', keyframes, frontRequestId);
|
|
@@ -1194,7 +1412,7 @@ class LiveController {
|
|
|
1194
1412
|
* 内置消息
|
|
1195
1413
|
*/
|
|
1196
1414
|
case exports.Command.BuiltinMsg: {
|
|
1197
|
-
|
|
1415
|
+
var builtinMsg = data;
|
|
1198
1416
|
live.emit('builtinEvent', builtinMsg);
|
|
1199
1417
|
if (builtinMsg.event_type === exports.BuiltinEventType.UserChange) {
|
|
1200
1418
|
live.emit('userChange', builtinMsg);
|
|
@@ -1237,27 +1455,31 @@ class LiveController {
|
|
|
1237
1455
|
else {
|
|
1238
1456
|
live.emit('error', liveMsg);
|
|
1239
1457
|
}
|
|
1240
|
-
}
|
|
1458
|
+
};
|
|
1241
1459
|
/**
|
|
1242
1460
|
* 发送数据
|
|
1243
1461
|
* @param data
|
|
1244
1462
|
*/
|
|
1245
|
-
sendMessage(data) {
|
|
1463
|
+
LiveController.prototype.sendMessage = function (data) {
|
|
1246
1464
|
if (!this.webSocket)
|
|
1247
1465
|
return console.warn('WebSocket has not yet been initialized!');
|
|
1248
1466
|
if (!data)
|
|
1249
1467
|
return console.warn('WebSocket messages is empty!');
|
|
1250
1468
|
this.webSocket.send(JSON.stringify(data));
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1469
|
+
};
|
|
1470
|
+
return LiveController;
|
|
1471
|
+
}());
|
|
1253
1472
|
|
|
1254
|
-
|
|
1473
|
+
var unimplementedGetVoiceSign = function (params) {
|
|
1474
|
+
return Promise.reject('unimplemented method GetVoiceSign');
|
|
1475
|
+
};
|
|
1255
1476
|
/**
|
|
1256
1477
|
* 创建 `live` 实例。
|
|
1257
1478
|
*/
|
|
1258
1479
|
function createLive(options) {
|
|
1259
|
-
|
|
1260
|
-
|
|
1480
|
+
var liveController = new LiveController(options);
|
|
1481
|
+
var createLiveMsg = function (command, data, toUserIds) {
|
|
1482
|
+
if (data === void 0) { data = {}; }
|
|
1261
1483
|
toUserIds = toUserIds
|
|
1262
1484
|
? Array.isArray(toUserIds)
|
|
1263
1485
|
? toUserIds
|
|
@@ -1265,14 +1487,16 @@ function createLive(options) {
|
|
|
1265
1487
|
: [];
|
|
1266
1488
|
if (toUserIds)
|
|
1267
1489
|
data['to_user_ids'] = toUserIds;
|
|
1268
|
-
return { command, front_request_id: uuid(), data };
|
|
1490
|
+
return { command: command, front_request_id: uuid(), data: data };
|
|
1269
1491
|
};
|
|
1270
|
-
|
|
1271
|
-
|
|
1492
|
+
var LiveTpl = /** @class */ (function (_super) {
|
|
1493
|
+
__extends(LiveTpl, _super);
|
|
1494
|
+
function LiveTpl() {
|
|
1495
|
+
var _this = this;
|
|
1272
1496
|
var _a, _b;
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1497
|
+
_this = _super.call(this) || this;
|
|
1498
|
+
_this.keyframes = new Subscribe();
|
|
1499
|
+
var jsBridge = (function () {
|
|
1276
1500
|
if (options.jsBridge)
|
|
1277
1501
|
return options.jsBridge;
|
|
1278
1502
|
if (options.useBuiltInJsBridge)
|
|
@@ -1287,7 +1511,7 @@ function createLive(options) {
|
|
|
1287
1511
|
if (!options.getVoiceSign) {
|
|
1288
1512
|
throw new Error('GetVoiceSign method must be passed when using built-in RTC instances');
|
|
1289
1513
|
}
|
|
1290
|
-
|
|
1514
|
+
var getVoiceSign = (_a = options.getVoiceSign) !== null && _a !== void 0 ? _a : unimplementedGetVoiceSign;
|
|
1291
1515
|
switch (options.rtcType) {
|
|
1292
1516
|
case exports.RTCType.RealseeVRWebViewRTC: {
|
|
1293
1517
|
// 内置的 VRWebViewRTC
|
|
@@ -1295,15 +1519,15 @@ function createLive(options) {
|
|
|
1295
1519
|
throw new Error('JsBridge instance must be passed when using built-in VRWebViewRTC instances');
|
|
1296
1520
|
}
|
|
1297
1521
|
liveController.options.rtc = new VRWebViewRTC({
|
|
1298
|
-
jsBridge,
|
|
1299
|
-
getVoiceSign,
|
|
1522
|
+
jsBridge: jsBridge,
|
|
1523
|
+
getVoiceSign: getVoiceSign,
|
|
1300
1524
|
});
|
|
1301
1525
|
break;
|
|
1302
1526
|
}
|
|
1303
1527
|
case exports.RTCType.RealseeBrowserChimeRTC: {
|
|
1304
1528
|
// 内置的 RealseeBrowserChimeRTC
|
|
1305
1529
|
liveController.options.rtc = new BrowserRTC4Chime({
|
|
1306
|
-
getVoiceSign,
|
|
1530
|
+
getVoiceSign: getVoiceSign,
|
|
1307
1531
|
logLevel: options.__debug__ ? amazonChimeSdkJs.LogLevel.DEBUG : amazonChimeSdkJs.LogLevel.ERROR,
|
|
1308
1532
|
});
|
|
1309
1533
|
break;
|
|
@@ -1311,7 +1535,7 @@ function createLive(options) {
|
|
|
1311
1535
|
case exports.RTCType.RealseeBrowserRTC: {
|
|
1312
1536
|
// 内置的 RealseeBrowserRTC
|
|
1313
1537
|
liveController.options.rtc = new BrowserRTC({
|
|
1314
|
-
getVoiceSign,
|
|
1538
|
+
getVoiceSign: getVoiceSign,
|
|
1315
1539
|
});
|
|
1316
1540
|
break;
|
|
1317
1541
|
}
|
|
@@ -1325,23 +1549,23 @@ function createLive(options) {
|
|
|
1325
1549
|
if (!options.getVoiceSign) {
|
|
1326
1550
|
throw new Error('GetVoiceSign method must be passed when using built-in RTC instances');
|
|
1327
1551
|
}
|
|
1328
|
-
|
|
1552
|
+
var getVoiceSign = (_b = options.getVoiceSign) !== null && _b !== void 0 ? _b : unimplementedGetVoiceSign;
|
|
1329
1553
|
if (!jsBridge) {
|
|
1330
1554
|
throw new Error('jsBridge instance must be passed when using built-in RTC instances');
|
|
1331
1555
|
}
|
|
1332
1556
|
// vrwebview 默认
|
|
1333
1557
|
if ((isRealseeVRWebview && (isAndroid || isIOS)) || isWxMiniProgram) {
|
|
1334
1558
|
liveController.options.rtc = new VRWebViewRTC({
|
|
1335
|
-
jsBridge,
|
|
1336
|
-
getVoiceSign,
|
|
1559
|
+
jsBridge: jsBridge,
|
|
1560
|
+
getVoiceSign: getVoiceSign,
|
|
1337
1561
|
});
|
|
1338
1562
|
}
|
|
1339
1563
|
else {
|
|
1340
1564
|
// 其它终端使用
|
|
1341
1565
|
liveController.options.rtc =
|
|
1342
1566
|
options.builtInRTCType === exports.BuiltInRTCType.RealseeXChimeRTC
|
|
1343
|
-
? new BrowserRTC4Chime({ getVoiceSign })
|
|
1344
|
-
: new BrowserRTC({ getVoiceSign });
|
|
1567
|
+
? new BrowserRTC4Chime({ getVoiceSign: getVoiceSign })
|
|
1568
|
+
: new BrowserRTC({ getVoiceSign: getVoiceSign });
|
|
1345
1569
|
}
|
|
1346
1570
|
}
|
|
1347
1571
|
}
|
|
@@ -1350,288 +1574,407 @@ function createLive(options) {
|
|
|
1350
1574
|
}
|
|
1351
1575
|
// 默认自动连接
|
|
1352
1576
|
if (liveController.options.url && liveController.options.getTicket) {
|
|
1353
|
-
|
|
1577
|
+
_this.connect();
|
|
1354
1578
|
}
|
|
1355
1579
|
// 健康检查:WHY --> 在某些WebView特殊场景下 WebSocket.readyState 发生变化时不会出发error\close等事件;
|
|
1356
1580
|
// 因此,开启一个定时任务监测 WebSocket.readyState 状态的更新
|
|
1357
|
-
|
|
1581
|
+
var healthCheck = (function (healthCheck) {
|
|
1358
1582
|
if (!healthCheck)
|
|
1359
1583
|
return 0;
|
|
1360
1584
|
if (healthCheck === true)
|
|
1361
1585
|
return 3000;
|
|
1362
|
-
|
|
1586
|
+
var duration = Number(healthCheck);
|
|
1363
1587
|
if (duration > 0)
|
|
1364
1588
|
return duration;
|
|
1365
1589
|
return 3000;
|
|
1366
1590
|
})(liveController.options.healthCheck);
|
|
1367
1591
|
if (healthCheck) {
|
|
1368
|
-
liveController.healthCheckId = setInterval(()
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
get options() {
|
|
1372
|
-
return Object.freeze(Object.assign({}, liveController.options));
|
|
1373
|
-
}
|
|
1374
|
-
get readyState() {
|
|
1375
|
-
liveController.checkReadyState(this);
|
|
1376
|
-
return liveController.readyState;
|
|
1377
|
-
}
|
|
1378
|
-
get url() {
|
|
1379
|
-
var _a;
|
|
1380
|
-
return ((_a = liveController.webSocket) === null || _a === void 0 ? void 0 : _a.url) || '';
|
|
1381
|
-
}
|
|
1382
|
-
get selfInfo() {
|
|
1383
|
-
return liveController.selfUserInfo;
|
|
1384
|
-
}
|
|
1385
|
-
get userList() {
|
|
1386
|
-
return liveController.userList || [];
|
|
1387
|
-
}
|
|
1388
|
-
get snapshot() {
|
|
1389
|
-
return liveController.keyframes || {};
|
|
1390
|
-
}
|
|
1391
|
-
get $RTC() {
|
|
1392
|
-
return liveController.options.rtc;
|
|
1393
|
-
}
|
|
1394
|
-
get jsBridge() {
|
|
1395
|
-
return liveController.options.jsBridge;
|
|
1396
|
-
}
|
|
1397
|
-
async setSelfInfo(userInfo) {
|
|
1398
|
-
if (this.readyState !== exports.WebSocketState.OPEN) {
|
|
1399
|
-
return new Error('The connection is not open and ready to communicate.');
|
|
1400
|
-
}
|
|
1401
|
-
try {
|
|
1402
|
-
return await this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserInfo, userInfo);
|
|
1403
|
-
}
|
|
1404
|
-
catch (error) {
|
|
1405
|
-
return error;
|
|
1592
|
+
liveController.healthCheckId = setInterval(function () { return liveController.checkReadyState(_this); }, healthCheck);
|
|
1406
1593
|
}
|
|
1594
|
+
return _this;
|
|
1407
1595
|
}
|
|
1408
|
-
|
|
1596
|
+
Object.defineProperty(LiveTpl.prototype, "options", {
|
|
1597
|
+
get: function () {
|
|
1598
|
+
return Object.freeze(Object.assign({}, liveController.options));
|
|
1599
|
+
},
|
|
1600
|
+
enumerable: false,
|
|
1601
|
+
configurable: true
|
|
1602
|
+
});
|
|
1603
|
+
Object.defineProperty(LiveTpl.prototype, "readyState", {
|
|
1604
|
+
get: function () {
|
|
1605
|
+
liveController.checkReadyState(this);
|
|
1606
|
+
return liveController.readyState;
|
|
1607
|
+
},
|
|
1608
|
+
enumerable: false,
|
|
1609
|
+
configurable: true
|
|
1610
|
+
});
|
|
1611
|
+
Object.defineProperty(LiveTpl.prototype, "url", {
|
|
1612
|
+
get: function () {
|
|
1613
|
+
var _a;
|
|
1614
|
+
return ((_a = liveController.webSocket) === null || _a === void 0 ? void 0 : _a.url) || '';
|
|
1615
|
+
},
|
|
1616
|
+
enumerable: false,
|
|
1617
|
+
configurable: true
|
|
1618
|
+
});
|
|
1619
|
+
Object.defineProperty(LiveTpl.prototype, "selfInfo", {
|
|
1620
|
+
get: function () {
|
|
1621
|
+
return liveController.selfUserInfo;
|
|
1622
|
+
},
|
|
1623
|
+
enumerable: false,
|
|
1624
|
+
configurable: true
|
|
1625
|
+
});
|
|
1626
|
+
Object.defineProperty(LiveTpl.prototype, "userList", {
|
|
1627
|
+
get: function () {
|
|
1628
|
+
return liveController.userList || [];
|
|
1629
|
+
},
|
|
1630
|
+
enumerable: false,
|
|
1631
|
+
configurable: true
|
|
1632
|
+
});
|
|
1633
|
+
Object.defineProperty(LiveTpl.prototype, "snapshot", {
|
|
1634
|
+
get: function () {
|
|
1635
|
+
return liveController.keyframes || {};
|
|
1636
|
+
},
|
|
1637
|
+
enumerable: false,
|
|
1638
|
+
configurable: true
|
|
1639
|
+
});
|
|
1640
|
+
Object.defineProperty(LiveTpl.prototype, "$RTC", {
|
|
1641
|
+
get: function () {
|
|
1642
|
+
return liveController.options.rtc;
|
|
1643
|
+
},
|
|
1644
|
+
enumerable: false,
|
|
1645
|
+
configurable: true
|
|
1646
|
+
});
|
|
1647
|
+
Object.defineProperty(LiveTpl.prototype, "jsBridge", {
|
|
1648
|
+
get: function () {
|
|
1649
|
+
return liveController.options.jsBridge;
|
|
1650
|
+
},
|
|
1651
|
+
enumerable: false,
|
|
1652
|
+
configurable: true
|
|
1653
|
+
});
|
|
1654
|
+
LiveTpl.prototype.setSelfInfo = function (userInfo) {
|
|
1655
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1656
|
+
var error_1;
|
|
1657
|
+
return __generator(this, function (_a) {
|
|
1658
|
+
switch (_a.label) {
|
|
1659
|
+
case 0:
|
|
1660
|
+
if (this.readyState !== exports.WebSocketState.OPEN) {
|
|
1661
|
+
return [2 /*return*/, new Error('The connection is not open and ready to communicate.')];
|
|
1662
|
+
}
|
|
1663
|
+
_a.label = 1;
|
|
1664
|
+
case 1:
|
|
1665
|
+
_a.trys.push([1, 3, , 4]);
|
|
1666
|
+
return [4 /*yield*/, this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserInfo, userInfo)];
|
|
1667
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
1668
|
+
case 3:
|
|
1669
|
+
error_1 = _a.sent();
|
|
1670
|
+
return [2 /*return*/, error_1];
|
|
1671
|
+
case 4: return [2 /*return*/];
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
});
|
|
1675
|
+
};
|
|
1676
|
+
LiveTpl.prototype.getFramesByKey = function (key) {
|
|
1409
1677
|
return liveController.keyframes[key];
|
|
1410
|
-
}
|
|
1411
|
-
sendKeyframe(key, frame) {
|
|
1678
|
+
};
|
|
1679
|
+
LiveTpl.prototype.sendKeyframe = function (key, frame) {
|
|
1412
1680
|
if (this.readyState !== exports.WebSocketState.OPEN) {
|
|
1413
1681
|
return new Error('The connection is not open and ready to communicate.');
|
|
1414
1682
|
}
|
|
1415
1683
|
liveController.keyframes[key] = frame;
|
|
1416
|
-
|
|
1684
|
+
var liveMsg = createLiveMsg(exports.Command.KeyframeSync, this.snapshot);
|
|
1417
1685
|
liveController.sendMessage(liveMsg);
|
|
1418
1686
|
return true;
|
|
1419
|
-
}
|
|
1420
|
-
broadcast(data, toUserIds, timeout) {
|
|
1687
|
+
};
|
|
1688
|
+
LiveTpl.prototype.broadcast = function (data, toUserIds, timeout) {
|
|
1689
|
+
var _this = this;
|
|
1421
1690
|
if (this.readyState !== exports.WebSocketState.OPEN) {
|
|
1422
1691
|
return new Error('The connection is not open and ready to communicate.');
|
|
1423
1692
|
}
|
|
1424
|
-
return new Promise((resolve, reject)
|
|
1425
|
-
|
|
1426
|
-
|
|
1693
|
+
return new Promise(function (resolve, reject) {
|
|
1694
|
+
var customEvent = createLiveMsg(exports.Command.CustomEvent, data, toUserIds);
|
|
1695
|
+
var front_request_id = customEvent.front_request_id;
|
|
1427
1696
|
liveController.sendMessage(customEvent);
|
|
1428
|
-
|
|
1429
|
-
? setTimeout(()
|
|
1697
|
+
var timeoutId = timeout
|
|
1698
|
+
? setTimeout(function () {
|
|
1430
1699
|
reject(new Error('RESPONSE TIMEOUT'));
|
|
1431
|
-
|
|
1700
|
+
_this.off('broadcast', broadcast);
|
|
1432
1701
|
}, timeout)
|
|
1433
1702
|
: undefined;
|
|
1434
|
-
|
|
1703
|
+
var broadcast = function (data, frontRequestId) {
|
|
1435
1704
|
if (frontRequestId !== front_request_id)
|
|
1436
1705
|
return;
|
|
1437
|
-
|
|
1706
|
+
_this.off('broadcast', broadcast);
|
|
1438
1707
|
resolve(data);
|
|
1439
1708
|
if (timeoutId)
|
|
1440
1709
|
clearInterval(timeoutId);
|
|
1441
1710
|
};
|
|
1442
|
-
|
|
1711
|
+
_this.on('broadcast', broadcast);
|
|
1443
1712
|
});
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
return
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1713
|
+
};
|
|
1714
|
+
LiveTpl.prototype.updateStatus = function (evtType, atnType, status, toUserIds) {
|
|
1715
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1716
|
+
var data, liveMsg;
|
|
1717
|
+
return __generator(this, function (_a) {
|
|
1718
|
+
// TODO 统一规则,不能联合类型
|
|
1719
|
+
if (this.readyState !== exports.WebSocketState.OPEN) {
|
|
1720
|
+
return [2 /*return*/, false];
|
|
1721
|
+
}
|
|
1722
|
+
data = Object.assign({ event_type: evtType, action: atnType }, { data: status });
|
|
1723
|
+
liveMsg = createLiveMsg(exports.Command.BuiltinMsg, data, toUserIds);
|
|
1724
|
+
liveController.sendMessage(liveMsg);
|
|
1725
|
+
return [2 /*return*/, true];
|
|
1726
|
+
});
|
|
1727
|
+
});
|
|
1728
|
+
};
|
|
1455
1729
|
// 仅用于用户自己的麦克风控制
|
|
1456
|
-
|
|
1730
|
+
LiveTpl.prototype.toggleMicro = function (microStatus) {
|
|
1457
1731
|
var _a, _b;
|
|
1458
|
-
|
|
1459
|
-
return
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1732
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1733
|
+
return __generator(this, function (_c) {
|
|
1734
|
+
switch (_c.label) {
|
|
1735
|
+
case 0:
|
|
1736
|
+
if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.control_own_micro))
|
|
1737
|
+
return [2 /*return*/, false];
|
|
1738
|
+
return [4 /*yield*/, this.$RTC.toggleMicro(microStatus)];
|
|
1739
|
+
case 1:
|
|
1740
|
+
_c.sent();
|
|
1741
|
+
return [4 /*yield*/, this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
|
|
1742
|
+
status: microStatus ? exports.MicroStatus.OPEN : exports.MicroStatus.CLOSE,
|
|
1743
|
+
}, [])];
|
|
1744
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
1745
|
+
}
|
|
1746
|
+
});
|
|
1747
|
+
});
|
|
1748
|
+
};
|
|
1749
|
+
LiveTpl.prototype.forbidMicro = function (microStatus, toUserIds) {
|
|
1466
1750
|
var _a, _b;
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1751
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1752
|
+
return __generator(this, function (_c) {
|
|
1753
|
+
switch (_c.label) {
|
|
1754
|
+
case 0:
|
|
1755
|
+
if (liveController.options.canForbidUserMicro &&
|
|
1756
|
+
!liveController.options.canForbidUserMicro(toUserIds)) {
|
|
1757
|
+
return [2 /*return*/, false];
|
|
1758
|
+
}
|
|
1759
|
+
if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.control_other_micro)) {
|
|
1760
|
+
return [2 /*return*/, false];
|
|
1761
|
+
}
|
|
1762
|
+
return [4 /*yield*/, this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
|
|
1763
|
+
status: microStatus,
|
|
1764
|
+
}, toUserIds)];
|
|
1765
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1766
|
+
}
|
|
1767
|
+
});
|
|
1768
|
+
});
|
|
1769
|
+
};
|
|
1478
1770
|
/**
|
|
1479
1771
|
* @deprecated 暂不可用
|
|
1480
1772
|
*/
|
|
1481
|
-
|
|
1773
|
+
LiveTpl.prototype.forbidSync = function (sync, toUserIds) {
|
|
1482
1774
|
var _a, _b;
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1775
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1776
|
+
return __generator(this, function (_c) {
|
|
1777
|
+
switch (_c.label) {
|
|
1778
|
+
case 0:
|
|
1779
|
+
if (liveController.options.canForbidUserSync &&
|
|
1780
|
+
!liveController.options.canForbidUserSync(toUserIds)) {
|
|
1781
|
+
return [2 /*return*/, false];
|
|
1782
|
+
}
|
|
1783
|
+
if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.control_other_sync)) {
|
|
1784
|
+
return [2 /*return*/, false];
|
|
1785
|
+
}
|
|
1786
|
+
return [4 /*yield*/, this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserPermission, { sync_frame: sync }, toUserIds)];
|
|
1787
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1788
|
+
}
|
|
1789
|
+
});
|
|
1790
|
+
});
|
|
1791
|
+
};
|
|
1792
|
+
LiveTpl.prototype.kick = function (toUserIds) {
|
|
1493
1793
|
var _a, _b;
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
}
|
|
1511
|
-
catch (e) {
|
|
1512
|
-
console.log(e);
|
|
1513
|
-
}
|
|
1514
|
-
return liveController.dispose();
|
|
1515
|
-
}
|
|
1516
|
-
async connect(options = {}) {
|
|
1517
|
-
// 连接 WebSocket 前验证麦克风权限
|
|
1518
|
-
const microAuth = await this.$RTC.detectMicro();
|
|
1519
|
-
if (!microAuth) {
|
|
1520
|
-
const error = new Error('系统监测麦克风未授权~');
|
|
1521
|
-
this.emit('ws.error', { type: exports.WebSocketErrorType.MicroAuth, error });
|
|
1522
|
-
return error;
|
|
1523
|
-
}
|
|
1524
|
-
// WebSocket 正在连接中,规避重复连接
|
|
1525
|
-
if (liveController.connecting) {
|
|
1526
|
-
const error = new Error('WebSocket 正在连接中,请勿重复连接 ...');
|
|
1527
|
-
this.emit('ws.error', {
|
|
1528
|
-
type: exports.WebSocketErrorType.DuplicateConnect,
|
|
1529
|
-
error,
|
|
1794
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1795
|
+
return __generator(this, function (_c) {
|
|
1796
|
+
switch (_c.label) {
|
|
1797
|
+
case 0:
|
|
1798
|
+
if (liveController.options.canForbidUserKick &&
|
|
1799
|
+
!liveController.options.canForbidUserKick(toUserIds)) {
|
|
1800
|
+
return [2 /*return*/, false];
|
|
1801
|
+
}
|
|
1802
|
+
if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.change_other_status)) {
|
|
1803
|
+
return [2 /*return*/, false];
|
|
1804
|
+
}
|
|
1805
|
+
return [4 /*yield*/, this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserStatus, {
|
|
1806
|
+
status: 'KICK_OUT',
|
|
1807
|
+
}, toUserIds)];
|
|
1808
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1809
|
+
}
|
|
1530
1810
|
});
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
this.emit('ws.error', { type: exports.WebSocketErrorType.IllegalURL, error });
|
|
1552
|
-
return error;
|
|
1553
|
-
}
|
|
1554
|
-
if (!liveController.options.getTicket) {
|
|
1555
|
-
const error = new Error(`getTicket() 未配置!`);
|
|
1556
|
-
this.emit('ws.error', { type: exports.WebSocketErrorType.IllegalArgs, error });
|
|
1557
|
-
return error;
|
|
1558
|
-
}
|
|
1559
|
-
// 连接锁
|
|
1560
|
-
liveController.connecting = true;
|
|
1561
|
-
// 连接前销毁之前绑定的事件
|
|
1562
|
-
liveController.disposeWebSocket();
|
|
1563
|
-
this.emit('ws.beforeConnect');
|
|
1564
|
-
const url = force || options.url || !this.url
|
|
1565
|
-
? appendUri(liveController.options.url, {
|
|
1566
|
-
ticket: await liveController.options.getTicket(),
|
|
1567
|
-
force: Number(!!force),
|
|
1568
|
-
})
|
|
1569
|
-
: this.url;
|
|
1570
|
-
liveController.webSocket = new WebSocket(url);
|
|
1571
|
-
liveController.onEvtOpnListener = () => {
|
|
1572
|
-
liveController.checkReadyState(this);
|
|
1573
|
-
this.emit('ws.afterConnect');
|
|
1574
|
-
};
|
|
1575
|
-
liveController.onEvtMsgListener = (evt) => {
|
|
1576
|
-
liveController.checkReadyState(this);
|
|
1577
|
-
try {
|
|
1578
|
-
const liveMsg = parseLiveMsg(evt.data);
|
|
1579
|
-
if (liveMsg === false)
|
|
1580
|
-
return;
|
|
1581
|
-
liveController.handleMessage(liveMsg, this);
|
|
1582
|
-
}
|
|
1583
|
-
catch (error) {
|
|
1584
|
-
// 未知错误
|
|
1585
|
-
this.emit('ws.error', {
|
|
1586
|
-
type: exports.WebSocketErrorType.Unknown,
|
|
1587
|
-
error,
|
|
1588
|
-
target: evt,
|
|
1589
|
-
});
|
|
1590
|
-
}
|
|
1591
|
-
};
|
|
1592
|
-
liveController.onEvtErrListener = (evt) => {
|
|
1593
|
-
live.emit('ws.error', { type: exports.WebSocketErrorType.Error, target: evt });
|
|
1594
|
-
liveController.checkReadyState(this);
|
|
1595
|
-
};
|
|
1596
|
-
liveController.onEvtCLEListener = (evt) => {
|
|
1597
|
-
liveController.checkReadyState(this);
|
|
1598
|
-
const code = Number(evt.code);
|
|
1599
|
-
if (code === 1000)
|
|
1600
|
-
return;
|
|
1601
|
-
// 异常退出不一定会触发'error'事件,根据 evt.code 一些类型的退出也算是 error 行为
|
|
1602
|
-
const errMsg = parseWSClsErr(code);
|
|
1603
|
-
live.emit('ws.error', {
|
|
1604
|
-
target: evt,
|
|
1605
|
-
type: exports.WebSocketErrorType.Close,
|
|
1606
|
-
closeError: errMsg,
|
|
1811
|
+
});
|
|
1812
|
+
};
|
|
1813
|
+
LiveTpl.prototype.exit = function () {
|
|
1814
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1815
|
+
var e_1;
|
|
1816
|
+
return __generator(this, function (_a) {
|
|
1817
|
+
switch (_a.label) {
|
|
1818
|
+
case 0:
|
|
1819
|
+
_a.trys.push([0, 2, , 3]);
|
|
1820
|
+
this.$RTC.quit();
|
|
1821
|
+
return [4 /*yield*/, this.updateStatus(exports.BuiltinEventType.RoomChange, exports.BuiltinActionType.RoomClose, {})];
|
|
1822
|
+
case 1:
|
|
1823
|
+
_a.sent();
|
|
1824
|
+
return [3 /*break*/, 3];
|
|
1825
|
+
case 2:
|
|
1826
|
+
e_1 = _a.sent();
|
|
1827
|
+
console.log(e_1);
|
|
1828
|
+
return [3 /*break*/, 3];
|
|
1829
|
+
case 3: return [2 /*return*/, liveController.dispose()];
|
|
1830
|
+
}
|
|
1607
1831
|
});
|
|
1608
|
-
};
|
|
1609
|
-
liveController.webSocket.addEventListener('open', liveController.onEvtOpnListener);
|
|
1610
|
-
liveController.webSocket.addEventListener('message', liveController.onEvtMsgListener);
|
|
1611
|
-
liveController.webSocket.addEventListener('error', liveController.onEvtErrListener);
|
|
1612
|
-
liveController.webSocket.addEventListener('close', liveController.onEvtCLEListener);
|
|
1613
|
-
return await new Promise((resolve, reject) => {
|
|
1614
|
-
const success = () => {
|
|
1615
|
-
resolve(true);
|
|
1616
|
-
liveController.connecting = false;
|
|
1617
|
-
this.off('ws.error', fail);
|
|
1618
|
-
};
|
|
1619
|
-
const fail = (error) => {
|
|
1620
|
-
reject(error.error
|
|
1621
|
-
? error.error
|
|
1622
|
-
: new Error('WebSocket connection failed!'));
|
|
1623
|
-
liveController.connecting = false;
|
|
1624
|
-
this.off('ws.afterConnect', success);
|
|
1625
|
-
};
|
|
1626
|
-
this.once('ws.afterConnect', success);
|
|
1627
|
-
this.once('ws.error', fail);
|
|
1628
1832
|
});
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1833
|
+
};
|
|
1834
|
+
LiveTpl.prototype.connect = function (options) {
|
|
1835
|
+
if (options === void 0) { options = {}; }
|
|
1836
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1837
|
+
var microAuth, error, error, force, error, error, url, _a, _b, _c;
|
|
1838
|
+
var _d;
|
|
1839
|
+
var _this = this;
|
|
1840
|
+
return __generator(this, function (_e) {
|
|
1841
|
+
switch (_e.label) {
|
|
1842
|
+
case 0: return [4 /*yield*/, this.$RTC.detectMicro()];
|
|
1843
|
+
case 1:
|
|
1844
|
+
microAuth = _e.sent();
|
|
1845
|
+
if (!microAuth) {
|
|
1846
|
+
error = new Error('系统监测麦克风未授权~');
|
|
1847
|
+
this.emit('ws.error', { type: exports.WebSocketErrorType.MicroAuth, error: error });
|
|
1848
|
+
return [2 /*return*/, error];
|
|
1849
|
+
}
|
|
1850
|
+
// WebSocket 正在连接中,规避重复连接
|
|
1851
|
+
if (liveController.connecting) {
|
|
1852
|
+
error = new Error('WebSocket 正在连接中,请勿重复连接 ...');
|
|
1853
|
+
this.emit('ws.error', {
|
|
1854
|
+
type: exports.WebSocketErrorType.DuplicateConnect,
|
|
1855
|
+
error: error,
|
|
1856
|
+
});
|
|
1857
|
+
return [2 /*return*/, error];
|
|
1858
|
+
}
|
|
1859
|
+
force = options.force;
|
|
1860
|
+
if (!force) {
|
|
1861
|
+
if (this.readyState === exports.WebSocketState.CONNECTING ||
|
|
1862
|
+
this.readyState === exports.WebSocketState.OPEN) {
|
|
1863
|
+
return [2 /*return*/, true];
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
// WebSocket URL 逻辑
|
|
1867
|
+
if (options.url) {
|
|
1868
|
+
liveController.options.url = options.url;
|
|
1869
|
+
}
|
|
1870
|
+
if (options.getTicket) {
|
|
1871
|
+
liveController.options.getTicket = options.getTicket;
|
|
1872
|
+
}
|
|
1873
|
+
if (!liveController.options.url ||
|
|
1874
|
+
!liveController.options.url.startsWith('ws')) {
|
|
1875
|
+
error = new Error("WebSocket URL \u672A\u914D\u7F6E\u6216\u683C\u5F0F\u4E0D\u5408\u6CD5\uFF1A\"".concat(liveController.options.url, "\""));
|
|
1876
|
+
this.emit('ws.error', { type: exports.WebSocketErrorType.IllegalURL, error: error });
|
|
1877
|
+
return [2 /*return*/, error];
|
|
1878
|
+
}
|
|
1879
|
+
if (!liveController.options.getTicket) {
|
|
1880
|
+
error = new Error("getTicket() \u672A\u914D\u7F6E!");
|
|
1881
|
+
this.emit('ws.error', { type: exports.WebSocketErrorType.IllegalArgs, error: error });
|
|
1882
|
+
return [2 /*return*/, error];
|
|
1883
|
+
}
|
|
1884
|
+
// 连接锁
|
|
1885
|
+
liveController.connecting = true;
|
|
1886
|
+
// 连接前销毁之前绑定的事件
|
|
1887
|
+
liveController.disposeWebSocket();
|
|
1888
|
+
this.emit('ws.beforeConnect');
|
|
1889
|
+
if (!(force || options.url || !this.url)) return [3 /*break*/, 3];
|
|
1890
|
+
_b = appendUri;
|
|
1891
|
+
_c = [liveController.options.url];
|
|
1892
|
+
_d = {};
|
|
1893
|
+
return [4 /*yield*/, liveController.options.getTicket()];
|
|
1894
|
+
case 2:
|
|
1895
|
+
_a = _b.apply(void 0, _c.concat([(_d.ticket = _e.sent(),
|
|
1896
|
+
_d.force = Number(!!force),
|
|
1897
|
+
_d)]));
|
|
1898
|
+
return [3 /*break*/, 4];
|
|
1899
|
+
case 3:
|
|
1900
|
+
_a = this.url;
|
|
1901
|
+
_e.label = 4;
|
|
1902
|
+
case 4:
|
|
1903
|
+
url = _a;
|
|
1904
|
+
liveController.webSocket = new WebSocket(url);
|
|
1905
|
+
liveController.onEvtOpnListener = function () {
|
|
1906
|
+
liveController.checkReadyState(_this);
|
|
1907
|
+
_this.emit('ws.afterConnect');
|
|
1908
|
+
};
|
|
1909
|
+
liveController.onEvtMsgListener = function (evt) {
|
|
1910
|
+
liveController.checkReadyState(_this);
|
|
1911
|
+
try {
|
|
1912
|
+
var liveMsg = parseLiveMsg(evt.data);
|
|
1913
|
+
if (liveMsg === false)
|
|
1914
|
+
return;
|
|
1915
|
+
liveController.handleMessage(liveMsg, _this);
|
|
1916
|
+
}
|
|
1917
|
+
catch (error) {
|
|
1918
|
+
// 未知错误
|
|
1919
|
+
_this.emit('ws.error', {
|
|
1920
|
+
type: exports.WebSocketErrorType.Unknown,
|
|
1921
|
+
error: error,
|
|
1922
|
+
target: evt,
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1925
|
+
};
|
|
1926
|
+
liveController.onEvtErrListener = function (evt) {
|
|
1927
|
+
live.emit('ws.error', { type: exports.WebSocketErrorType.Error, target: evt });
|
|
1928
|
+
liveController.checkReadyState(_this);
|
|
1929
|
+
};
|
|
1930
|
+
liveController.onEvtCLEListener = function (evt) {
|
|
1931
|
+
liveController.checkReadyState(_this);
|
|
1932
|
+
var code = Number(evt.code);
|
|
1933
|
+
if (code === 1000)
|
|
1934
|
+
return;
|
|
1935
|
+
// 异常退出不一定会触发'error'事件,根据 evt.code 一些类型的退出也算是 error 行为
|
|
1936
|
+
var errMsg = parseWSClsErr(code);
|
|
1937
|
+
live.emit('ws.error', {
|
|
1938
|
+
target: evt,
|
|
1939
|
+
type: exports.WebSocketErrorType.Close,
|
|
1940
|
+
closeError: errMsg,
|
|
1941
|
+
});
|
|
1942
|
+
};
|
|
1943
|
+
liveController.webSocket.addEventListener('open', liveController.onEvtOpnListener);
|
|
1944
|
+
liveController.webSocket.addEventListener('message', liveController.onEvtMsgListener);
|
|
1945
|
+
liveController.webSocket.addEventListener('error', liveController.onEvtErrListener);
|
|
1946
|
+
liveController.webSocket.addEventListener('close', liveController.onEvtCLEListener);
|
|
1947
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
1948
|
+
var success = function () {
|
|
1949
|
+
resolve(true);
|
|
1950
|
+
liveController.connecting = false;
|
|
1951
|
+
_this.off('ws.error', fail);
|
|
1952
|
+
};
|
|
1953
|
+
var fail = function (error) {
|
|
1954
|
+
reject(error.error
|
|
1955
|
+
? error.error
|
|
1956
|
+
: new Error('WebSocket connection failed!'));
|
|
1957
|
+
liveController.connecting = false;
|
|
1958
|
+
_this.off('ws.afterConnect', success);
|
|
1959
|
+
};
|
|
1960
|
+
_this.once('ws.afterConnect', success);
|
|
1961
|
+
_this.once('ws.error', fail);
|
|
1962
|
+
})];
|
|
1963
|
+
case 5: return [2 /*return*/, _e.sent()];
|
|
1964
|
+
}
|
|
1965
|
+
});
|
|
1966
|
+
});
|
|
1967
|
+
};
|
|
1968
|
+
LiveTpl.prototype.revoke = function () {
|
|
1969
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1970
|
+
return __generator(this, function (_a) {
|
|
1971
|
+
return [2 /*return*/, true];
|
|
1972
|
+
});
|
|
1973
|
+
});
|
|
1974
|
+
};
|
|
1975
|
+
return LiveTpl;
|
|
1976
|
+
}(Subscribe));
|
|
1977
|
+
var live = new LiveTpl();
|
|
1635
1978
|
// 如果是调试环境则将内部状态暴露出来
|
|
1636
1979
|
if (options.__debug__) {
|
|
1637
1980
|
Object.assign(live, { __controller__: liveController });
|
|
@@ -1644,14 +1987,14 @@ function createLive(options) {
|
|
|
1644
1987
|
* 创建 {@link LiveReact} 实例,并提供 `React` 技术栈相关工具链。
|
|
1645
1988
|
*/
|
|
1646
1989
|
function createLiveReact(options) {
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1990
|
+
var LiveContext = React__default["default"].createContext(null);
|
|
1991
|
+
var live = createLive(options);
|
|
1992
|
+
var jsBridge = live.jsBridge;
|
|
1650
1993
|
function LiveProvider(props) {
|
|
1651
1994
|
return (React__default["default"].createElement(LiveContext.Provider, { value: props.live || live }, props.children));
|
|
1652
1995
|
}
|
|
1653
1996
|
function useLiveInstance() {
|
|
1654
|
-
|
|
1997
|
+
var context = React__default["default"].useContext(LiveContext);
|
|
1655
1998
|
if (!context)
|
|
1656
1999
|
throw new Error('LiveProvider never found.');
|
|
1657
2000
|
return context;
|
|
@@ -1664,7 +2007,7 @@ function createLiveReact(options) {
|
|
|
1664
2007
|
return useLiveInstance();
|
|
1665
2008
|
}
|
|
1666
2009
|
function useRTCInstance() {
|
|
1667
|
-
|
|
2010
|
+
var live = useLiveInstance();
|
|
1668
2011
|
return live.$RTC;
|
|
1669
2012
|
}
|
|
1670
2013
|
/**
|
|
@@ -1675,76 +2018,93 @@ function createLiveReact(options) {
|
|
|
1675
2018
|
return useRTCInstance();
|
|
1676
2019
|
}
|
|
1677
2020
|
function useConnect() {
|
|
1678
|
-
|
|
1679
|
-
|
|
2021
|
+
var _this = this;
|
|
2022
|
+
var live = useLiveInstance();
|
|
2023
|
+
return function (options) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
2024
|
+
switch (_a.label) {
|
|
2025
|
+
case 0: return [4 /*yield*/, live.connect(options)];
|
|
2026
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
2027
|
+
}
|
|
2028
|
+
}); }); };
|
|
1680
2029
|
}
|
|
1681
2030
|
function useCurrentWebSocketUrl() {
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
React__default["default"].useEffect(()
|
|
1685
|
-
|
|
2031
|
+
var live = useLiveInstance();
|
|
2032
|
+
var _a = React__default["default"].useState(undefined), state = _a[0], setState = _a[1];
|
|
2033
|
+
React__default["default"].useEffect(function () {
|
|
2034
|
+
var onWSBeforeConnect = function () { return setState(live.url); };
|
|
1686
2035
|
live.on('ws.beforeConnect', onWSBeforeConnect);
|
|
1687
|
-
return ()
|
|
2036
|
+
return function () { return live.off('ws.beforeConnect', onWSBeforeConnect); };
|
|
1688
2037
|
}, [live]);
|
|
1689
2038
|
return state;
|
|
1690
2039
|
}
|
|
1691
|
-
function useKeyframeUpdateCallback(name, callback, deps
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
2040
|
+
function useKeyframeUpdateCallback(name, callback, deps) {
|
|
2041
|
+
if (deps === void 0) { deps = []; }
|
|
2042
|
+
var live = useLiveInstance();
|
|
2043
|
+
var dependencyList = __spreadArray([live, name], deps, true);
|
|
2044
|
+
var dispose = function () { return live.keyframes.off(name, callback); };
|
|
2045
|
+
React__default["default"].useEffect(function () {
|
|
1696
2046
|
live.keyframes.on(name, callback);
|
|
1697
2047
|
return dispose;
|
|
1698
2048
|
}, dependencyList);
|
|
1699
2049
|
return dispose;
|
|
1700
2050
|
}
|
|
1701
2051
|
function useLiveAction() {
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
2052
|
+
var live = useLiveInstance();
|
|
2053
|
+
var toggleMicro = React__default["default"].useCallback(function (microStatus) { return live.toggleMicro(microStatus); }, [live]);
|
|
2054
|
+
var broadcast = React__default["default"].useCallback(function (data, toUserIds, timeout) {
|
|
2055
|
+
if (timeout === void 0) { timeout = 0; }
|
|
2056
|
+
return live.broadcast(data, toUserIds, timeout);
|
|
2057
|
+
}, [live]);
|
|
2058
|
+
var exit = React__default["default"].useCallback(function () { return live.exit(); }, [live]);
|
|
2059
|
+
var kick = React__default["default"].useCallback(function (toUserIds) { return live.kick(toUserIds); }, [live]);
|
|
2060
|
+
var forbidMicro = React__default["default"].useCallback(function (micro, toUserIds) {
|
|
2061
|
+
return live.forbidMicro(micro, toUserIds);
|
|
2062
|
+
}, [live]);
|
|
1708
2063
|
// const forbidSync = React.useCallback(
|
|
1709
2064
|
// (sync: boolean, toUserIds?: string | string[] | undefined) =>
|
|
1710
2065
|
// live.forbidSync(sync, toUserIds),
|
|
1711
2066
|
// [live],
|
|
1712
2067
|
// );
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
2068
|
+
var getFramesByKey = React__default["default"].useCallback(function (key) { return live.getFramesByKey(key); }, [live]);
|
|
2069
|
+
var sendKeyframe = React__default["default"].useCallback(function (key, frame) {
|
|
2070
|
+
return live.sendKeyframe(key, frame);
|
|
2071
|
+
}, [live]);
|
|
2072
|
+
var setSelfInfo = React__default["default"].useCallback(function (userInfo) { return live.setSelfInfo(userInfo); }, [live]);
|
|
2073
|
+
var updateStatus = React__default["default"].useCallback(function (evtType, atnType, status, toUserIds) { return live.updateStatus(evtType, atnType, status, toUserIds); }, [live]);
|
|
1717
2074
|
return {
|
|
1718
|
-
broadcast,
|
|
1719
|
-
exit,
|
|
1720
|
-
kick,
|
|
1721
|
-
toggleMicro,
|
|
1722
|
-
forbidMicro,
|
|
2075
|
+
broadcast: broadcast,
|
|
2076
|
+
exit: exit,
|
|
2077
|
+
kick: kick,
|
|
2078
|
+
toggleMicro: toggleMicro,
|
|
2079
|
+
forbidMicro: forbidMicro,
|
|
1723
2080
|
// forbidSync,
|
|
1724
|
-
sendKeyframe,
|
|
1725
|
-
getFramesByKey,
|
|
1726
|
-
setSelfInfo,
|
|
1727
|
-
updateStatus,
|
|
2081
|
+
sendKeyframe: sendKeyframe,
|
|
2082
|
+
getFramesByKey: getFramesByKey,
|
|
2083
|
+
setSelfInfo: setSelfInfo,
|
|
2084
|
+
updateStatus: updateStatus,
|
|
1728
2085
|
};
|
|
1729
2086
|
}
|
|
1730
2087
|
function useKeyframe(key) {
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
React__default["default"].useEffect(()
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
2088
|
+
var live = useLiveInstance();
|
|
2089
|
+
var _a = React__default["default"].useState(live.getFramesByKey(key)), state = _a[0], updateState = _a[1];
|
|
2090
|
+
React__default["default"].useEffect(function () {
|
|
2091
|
+
var onUpdate = function (nextKeyframes) {
|
|
2092
|
+
return updateState(nextKeyframes);
|
|
2093
|
+
};
|
|
2094
|
+
var evtName = key;
|
|
2095
|
+
var callback = onUpdate;
|
|
1737
2096
|
live.keyframes.on(evtName, callback);
|
|
1738
|
-
return ()
|
|
2097
|
+
return function () { return live.keyframes.off(evtName, callback); };
|
|
1739
2098
|
}, [live]);
|
|
1740
|
-
|
|
2099
|
+
var setState = React__default["default"].useCallback(function (frame) { return live.sendKeyframe(key, frame); }, [live]);
|
|
1741
2100
|
return [state, setState];
|
|
1742
2101
|
}
|
|
1743
|
-
function useLiveEventCallback(name, callback, deps
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
2102
|
+
function useLiveEventCallback(name, callback, deps) {
|
|
2103
|
+
if (deps === void 0) { deps = []; }
|
|
2104
|
+
var live = useLiveInstance();
|
|
2105
|
+
var dispose = function () { return live.off(name, callback); };
|
|
2106
|
+
var dependencyList = __spreadArray([live, name], deps, true);
|
|
2107
|
+
React__default["default"].useEffect(function () {
|
|
1748
2108
|
live.on(name, callback);
|
|
1749
2109
|
return dispose;
|
|
1750
2110
|
}, dependencyList);
|
|
@@ -1755,70 +2115,81 @@ function createLiveReact(options) {
|
|
|
1755
2115
|
* @returns
|
|
1756
2116
|
*/
|
|
1757
2117
|
function useReadyState() {
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
React__default["default"].useEffect(()
|
|
1761
|
-
|
|
2118
|
+
var live = useLiveInstance();
|
|
2119
|
+
var _a = React__default["default"].useState(live.readyState), state = _a[0], updateState = _a[1];
|
|
2120
|
+
React__default["default"].useEffect(function () {
|
|
2121
|
+
var readyStateUpdate = function (readyState) {
|
|
2122
|
+
return updateState(readyState);
|
|
2123
|
+
};
|
|
1762
2124
|
live.on('ws.readyStateUpdate', readyStateUpdate);
|
|
1763
|
-
return ()
|
|
2125
|
+
return function () { return live.off('ws.readyStateUpdate', readyStateUpdate); };
|
|
1764
2126
|
}, [live]);
|
|
1765
2127
|
return state;
|
|
1766
2128
|
}
|
|
1767
2129
|
function useRTCAction() {
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
2130
|
+
var live = useLiveInstance();
|
|
2131
|
+
var join = React__default["default"].useCallback(function (options) { return live.$RTC.join(options); }, [live]);
|
|
2132
|
+
var quit = React__default["default"].useCallback(function () { return live.$RTC.quit(); }, [live]);
|
|
2133
|
+
var shock = React__default["default"].useCallback(function () { var _a, _b; return (_b = (_a = live.$RTC).shock) === null || _b === void 0 ? void 0 : _b.call(_a); }, [live]);
|
|
2134
|
+
var toggleMicro = React__default["default"].useCallback(function (flag) { return live.$RTC.toggleMicro(flag); }, [live]);
|
|
2135
|
+
var detectMicro = React__default["default"].useCallback(function () { return live.$RTC.detectMicro(); }, [live]);
|
|
1774
2136
|
return {
|
|
1775
|
-
join,
|
|
1776
|
-
quit,
|
|
1777
|
-
shock,
|
|
1778
|
-
toggleMicro,
|
|
1779
|
-
detectMicro,
|
|
2137
|
+
join: join,
|
|
2138
|
+
quit: quit,
|
|
2139
|
+
shock: shock,
|
|
2140
|
+
toggleMicro: toggleMicro,
|
|
2141
|
+
detectMicro: detectMicro,
|
|
1780
2142
|
};
|
|
1781
2143
|
}
|
|
1782
|
-
function useRTCEventCallback(name, callback, deps
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
2144
|
+
function useRTCEventCallback(name, callback, deps) {
|
|
2145
|
+
if (deps === void 0) { deps = []; }
|
|
2146
|
+
var live = useLiveInstance();
|
|
2147
|
+
var dispose = function () { return live.$RTC.off(name, callback); };
|
|
2148
|
+
var dependencyList = __spreadArray([live, name], deps, true);
|
|
2149
|
+
React__default["default"].useEffect(function () {
|
|
1787
2150
|
live.$RTC.on(name, callback);
|
|
1788
2151
|
return dispose;
|
|
1789
2152
|
}, dependencyList);
|
|
1790
2153
|
return dispose;
|
|
1791
2154
|
}
|
|
1792
2155
|
function useSelfInfo() {
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
2156
|
+
var _this = this;
|
|
2157
|
+
var live = useLiveInstance();
|
|
2158
|
+
var _a = React__default["default"].useState(live.selfInfo || {}), state = _a[0], updateState = _a[1];
|
|
2159
|
+
var selfInfoUpdate = function (userInfo) {
|
|
2160
|
+
return updateState(userInfo);
|
|
2161
|
+
};
|
|
2162
|
+
React__default["default"].useEffect(function () {
|
|
1797
2163
|
live.on('selfInfoUpdate', selfInfoUpdate);
|
|
1798
|
-
return ()
|
|
1799
|
-
}, [live]);
|
|
1800
|
-
const setState = React__default["default"].useCallback(async (userInfo) => {
|
|
1801
|
-
return await live.setSelfInfo(userInfo);
|
|
2164
|
+
return function () { return live.off('selfInfoUpdate', selfInfoUpdate); };
|
|
1802
2165
|
}, [live]);
|
|
2166
|
+
var setState = React__default["default"].useCallback(function (userInfo) { return __awaiter(_this, void 0, void 0, function () {
|
|
2167
|
+
return __generator(this, function (_a) {
|
|
2168
|
+
switch (_a.label) {
|
|
2169
|
+
case 0: return [4 /*yield*/, live.setSelfInfo(userInfo)];
|
|
2170
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
2171
|
+
}
|
|
2172
|
+
});
|
|
2173
|
+
}); }, [live]);
|
|
1803
2174
|
return [state, setState];
|
|
1804
2175
|
}
|
|
1805
2176
|
function useSnapshot() {
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
React__default["default"].useEffect(()
|
|
1809
|
-
|
|
2177
|
+
var live = useLiveInstance();
|
|
2178
|
+
var _a = React__default["default"].useState(live.snapshot), state = _a[0], setState = _a[1];
|
|
2179
|
+
React__default["default"].useEffect(function () {
|
|
2180
|
+
var onKeyframes = function (keyframes) { return setState(keyframes); };
|
|
1810
2181
|
live.on('keyframes', onKeyframes);
|
|
1811
|
-
return ()
|
|
2182
|
+
return function () { return live.off('keyframes', onKeyframes); };
|
|
1812
2183
|
});
|
|
1813
2184
|
return state;
|
|
1814
2185
|
}
|
|
1815
2186
|
function useUserList() {
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
React__default["default"].useEffect(()
|
|
2187
|
+
var live = useLiveInstance();
|
|
2188
|
+
var _a = React__default["default"].useState(live.userList), state = _a[0], updateState = _a[1];
|
|
2189
|
+
var userListUpdate = function (userList) { return updateState(userList); };
|
|
2190
|
+
React__default["default"].useEffect(function () {
|
|
1820
2191
|
live.on('userListUpdate', userListUpdate);
|
|
1821
|
-
return ()
|
|
2192
|
+
return function () { return live.off('userListUpdate', userListUpdate); };
|
|
1822
2193
|
}, [live]);
|
|
1823
2194
|
return state;
|
|
1824
2195
|
}
|
|
@@ -1830,35 +2201,36 @@ function createLiveReact(options) {
|
|
|
1830
2201
|
* @returns
|
|
1831
2202
|
* @deprecated
|
|
1832
2203
|
*/
|
|
1833
|
-
function useWebSocketEventCallback(name, callback, deps
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
2204
|
+
function useWebSocketEventCallback(name, callback, deps) {
|
|
2205
|
+
if (deps === void 0) { deps = []; }
|
|
2206
|
+
var live = useLiveInstance();
|
|
2207
|
+
var dispose = function () { return live.off(name, callback); };
|
|
2208
|
+
var dependencyList = __spreadArray([live, name], deps, true);
|
|
2209
|
+
React__default["default"].useEffect(function () {
|
|
1838
2210
|
live.on(name, callback);
|
|
1839
2211
|
return dispose;
|
|
1840
2212
|
}, dependencyList);
|
|
1841
2213
|
return dispose;
|
|
1842
2214
|
}
|
|
1843
2215
|
return {
|
|
1844
|
-
live,
|
|
1845
|
-
jsBridge,
|
|
1846
|
-
LiveProvider,
|
|
1847
|
-
unsafe__useLiveInstance,
|
|
1848
|
-
unsafe__useRTCInstance,
|
|
1849
|
-
useCurrentWebSocketUrl,
|
|
1850
|
-
useConnect,
|
|
1851
|
-
useKeyframe,
|
|
1852
|
-
useKeyframeUpdateCallback,
|
|
1853
|
-
useLiveAction,
|
|
1854
|
-
useLiveEventCallback,
|
|
1855
|
-
useReadyState,
|
|
1856
|
-
useRTCAction,
|
|
1857
|
-
useRTCEventCallback,
|
|
1858
|
-
useSelfInfo,
|
|
1859
|
-
useSnapshot,
|
|
1860
|
-
useUserList,
|
|
1861
|
-
useWebSocketEventCallback,
|
|
2216
|
+
live: live,
|
|
2217
|
+
jsBridge: jsBridge,
|
|
2218
|
+
LiveProvider: LiveProvider,
|
|
2219
|
+
unsafe__useLiveInstance: unsafe__useLiveInstance,
|
|
2220
|
+
unsafe__useRTCInstance: unsafe__useRTCInstance,
|
|
2221
|
+
useCurrentWebSocketUrl: useCurrentWebSocketUrl,
|
|
2222
|
+
useConnect: useConnect,
|
|
2223
|
+
useKeyframe: useKeyframe,
|
|
2224
|
+
useKeyframeUpdateCallback: useKeyframeUpdateCallback,
|
|
2225
|
+
useLiveAction: useLiveAction,
|
|
2226
|
+
useLiveEventCallback: useLiveEventCallback,
|
|
2227
|
+
useReadyState: useReadyState,
|
|
2228
|
+
useRTCAction: useRTCAction,
|
|
2229
|
+
useRTCEventCallback: useRTCEventCallback,
|
|
2230
|
+
useSelfInfo: useSelfInfo,
|
|
2231
|
+
useSnapshot: useSnapshot,
|
|
2232
|
+
useUserList: useUserList,
|
|
2233
|
+
useWebSocketEventCallback: useWebSocketEventCallback,
|
|
1862
2234
|
};
|
|
1863
2235
|
}
|
|
1864
2236
|
|