@realsee/live 0.4.0-beta.4 → 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/live/controller.d.ts +2 -2
- package/dist/realsee-live.cjs.development.js +1172 -790
- 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 +1173 -791
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +51277 -50895
- 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/docs/classes/BrowserRTC4Chime.html +3 -3
- package/package.json +15 -15
|
@@ -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,175 +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() {
|
|
503
|
-
|
|
653
|
+
};
|
|
654
|
+
BrowserRTC4Chime.prototype.quit = function () {
|
|
655
|
+
var _this = this;
|
|
656
|
+
if (!this.joined)
|
|
657
|
+
return Promise.resolve(true);
|
|
658
|
+
return new Promise(function (success, fail) {
|
|
504
659
|
var _a, _b;
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
audioVideoDidStop: (sessionStatus)
|
|
508
|
-
|
|
660
|
+
_this.joined = false;
|
|
661
|
+
var observer = {
|
|
662
|
+
audioVideoDidStop: function (sessionStatus) {
|
|
663
|
+
var sessionStatusCode = sessionStatus.statusCode();
|
|
509
664
|
if (sessionStatusCode === amazonChimeSdkJs.MeetingSessionStatusCode.Left) {
|
|
510
665
|
/*
|
|
511
666
|
- You called meetingSession.audioVideo.stop().
|
|
512
667
|
- When closing a browser window or page, Chime SDK attempts to leave the session.
|
|
513
668
|
*/
|
|
514
|
-
|
|
669
|
+
_this.logger.info('You left the session');
|
|
515
670
|
success(true);
|
|
516
671
|
}
|
|
517
672
|
else {
|
|
518
|
-
|
|
673
|
+
_this.logger.info("Stopped with a session status code: ".concat(sessionStatusCode));
|
|
519
674
|
success(true);
|
|
520
675
|
}
|
|
521
676
|
},
|
|
522
677
|
};
|
|
523
|
-
(_a =
|
|
524
|
-
(_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();
|
|
525
680
|
});
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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
|
+
});
|
|
540
700
|
});
|
|
541
|
-
}
|
|
542
|
-
|
|
701
|
+
};
|
|
702
|
+
BrowserRTC4Chime.prototype.toggleMicro = function (flag) {
|
|
543
703
|
var _a, _b, _c;
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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 () {
|
|
559
724
|
throw new Error('Method not implemented.');
|
|
560
|
-
}
|
|
561
|
-
|
|
725
|
+
};
|
|
726
|
+
return BrowserRTC4Chime;
|
|
727
|
+
}(CoreRTC));
|
|
562
728
|
|
|
563
729
|
/**
|
|
564
730
|
* rtc加入返回值code枚举
|
|
@@ -583,75 +749,122 @@ exports.RTCJoinedInfoCodeEnum = void 0;
|
|
|
583
749
|
RTCJoinedInfoCodeEnum[RTCJoinedInfoCodeEnum["NoMicroPermission"] = 3] = "NoMicroPermission";
|
|
584
750
|
})(exports.RTCJoinedInfoCodeEnum || (exports.RTCJoinedInfoCodeEnum = {}));
|
|
585
751
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
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);
|
|
596
764
|
});
|
|
597
|
-
|
|
765
|
+
_this.jsBridge.callAndListen('live/weakNetwork', function (weakNetwork) {
|
|
598
766
|
if (weakNetwork)
|
|
599
|
-
|
|
767
|
+
_this.emit('weakNetwork');
|
|
600
768
|
});
|
|
769
|
+
return _this;
|
|
601
770
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
this
|
|
613
|
-
|
|
614
|
-
|
|
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
|
-
this
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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 () {
|
|
652
864
|
this.jsBridge.shock(1);
|
|
653
|
-
}
|
|
654
|
-
|
|
865
|
+
};
|
|
866
|
+
return VRWebViewRTC;
|
|
867
|
+
}(CoreRTC));
|
|
655
868
|
|
|
656
869
|
/**
|
|
657
870
|
* WebSocket 通信指令
|
|
@@ -736,8 +949,8 @@ exports.MicroStatus = void 0;
|
|
|
736
949
|
*/
|
|
737
950
|
function parseLiveMsg(jsonTxt) {
|
|
738
951
|
try {
|
|
739
|
-
|
|
740
|
-
|
|
952
|
+
var msg = JSON.parse(jsonTxt);
|
|
953
|
+
var resMsg_1 = {
|
|
741
954
|
code: msg.code,
|
|
742
955
|
message: msg.message,
|
|
743
956
|
command: msg.command,
|
|
@@ -748,11 +961,11 @@ function parseLiveMsg(jsonTxt) {
|
|
|
748
961
|
triggerUserID: msg.trigger_user_id,
|
|
749
962
|
data: msg.data || {},
|
|
750
963
|
};
|
|
751
|
-
|
|
964
|
+
var undefinedKeys = Object.keys(resMsg_1).filter(function (key) { return resMsg_1[key] === undefined; });
|
|
752
965
|
if (undefinedKeys.length > 0) {
|
|
753
|
-
console.warn(
|
|
966
|
+
console.warn("\u63A8\u9001\u6570\u636E\u683C\u5F0F\u5F02\u5E38\uFF1A".concat(undefinedKeys.join(" "), " \u503C\u4E0D\u5B58\u5728\uFF01"));
|
|
754
967
|
}
|
|
755
|
-
return
|
|
968
|
+
return resMsg_1;
|
|
756
969
|
}
|
|
757
970
|
catch (error) {
|
|
758
971
|
// notcare? 过滤掉所有不符合规范的数据
|
|
@@ -890,16 +1103,19 @@ function parseWSClsErr(code) {
|
|
|
890
1103
|
}
|
|
891
1104
|
|
|
892
1105
|
function appendUri(uri, query) {
|
|
893
|
-
|
|
894
|
-
|
|
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
|
+
}, '');
|
|
895
1111
|
return uri + newQuery;
|
|
896
1112
|
}
|
|
897
1113
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
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);
|
|
903
1119
|
|
|
904
1120
|
/**
|
|
905
1121
|
* 判断是否是真实的对象类型
|
|
@@ -931,12 +1147,12 @@ function baseIsEqual(value, other) {
|
|
|
931
1147
|
* @returns
|
|
932
1148
|
*/
|
|
933
1149
|
function objEqualShallow(value, other) {
|
|
934
|
-
|
|
935
|
-
|
|
1150
|
+
var valueProps = Object.getOwnPropertyNames(value);
|
|
1151
|
+
var otherProps = Object.getOwnPropertyNames(other);
|
|
936
1152
|
if (valueProps.length !== otherProps.length)
|
|
937
1153
|
return false;
|
|
938
|
-
for (
|
|
939
|
-
|
|
1154
|
+
for (var i = 0, len = valueProps.length; i < len; i++) {
|
|
1155
|
+
var propName = valueProps[i];
|
|
940
1156
|
if (!baseIsEqual(value[propName], other[propName]))
|
|
941
1157
|
return false;
|
|
942
1158
|
}
|
|
@@ -951,7 +1167,7 @@ function objEqualShallow(value, other) {
|
|
|
951
1167
|
function arrayEqualShallow(value, other) {
|
|
952
1168
|
if (value.length !== other.length)
|
|
953
1169
|
return false;
|
|
954
|
-
for (
|
|
1170
|
+
for (var i = 0, len = value.length; i < len; i++) {
|
|
955
1171
|
if (!baseIsEqual(value[i], other[i]))
|
|
956
1172
|
return false;
|
|
957
1173
|
}
|
|
@@ -996,7 +1212,7 @@ function isDeepEqual(value, other) {
|
|
|
996
1212
|
function arrayEqualDeep(value, other) {
|
|
997
1213
|
if (value.length !== other.length)
|
|
998
1214
|
return false;
|
|
999
|
-
for (
|
|
1215
|
+
for (var i = 0, len = value.length; i < len; i++) {
|
|
1000
1216
|
if (!isDeepEqual(value[i], other[i]))
|
|
1001
1217
|
return false;
|
|
1002
1218
|
}
|
|
@@ -1009,12 +1225,12 @@ function arrayEqualDeep(value, other) {
|
|
|
1009
1225
|
* @returns
|
|
1010
1226
|
*/
|
|
1011
1227
|
function objEqualDeep(value, other) {
|
|
1012
|
-
|
|
1013
|
-
|
|
1228
|
+
var valueProps = Object.getOwnPropertyNames(value);
|
|
1229
|
+
var otherProps = Object.getOwnPropertyNames(other);
|
|
1014
1230
|
if (valueProps.length !== otherProps.length)
|
|
1015
1231
|
return false;
|
|
1016
|
-
for (
|
|
1017
|
-
|
|
1232
|
+
for (var i = 0, len = valueProps.length; i < len; i++) {
|
|
1233
|
+
var propName = valueProps[i];
|
|
1018
1234
|
if (!isDeepEqual(value[propName], other[propName]))
|
|
1019
1235
|
return false;
|
|
1020
1236
|
}
|
|
@@ -1028,13 +1244,15 @@ function objEqualDeep(value, other) {
|
|
|
1028
1244
|
* @returns {boolean} 是否相等。
|
|
1029
1245
|
*/
|
|
1030
1246
|
function equal(value, other, opt) {
|
|
1247
|
+
if (opt === void 0) { opt = { deep: false }; }
|
|
1031
1248
|
if (!opt.deep)
|
|
1032
1249
|
return isShallowEqual(value, other);
|
|
1033
1250
|
return isDeepEqual(value, other);
|
|
1034
1251
|
}
|
|
1035
1252
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1253
|
+
var LiveController = /** @class */ (function () {
|
|
1254
|
+
function LiveController(options) {
|
|
1255
|
+
var _this = this;
|
|
1038
1256
|
this.readyState = exports.WebSocketState.NOTINITIALIZED;
|
|
1039
1257
|
this.canSync = true;
|
|
1040
1258
|
this.connecting = false;
|
|
@@ -1042,55 +1260,57 @@ class LiveController {
|
|
|
1042
1260
|
/**
|
|
1043
1261
|
* 检测 WebSocket.readyState 状态
|
|
1044
1262
|
*/
|
|
1045
|
-
this.checkReadyState = (live)
|
|
1263
|
+
this.checkReadyState = function (live) {
|
|
1046
1264
|
do {
|
|
1047
|
-
if (!
|
|
1048
|
-
if (
|
|
1049
|
-
|
|
1050
|
-
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);
|
|
1051
1269
|
}
|
|
1052
1270
|
break;
|
|
1053
1271
|
}
|
|
1054
|
-
|
|
1055
|
-
if (readyState !==
|
|
1056
|
-
|
|
1057
|
-
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);
|
|
1058
1276
|
}
|
|
1059
1277
|
} while (false);
|
|
1060
|
-
return
|
|
1278
|
+
return _this.readyState;
|
|
1061
1279
|
};
|
|
1062
|
-
this.dispose = ()
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
if (
|
|
1066
|
-
clearInterval(
|
|
1067
|
-
|
|
1280
|
+
this.dispose = function () {
|
|
1281
|
+
_this.disposeWebSocket();
|
|
1282
|
+
_this.connecting = false;
|
|
1283
|
+
if (_this.healthCheckId) {
|
|
1284
|
+
clearInterval(_this.healthCheckId);
|
|
1285
|
+
_this.healthCheckId = undefined;
|
|
1068
1286
|
}
|
|
1287
|
+
return true;
|
|
1069
1288
|
};
|
|
1070
1289
|
/**
|
|
1071
1290
|
* 销毁WebSocket相关依赖。
|
|
1072
1291
|
*/
|
|
1073
|
-
this.disposeWebSocket = ()
|
|
1074
|
-
if (!
|
|
1292
|
+
this.disposeWebSocket = function () {
|
|
1293
|
+
if (!_this.webSocket)
|
|
1075
1294
|
return;
|
|
1076
|
-
if (
|
|
1077
|
-
|
|
1078
|
-
|
|
1295
|
+
if (_this.onEvtOpnListener) {
|
|
1296
|
+
_this.webSocket.removeEventListener('open', _this.onEvtOpnListener);
|
|
1297
|
+
_this.onEvtOpnListener = undefined;
|
|
1079
1298
|
}
|
|
1080
|
-
if (
|
|
1081
|
-
|
|
1082
|
-
|
|
1299
|
+
if (_this.onEvtMsgListener) {
|
|
1300
|
+
_this.webSocket.removeEventListener('message', _this.onEvtMsgListener);
|
|
1301
|
+
_this.onEvtMsgListener = undefined;
|
|
1083
1302
|
}
|
|
1084
|
-
if (
|
|
1085
|
-
|
|
1086
|
-
|
|
1303
|
+
if (_this.onEvtErrListener) {
|
|
1304
|
+
_this.webSocket.removeEventListener('error', _this.onEvtErrListener);
|
|
1305
|
+
_this.onEvtErrListener = undefined;
|
|
1087
1306
|
}
|
|
1088
|
-
if (
|
|
1089
|
-
|
|
1090
|
-
|
|
1307
|
+
if (_this.onEvtCLEListener) {
|
|
1308
|
+
_this.webSocket.removeEventListener('close', _this.onEvtCLEListener);
|
|
1309
|
+
_this.onEvtCLEListener = undefined;
|
|
1091
1310
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1311
|
+
_this.webSocket.close();
|
|
1312
|
+
_this.webSocket = undefined;
|
|
1313
|
+
return true;
|
|
1094
1314
|
};
|
|
1095
1315
|
this.options = Object.assign({ autoConnect: true, healthCheck: 3000 }, options);
|
|
1096
1316
|
}
|
|
@@ -1099,16 +1319,17 @@ class LiveController {
|
|
|
1099
1319
|
* @param liveMsg
|
|
1100
1320
|
* @param live
|
|
1101
1321
|
*/
|
|
1102
|
-
handleMessage(liveMsg, live) {
|
|
1322
|
+
LiveController.prototype.handleMessage = function (liveMsg, live) {
|
|
1323
|
+
var _this = this;
|
|
1103
1324
|
var _a, _b, _c;
|
|
1104
|
-
|
|
1325
|
+
var command = liveMsg.command, data = liveMsg.data, frontRequestId = liveMsg.frontRequestId, code = liveMsg.code;
|
|
1105
1326
|
if (code === 'SUCCESS') {
|
|
1106
1327
|
switch (command) {
|
|
1107
1328
|
/**
|
|
1108
1329
|
* 自己的状态变化
|
|
1109
1330
|
*/
|
|
1110
1331
|
case exports.Command.SelfUserInfo: {
|
|
1111
|
-
|
|
1332
|
+
var selfInfo = data;
|
|
1112
1333
|
if (equal(this.selfUserInfo, selfInfo, { deep: true }))
|
|
1113
1334
|
return;
|
|
1114
1335
|
this.selfUserInfo = selfInfo;
|
|
@@ -1119,7 +1340,7 @@ class LiveController {
|
|
|
1119
1340
|
* 房间信息变化
|
|
1120
1341
|
*/
|
|
1121
1342
|
case exports.Command.RoomInfo: {
|
|
1122
|
-
|
|
1343
|
+
var roomInfo = data;
|
|
1123
1344
|
this.roomInfo = Object.assign({}, roomInfo);
|
|
1124
1345
|
live.emit('readyKeyframeSync', (roomInfo.last_frame || {}));
|
|
1125
1346
|
break;
|
|
@@ -1128,16 +1349,16 @@ class LiveController {
|
|
|
1128
1349
|
* 语音信息变化
|
|
1129
1350
|
*/
|
|
1130
1351
|
case exports.Command.RTCInfo: {
|
|
1131
|
-
|
|
1352
|
+
var _d = data, voiceId = _d.voice_id, type = _d.type;
|
|
1132
1353
|
/* 如果已经进入语音房间,则不重复进入 --> "RTCInfo" 指令可能会下发多次 */
|
|
1133
1354
|
if (live.$RTC.joined) {
|
|
1134
1355
|
break;
|
|
1135
1356
|
}
|
|
1136
1357
|
live.$RTC.join({
|
|
1137
|
-
voiceId,
|
|
1358
|
+
voiceId: voiceId,
|
|
1138
1359
|
userId: ((_a = this.selfUserInfo) === null || _a === void 0 ? void 0 : _a.id) || '',
|
|
1139
1360
|
roomId: (_b = this.roomInfo) === null || _b === void 0 ? void 0 : _b.info.room_code,
|
|
1140
|
-
type,
|
|
1361
|
+
type: type,
|
|
1141
1362
|
});
|
|
1142
1363
|
// 加入房间后 麦克风默认就开启了:需要发个指令。
|
|
1143
1364
|
live.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
|
|
@@ -1149,7 +1370,7 @@ class LiveController {
|
|
|
1149
1370
|
* 房间用户列表变化
|
|
1150
1371
|
*/
|
|
1151
1372
|
case exports.Command.UserList: {
|
|
1152
|
-
|
|
1373
|
+
var userList = data;
|
|
1153
1374
|
this.userList = userList;
|
|
1154
1375
|
live.emit('userListUpdate', this.userList, frontRequestId);
|
|
1155
1376
|
break;
|
|
@@ -1158,7 +1379,7 @@ class LiveController {
|
|
|
1158
1379
|
* 自定义事件广播
|
|
1159
1380
|
*/
|
|
1160
1381
|
case exports.Command.CustomEvent: {
|
|
1161
|
-
|
|
1382
|
+
var evtMsg = data;
|
|
1162
1383
|
live.emit('broadcast', evtMsg, frontRequestId);
|
|
1163
1384
|
break;
|
|
1164
1385
|
}
|
|
@@ -1166,21 +1387,22 @@ class LiveController {
|
|
|
1166
1387
|
* 帧数据同步
|
|
1167
1388
|
*/
|
|
1168
1389
|
case exports.Command.KeyframeSync: {
|
|
1169
|
-
|
|
1390
|
+
var remoteKeyframes_1 = data;
|
|
1170
1391
|
// 此处做一层 diff,仅跟本地数据不一致的情况下才广播数据。
|
|
1171
|
-
|
|
1172
|
-
|
|
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 })) {
|
|
1173
1395
|
return accu;
|
|
1174
1396
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1397
|
+
var params = [
|
|
1398
|
+
remoteKeyframes_1[curr],
|
|
1399
|
+
_this.keyframes[curr],
|
|
1178
1400
|
frontRequestId,
|
|
1179
1401
|
];
|
|
1180
|
-
|
|
1181
|
-
live.keyframes.emit(evtName,
|
|
1182
|
-
|
|
1183
|
-
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];
|
|
1184
1406
|
return accu;
|
|
1185
1407
|
}, {});
|
|
1186
1408
|
live.emit('keyframes', keyframes, frontRequestId);
|
|
@@ -1190,7 +1412,7 @@ class LiveController {
|
|
|
1190
1412
|
* 内置消息
|
|
1191
1413
|
*/
|
|
1192
1414
|
case exports.Command.BuiltinMsg: {
|
|
1193
|
-
|
|
1415
|
+
var builtinMsg = data;
|
|
1194
1416
|
live.emit('builtinEvent', builtinMsg);
|
|
1195
1417
|
if (builtinMsg.event_type === exports.BuiltinEventType.UserChange) {
|
|
1196
1418
|
live.emit('userChange', builtinMsg);
|
|
@@ -1233,27 +1455,31 @@ class LiveController {
|
|
|
1233
1455
|
else {
|
|
1234
1456
|
live.emit('error', liveMsg);
|
|
1235
1457
|
}
|
|
1236
|
-
}
|
|
1458
|
+
};
|
|
1237
1459
|
/**
|
|
1238
1460
|
* 发送数据
|
|
1239
1461
|
* @param data
|
|
1240
1462
|
*/
|
|
1241
|
-
sendMessage(data) {
|
|
1463
|
+
LiveController.prototype.sendMessage = function (data) {
|
|
1242
1464
|
if (!this.webSocket)
|
|
1243
1465
|
return console.warn('WebSocket has not yet been initialized!');
|
|
1244
1466
|
if (!data)
|
|
1245
1467
|
return console.warn('WebSocket messages is empty!');
|
|
1246
1468
|
this.webSocket.send(JSON.stringify(data));
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1469
|
+
};
|
|
1470
|
+
return LiveController;
|
|
1471
|
+
}());
|
|
1249
1472
|
|
|
1250
|
-
|
|
1473
|
+
var unimplementedGetVoiceSign = function (params) {
|
|
1474
|
+
return Promise.reject('unimplemented method GetVoiceSign');
|
|
1475
|
+
};
|
|
1251
1476
|
/**
|
|
1252
1477
|
* 创建 `live` 实例。
|
|
1253
1478
|
*/
|
|
1254
1479
|
function createLive(options) {
|
|
1255
|
-
|
|
1256
|
-
|
|
1480
|
+
var liveController = new LiveController(options);
|
|
1481
|
+
var createLiveMsg = function (command, data, toUserIds) {
|
|
1482
|
+
if (data === void 0) { data = {}; }
|
|
1257
1483
|
toUserIds = toUserIds
|
|
1258
1484
|
? Array.isArray(toUserIds)
|
|
1259
1485
|
? toUserIds
|
|
@@ -1261,14 +1487,16 @@ function createLive(options) {
|
|
|
1261
1487
|
: [];
|
|
1262
1488
|
if (toUserIds)
|
|
1263
1489
|
data['to_user_ids'] = toUserIds;
|
|
1264
|
-
return { command, front_request_id: uuid(), data };
|
|
1490
|
+
return { command: command, front_request_id: uuid(), data: data };
|
|
1265
1491
|
};
|
|
1266
|
-
|
|
1267
|
-
|
|
1492
|
+
var LiveTpl = /** @class */ (function (_super) {
|
|
1493
|
+
__extends(LiveTpl, _super);
|
|
1494
|
+
function LiveTpl() {
|
|
1495
|
+
var _this = this;
|
|
1268
1496
|
var _a, _b;
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1497
|
+
_this = _super.call(this) || this;
|
|
1498
|
+
_this.keyframes = new Subscribe();
|
|
1499
|
+
var jsBridge = (function () {
|
|
1272
1500
|
if (options.jsBridge)
|
|
1273
1501
|
return options.jsBridge;
|
|
1274
1502
|
if (options.useBuiltInJsBridge)
|
|
@@ -1283,7 +1511,7 @@ function createLive(options) {
|
|
|
1283
1511
|
if (!options.getVoiceSign) {
|
|
1284
1512
|
throw new Error('GetVoiceSign method must be passed when using built-in RTC instances');
|
|
1285
1513
|
}
|
|
1286
|
-
|
|
1514
|
+
var getVoiceSign = (_a = options.getVoiceSign) !== null && _a !== void 0 ? _a : unimplementedGetVoiceSign;
|
|
1287
1515
|
switch (options.rtcType) {
|
|
1288
1516
|
case exports.RTCType.RealseeVRWebViewRTC: {
|
|
1289
1517
|
// 内置的 VRWebViewRTC
|
|
@@ -1291,15 +1519,15 @@ function createLive(options) {
|
|
|
1291
1519
|
throw new Error('JsBridge instance must be passed when using built-in VRWebViewRTC instances');
|
|
1292
1520
|
}
|
|
1293
1521
|
liveController.options.rtc = new VRWebViewRTC({
|
|
1294
|
-
jsBridge,
|
|
1295
|
-
getVoiceSign,
|
|
1522
|
+
jsBridge: jsBridge,
|
|
1523
|
+
getVoiceSign: getVoiceSign,
|
|
1296
1524
|
});
|
|
1297
1525
|
break;
|
|
1298
1526
|
}
|
|
1299
1527
|
case exports.RTCType.RealseeBrowserChimeRTC: {
|
|
1300
1528
|
// 内置的 RealseeBrowserChimeRTC
|
|
1301
1529
|
liveController.options.rtc = new BrowserRTC4Chime({
|
|
1302
|
-
getVoiceSign,
|
|
1530
|
+
getVoiceSign: getVoiceSign,
|
|
1303
1531
|
logLevel: options.__debug__ ? amazonChimeSdkJs.LogLevel.DEBUG : amazonChimeSdkJs.LogLevel.ERROR,
|
|
1304
1532
|
});
|
|
1305
1533
|
break;
|
|
@@ -1307,7 +1535,7 @@ function createLive(options) {
|
|
|
1307
1535
|
case exports.RTCType.RealseeBrowserRTC: {
|
|
1308
1536
|
// 内置的 RealseeBrowserRTC
|
|
1309
1537
|
liveController.options.rtc = new BrowserRTC({
|
|
1310
|
-
getVoiceSign,
|
|
1538
|
+
getVoiceSign: getVoiceSign,
|
|
1311
1539
|
});
|
|
1312
1540
|
break;
|
|
1313
1541
|
}
|
|
@@ -1321,23 +1549,23 @@ function createLive(options) {
|
|
|
1321
1549
|
if (!options.getVoiceSign) {
|
|
1322
1550
|
throw new Error('GetVoiceSign method must be passed when using built-in RTC instances');
|
|
1323
1551
|
}
|
|
1324
|
-
|
|
1552
|
+
var getVoiceSign = (_b = options.getVoiceSign) !== null && _b !== void 0 ? _b : unimplementedGetVoiceSign;
|
|
1325
1553
|
if (!jsBridge) {
|
|
1326
1554
|
throw new Error('jsBridge instance must be passed when using built-in RTC instances');
|
|
1327
1555
|
}
|
|
1328
1556
|
// vrwebview 默认
|
|
1329
1557
|
if ((isRealseeVRWebview && (isAndroid || isIOS)) || isWxMiniProgram) {
|
|
1330
1558
|
liveController.options.rtc = new VRWebViewRTC({
|
|
1331
|
-
jsBridge,
|
|
1332
|
-
getVoiceSign,
|
|
1559
|
+
jsBridge: jsBridge,
|
|
1560
|
+
getVoiceSign: getVoiceSign,
|
|
1333
1561
|
});
|
|
1334
1562
|
}
|
|
1335
1563
|
else {
|
|
1336
1564
|
// 其它终端使用
|
|
1337
1565
|
liveController.options.rtc =
|
|
1338
1566
|
options.builtInRTCType === exports.BuiltInRTCType.RealseeXChimeRTC
|
|
1339
|
-
? new BrowserRTC4Chime({ getVoiceSign })
|
|
1340
|
-
: new BrowserRTC({ getVoiceSign });
|
|
1567
|
+
? new BrowserRTC4Chime({ getVoiceSign: getVoiceSign })
|
|
1568
|
+
: new BrowserRTC({ getVoiceSign: getVoiceSign });
|
|
1341
1569
|
}
|
|
1342
1570
|
}
|
|
1343
1571
|
}
|
|
@@ -1346,282 +1574,407 @@ function createLive(options) {
|
|
|
1346
1574
|
}
|
|
1347
1575
|
// 默认自动连接
|
|
1348
1576
|
if (liveController.options.url && liveController.options.getTicket) {
|
|
1349
|
-
|
|
1577
|
+
_this.connect();
|
|
1350
1578
|
}
|
|
1351
1579
|
// 健康检查:WHY --> 在某些WebView特殊场景下 WebSocket.readyState 发生变化时不会出发error\close等事件;
|
|
1352
1580
|
// 因此,开启一个定时任务监测 WebSocket.readyState 状态的更新
|
|
1353
|
-
|
|
1581
|
+
var healthCheck = (function (healthCheck) {
|
|
1354
1582
|
if (!healthCheck)
|
|
1355
1583
|
return 0;
|
|
1356
1584
|
if (healthCheck === true)
|
|
1357
1585
|
return 3000;
|
|
1358
|
-
|
|
1586
|
+
var duration = Number(healthCheck);
|
|
1359
1587
|
if (duration > 0)
|
|
1360
1588
|
return duration;
|
|
1361
1589
|
return 3000;
|
|
1362
1590
|
})(liveController.options.healthCheck);
|
|
1363
1591
|
if (healthCheck) {
|
|
1364
|
-
liveController.healthCheckId = setInterval(()
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
get options() {
|
|
1368
|
-
return Object.freeze(Object.assign({}, liveController.options));
|
|
1369
|
-
}
|
|
1370
|
-
get readyState() {
|
|
1371
|
-
liveController.checkReadyState(this);
|
|
1372
|
-
return liveController.readyState;
|
|
1373
|
-
}
|
|
1374
|
-
get url() {
|
|
1375
|
-
var _a;
|
|
1376
|
-
return ((_a = liveController.webSocket) === null || _a === void 0 ? void 0 : _a.url) || '';
|
|
1377
|
-
}
|
|
1378
|
-
get selfInfo() {
|
|
1379
|
-
return liveController.selfUserInfo;
|
|
1380
|
-
}
|
|
1381
|
-
get userList() {
|
|
1382
|
-
return liveController.userList || [];
|
|
1383
|
-
}
|
|
1384
|
-
get snapshot() {
|
|
1385
|
-
return liveController.keyframes || {};
|
|
1386
|
-
}
|
|
1387
|
-
get $RTC() {
|
|
1388
|
-
return liveController.options.rtc;
|
|
1389
|
-
}
|
|
1390
|
-
get jsBridge() {
|
|
1391
|
-
return liveController.options.jsBridge;
|
|
1392
|
-
}
|
|
1393
|
-
async setSelfInfo(userInfo) {
|
|
1394
|
-
if (this.readyState !== exports.WebSocketState.OPEN) {
|
|
1395
|
-
return new Error('The connection is not open and ready to communicate.');
|
|
1396
|
-
}
|
|
1397
|
-
try {
|
|
1398
|
-
return await this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserInfo, userInfo);
|
|
1399
|
-
}
|
|
1400
|
-
catch (error) {
|
|
1401
|
-
return error;
|
|
1592
|
+
liveController.healthCheckId = setInterval(function () { return liveController.checkReadyState(_this); }, healthCheck);
|
|
1402
1593
|
}
|
|
1594
|
+
return _this;
|
|
1403
1595
|
}
|
|
1404
|
-
|
|
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) {
|
|
1405
1677
|
return liveController.keyframes[key];
|
|
1406
|
-
}
|
|
1407
|
-
sendKeyframe(key, frame) {
|
|
1678
|
+
};
|
|
1679
|
+
LiveTpl.prototype.sendKeyframe = function (key, frame) {
|
|
1408
1680
|
if (this.readyState !== exports.WebSocketState.OPEN) {
|
|
1409
1681
|
return new Error('The connection is not open and ready to communicate.');
|
|
1410
1682
|
}
|
|
1411
1683
|
liveController.keyframes[key] = frame;
|
|
1412
|
-
|
|
1684
|
+
var liveMsg = createLiveMsg(exports.Command.KeyframeSync, this.snapshot);
|
|
1413
1685
|
liveController.sendMessage(liveMsg);
|
|
1414
1686
|
return true;
|
|
1415
|
-
}
|
|
1416
|
-
broadcast(data, toUserIds, timeout) {
|
|
1687
|
+
};
|
|
1688
|
+
LiveTpl.prototype.broadcast = function (data, toUserIds, timeout) {
|
|
1689
|
+
var _this = this;
|
|
1417
1690
|
if (this.readyState !== exports.WebSocketState.OPEN) {
|
|
1418
1691
|
return new Error('The connection is not open and ready to communicate.');
|
|
1419
1692
|
}
|
|
1420
|
-
return new Promise((resolve, reject)
|
|
1421
|
-
|
|
1422
|
-
|
|
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;
|
|
1423
1696
|
liveController.sendMessage(customEvent);
|
|
1424
|
-
|
|
1425
|
-
? setTimeout(()
|
|
1697
|
+
var timeoutId = timeout
|
|
1698
|
+
? setTimeout(function () {
|
|
1426
1699
|
reject(new Error('RESPONSE TIMEOUT'));
|
|
1427
|
-
|
|
1700
|
+
_this.off('broadcast', broadcast);
|
|
1428
1701
|
}, timeout)
|
|
1429
1702
|
: undefined;
|
|
1430
|
-
|
|
1703
|
+
var broadcast = function (data, frontRequestId) {
|
|
1431
1704
|
if (frontRequestId !== front_request_id)
|
|
1432
1705
|
return;
|
|
1433
|
-
|
|
1706
|
+
_this.off('broadcast', broadcast);
|
|
1434
1707
|
resolve(data);
|
|
1435
1708
|
if (timeoutId)
|
|
1436
1709
|
clearInterval(timeoutId);
|
|
1437
1710
|
};
|
|
1438
|
-
|
|
1711
|
+
_this.on('broadcast', broadcast);
|
|
1439
1712
|
});
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
return
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
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
|
+
};
|
|
1451
1729
|
// 仅用于用户自己的麦克风控制
|
|
1452
|
-
|
|
1730
|
+
LiveTpl.prototype.toggleMicro = function (microStatus) {
|
|
1453
1731
|
var _a, _b;
|
|
1454
|
-
|
|
1455
|
-
return
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
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) {
|
|
1462
1750
|
var _a, _b;
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
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
|
+
};
|
|
1474
1770
|
/**
|
|
1475
1771
|
* @deprecated 暂不可用
|
|
1476
1772
|
*/
|
|
1477
|
-
|
|
1773
|
+
LiveTpl.prototype.forbidSync = function (sync, toUserIds) {
|
|
1478
1774
|
var _a, _b;
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
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) {
|
|
1489
1793
|
var _a, _b;
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
async connect(options = {}) {
|
|
1507
|
-
// 连接 WebSocket 前验证麦克风权限
|
|
1508
|
-
const microAuth = await this.$RTC.detectMicro();
|
|
1509
|
-
if (!microAuth) {
|
|
1510
|
-
const error = new Error('系统监测麦克风未授权~');
|
|
1511
|
-
this.emit('ws.error', { type: exports.WebSocketErrorType.MicroAuth, error });
|
|
1512
|
-
return error;
|
|
1513
|
-
}
|
|
1514
|
-
// WebSocket 正在连接中,规避重复连接
|
|
1515
|
-
if (liveController.connecting) {
|
|
1516
|
-
const error = new Error('WebSocket 正在连接中,请勿重复连接 ...');
|
|
1517
|
-
this.emit('ws.error', {
|
|
1518
|
-
type: exports.WebSocketErrorType.DuplicateConnect,
|
|
1519
|
-
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
|
+
}
|
|
1520
1810
|
});
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
this.emit('ws.error', { type: exports.WebSocketErrorType.IllegalURL, error });
|
|
1542
|
-
return error;
|
|
1543
|
-
}
|
|
1544
|
-
if (!liveController.options.getTicket) {
|
|
1545
|
-
const error = new Error(`getTicket() 未配置!`);
|
|
1546
|
-
this.emit('ws.error', { type: exports.WebSocketErrorType.IllegalArgs, error });
|
|
1547
|
-
return error;
|
|
1548
|
-
}
|
|
1549
|
-
// 连接锁
|
|
1550
|
-
liveController.connecting = true;
|
|
1551
|
-
// 连接前销毁之前绑定的事件
|
|
1552
|
-
liveController.disposeWebSocket();
|
|
1553
|
-
this.emit('ws.beforeConnect');
|
|
1554
|
-
const url = force || options.url || !this.url
|
|
1555
|
-
? appendUri(liveController.options.url, {
|
|
1556
|
-
ticket: await liveController.options.getTicket(),
|
|
1557
|
-
force: Number(!!force),
|
|
1558
|
-
})
|
|
1559
|
-
: this.url;
|
|
1560
|
-
liveController.webSocket = new WebSocket(url);
|
|
1561
|
-
liveController.onEvtOpnListener = () => {
|
|
1562
|
-
liveController.checkReadyState(this);
|
|
1563
|
-
this.emit('ws.afterConnect');
|
|
1564
|
-
};
|
|
1565
|
-
liveController.onEvtMsgListener = (evt) => {
|
|
1566
|
-
liveController.checkReadyState(this);
|
|
1567
|
-
try {
|
|
1568
|
-
const liveMsg = parseLiveMsg(evt.data);
|
|
1569
|
-
if (liveMsg === false)
|
|
1570
|
-
return;
|
|
1571
|
-
liveController.handleMessage(liveMsg, this);
|
|
1572
|
-
}
|
|
1573
|
-
catch (error) {
|
|
1574
|
-
// 未知错误
|
|
1575
|
-
this.emit('ws.error', {
|
|
1576
|
-
type: exports.WebSocketErrorType.Unknown,
|
|
1577
|
-
error,
|
|
1578
|
-
target: evt,
|
|
1579
|
-
});
|
|
1580
|
-
}
|
|
1581
|
-
};
|
|
1582
|
-
liveController.onEvtErrListener = (evt) => {
|
|
1583
|
-
live.emit('ws.error', { type: exports.WebSocketErrorType.Error, target: evt });
|
|
1584
|
-
liveController.checkReadyState(this);
|
|
1585
|
-
};
|
|
1586
|
-
liveController.onEvtCLEListener = (evt) => {
|
|
1587
|
-
liveController.checkReadyState(this);
|
|
1588
|
-
const code = Number(evt.code);
|
|
1589
|
-
if (code === 1000)
|
|
1590
|
-
return;
|
|
1591
|
-
// 异常退出不一定会触发'error'事件,根据 evt.code 一些类型的退出也算是 error 行为
|
|
1592
|
-
const errMsg = parseWSClsErr(code);
|
|
1593
|
-
live.emit('ws.error', {
|
|
1594
|
-
target: evt,
|
|
1595
|
-
type: exports.WebSocketErrorType.Close,
|
|
1596
|
-
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
|
+
}
|
|
1597
1831
|
});
|
|
1598
|
-
};
|
|
1599
|
-
liveController.webSocket.addEventListener('open', liveController.onEvtOpnListener);
|
|
1600
|
-
liveController.webSocket.addEventListener('message', liveController.onEvtMsgListener);
|
|
1601
|
-
liveController.webSocket.addEventListener('error', liveController.onEvtErrListener);
|
|
1602
|
-
liveController.webSocket.addEventListener('close', liveController.onEvtCLEListener);
|
|
1603
|
-
return await new Promise((resolve, reject) => {
|
|
1604
|
-
const success = () => {
|
|
1605
|
-
resolve(true);
|
|
1606
|
-
liveController.connecting = false;
|
|
1607
|
-
this.off('ws.error', fail);
|
|
1608
|
-
};
|
|
1609
|
-
const fail = (error) => {
|
|
1610
|
-
reject(error.error
|
|
1611
|
-
? error.error
|
|
1612
|
-
: new Error('WebSocket connection failed!'));
|
|
1613
|
-
liveController.connecting = false;
|
|
1614
|
-
this.off('ws.afterConnect', success);
|
|
1615
|
-
};
|
|
1616
|
-
this.once('ws.afterConnect', success);
|
|
1617
|
-
this.once('ws.error', fail);
|
|
1618
1832
|
});
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
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();
|
|
1625
1978
|
// 如果是调试环境则将内部状态暴露出来
|
|
1626
1979
|
if (options.__debug__) {
|
|
1627
1980
|
Object.assign(live, { __controller__: liveController });
|
|
@@ -1634,14 +1987,14 @@ function createLive(options) {
|
|
|
1634
1987
|
* 创建 {@link LiveReact} 实例,并提供 `React` 技术栈相关工具链。
|
|
1635
1988
|
*/
|
|
1636
1989
|
function createLiveReact(options) {
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1990
|
+
var LiveContext = React__default["default"].createContext(null);
|
|
1991
|
+
var live = createLive(options);
|
|
1992
|
+
var jsBridge = live.jsBridge;
|
|
1640
1993
|
function LiveProvider(props) {
|
|
1641
1994
|
return (React__default["default"].createElement(LiveContext.Provider, { value: props.live || live }, props.children));
|
|
1642
1995
|
}
|
|
1643
1996
|
function useLiveInstance() {
|
|
1644
|
-
|
|
1997
|
+
var context = React__default["default"].useContext(LiveContext);
|
|
1645
1998
|
if (!context)
|
|
1646
1999
|
throw new Error('LiveProvider never found.');
|
|
1647
2000
|
return context;
|
|
@@ -1654,7 +2007,7 @@ function createLiveReact(options) {
|
|
|
1654
2007
|
return useLiveInstance();
|
|
1655
2008
|
}
|
|
1656
2009
|
function useRTCInstance() {
|
|
1657
|
-
|
|
2010
|
+
var live = useLiveInstance();
|
|
1658
2011
|
return live.$RTC;
|
|
1659
2012
|
}
|
|
1660
2013
|
/**
|
|
@@ -1665,76 +2018,93 @@ function createLiveReact(options) {
|
|
|
1665
2018
|
return useRTCInstance();
|
|
1666
2019
|
}
|
|
1667
2020
|
function useConnect() {
|
|
1668
|
-
|
|
1669
|
-
|
|
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
|
+
}); }); };
|
|
1670
2029
|
}
|
|
1671
2030
|
function useCurrentWebSocketUrl() {
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
React__default["default"].useEffect(()
|
|
1675
|
-
|
|
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); };
|
|
1676
2035
|
live.on('ws.beforeConnect', onWSBeforeConnect);
|
|
1677
|
-
return ()
|
|
2036
|
+
return function () { return live.off('ws.beforeConnect', onWSBeforeConnect); };
|
|
1678
2037
|
}, [live]);
|
|
1679
2038
|
return state;
|
|
1680
2039
|
}
|
|
1681
|
-
function useKeyframeUpdateCallback(name, callback, deps
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
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 () {
|
|
1686
2046
|
live.keyframes.on(name, callback);
|
|
1687
2047
|
return dispose;
|
|
1688
2048
|
}, dependencyList);
|
|
1689
2049
|
return dispose;
|
|
1690
2050
|
}
|
|
1691
2051
|
function useLiveAction() {
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
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]);
|
|
1698
2063
|
// const forbidSync = React.useCallback(
|
|
1699
2064
|
// (sync: boolean, toUserIds?: string | string[] | undefined) =>
|
|
1700
2065
|
// live.forbidSync(sync, toUserIds),
|
|
1701
2066
|
// [live],
|
|
1702
2067
|
// );
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
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]);
|
|
1707
2074
|
return {
|
|
1708
|
-
broadcast,
|
|
1709
|
-
exit,
|
|
1710
|
-
kick,
|
|
1711
|
-
toggleMicro,
|
|
1712
|
-
forbidMicro,
|
|
2075
|
+
broadcast: broadcast,
|
|
2076
|
+
exit: exit,
|
|
2077
|
+
kick: kick,
|
|
2078
|
+
toggleMicro: toggleMicro,
|
|
2079
|
+
forbidMicro: forbidMicro,
|
|
1713
2080
|
// forbidSync,
|
|
1714
|
-
sendKeyframe,
|
|
1715
|
-
getFramesByKey,
|
|
1716
|
-
setSelfInfo,
|
|
1717
|
-
updateStatus,
|
|
2081
|
+
sendKeyframe: sendKeyframe,
|
|
2082
|
+
getFramesByKey: getFramesByKey,
|
|
2083
|
+
setSelfInfo: setSelfInfo,
|
|
2084
|
+
updateStatus: updateStatus,
|
|
1718
2085
|
};
|
|
1719
2086
|
}
|
|
1720
2087
|
function useKeyframe(key) {
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
React__default["default"].useEffect(()
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
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;
|
|
1727
2096
|
live.keyframes.on(evtName, callback);
|
|
1728
|
-
return ()
|
|
2097
|
+
return function () { return live.keyframes.off(evtName, callback); };
|
|
1729
2098
|
}, [live]);
|
|
1730
|
-
|
|
2099
|
+
var setState = React__default["default"].useCallback(function (frame) { return live.sendKeyframe(key, frame); }, [live]);
|
|
1731
2100
|
return [state, setState];
|
|
1732
2101
|
}
|
|
1733
|
-
function useLiveEventCallback(name, callback, deps
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
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 () {
|
|
1738
2108
|
live.on(name, callback);
|
|
1739
2109
|
return dispose;
|
|
1740
2110
|
}, dependencyList);
|
|
@@ -1745,70 +2115,81 @@ function createLiveReact(options) {
|
|
|
1745
2115
|
* @returns
|
|
1746
2116
|
*/
|
|
1747
2117
|
function useReadyState() {
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
React__default["default"].useEffect(()
|
|
1751
|
-
|
|
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
|
+
};
|
|
1752
2124
|
live.on('ws.readyStateUpdate', readyStateUpdate);
|
|
1753
|
-
return ()
|
|
2125
|
+
return function () { return live.off('ws.readyStateUpdate', readyStateUpdate); };
|
|
1754
2126
|
}, [live]);
|
|
1755
2127
|
return state;
|
|
1756
2128
|
}
|
|
1757
2129
|
function useRTCAction() {
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
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]);
|
|
1764
2136
|
return {
|
|
1765
|
-
join,
|
|
1766
|
-
quit,
|
|
1767
|
-
shock,
|
|
1768
|
-
toggleMicro,
|
|
1769
|
-
detectMicro,
|
|
2137
|
+
join: join,
|
|
2138
|
+
quit: quit,
|
|
2139
|
+
shock: shock,
|
|
2140
|
+
toggleMicro: toggleMicro,
|
|
2141
|
+
detectMicro: detectMicro,
|
|
1770
2142
|
};
|
|
1771
2143
|
}
|
|
1772
|
-
function useRTCEventCallback(name, callback, deps
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
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 () {
|
|
1777
2150
|
live.$RTC.on(name, callback);
|
|
1778
2151
|
return dispose;
|
|
1779
2152
|
}, dependencyList);
|
|
1780
2153
|
return dispose;
|
|
1781
2154
|
}
|
|
1782
2155
|
function useSelfInfo() {
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
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 () {
|
|
1787
2163
|
live.on('selfInfoUpdate', selfInfoUpdate);
|
|
1788
|
-
return ()
|
|
1789
|
-
}, [live]);
|
|
1790
|
-
const setState = React__default["default"].useCallback(async (userInfo) => {
|
|
1791
|
-
return await live.setSelfInfo(userInfo);
|
|
2164
|
+
return function () { return live.off('selfInfoUpdate', selfInfoUpdate); };
|
|
1792
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]);
|
|
1793
2174
|
return [state, setState];
|
|
1794
2175
|
}
|
|
1795
2176
|
function useSnapshot() {
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
React__default["default"].useEffect(()
|
|
1799
|
-
|
|
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); };
|
|
1800
2181
|
live.on('keyframes', onKeyframes);
|
|
1801
|
-
return ()
|
|
2182
|
+
return function () { return live.off('keyframes', onKeyframes); };
|
|
1802
2183
|
});
|
|
1803
2184
|
return state;
|
|
1804
2185
|
}
|
|
1805
2186
|
function useUserList() {
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
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 () {
|
|
1810
2191
|
live.on('userListUpdate', userListUpdate);
|
|
1811
|
-
return ()
|
|
2192
|
+
return function () { return live.off('userListUpdate', userListUpdate); };
|
|
1812
2193
|
}, [live]);
|
|
1813
2194
|
return state;
|
|
1814
2195
|
}
|
|
@@ -1820,35 +2201,36 @@ function createLiveReact(options) {
|
|
|
1820
2201
|
* @returns
|
|
1821
2202
|
* @deprecated
|
|
1822
2203
|
*/
|
|
1823
|
-
function useWebSocketEventCallback(name, callback, deps
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
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 () {
|
|
1828
2210
|
live.on(name, callback);
|
|
1829
2211
|
return dispose;
|
|
1830
2212
|
}, dependencyList);
|
|
1831
2213
|
return dispose;
|
|
1832
2214
|
}
|
|
1833
2215
|
return {
|
|
1834
|
-
live,
|
|
1835
|
-
jsBridge,
|
|
1836
|
-
LiveProvider,
|
|
1837
|
-
unsafe__useLiveInstance,
|
|
1838
|
-
unsafe__useRTCInstance,
|
|
1839
|
-
useCurrentWebSocketUrl,
|
|
1840
|
-
useConnect,
|
|
1841
|
-
useKeyframe,
|
|
1842
|
-
useKeyframeUpdateCallback,
|
|
1843
|
-
useLiveAction,
|
|
1844
|
-
useLiveEventCallback,
|
|
1845
|
-
useReadyState,
|
|
1846
|
-
useRTCAction,
|
|
1847
|
-
useRTCEventCallback,
|
|
1848
|
-
useSelfInfo,
|
|
1849
|
-
useSnapshot,
|
|
1850
|
-
useUserList,
|
|
1851
|
-
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,
|
|
1852
2234
|
};
|
|
1853
2235
|
}
|
|
1854
2236
|
|