@realsee/live 0.4.0-beta.7 → 0.5.0-alpha.10
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 +81 -38
- package/dist/live/createLive.d.ts +5 -3
- package/dist/live/createLiveReact.d.ts +49 -3
- package/dist/live/live.d.ts +170 -0
- package/dist/realsee-live.cjs.development.js +1654 -1445
- 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 +1656 -1447
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +51517 -51302
- 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/dist/typings/live/EventType.d.ts +17 -33
- package/dist/typings/live/LiveConnectOptions.d.ts +7 -0
- package/dist/typings/live/LiveErrorType.d.ts +9 -0
- package/dist/typings/live/LiveOptions.d.ts +5 -12
- package/dist/typings/live/LiveState.d.ts +15 -0
- package/dist/typings/live/index.d.ts +2 -1
- package/dist/typings/react/index.d.ts +0 -1
- package/dist/utils/RobustWebSocket.d.ts +153 -0
- package/dist/utils/logger.d.ts +16 -0
- package/docs/assets/search.js +1 -1
- package/docs/classes/VRWebViewRTC.html +5 -5
- package/docs/enums/LiveState.html +7 -0
- package/docs/index.html +1 -1
- package/docs/interfaces/LiveOptions.html +16 -19
- package/docs/modules.html +40 -40
- package/package.json +2 -2
- package/dist/typings/live/Live.d.ts +0 -128
- package/dist/typings/react/LiveReact.d.ts +0 -164
- package/docs/interfaces/Live.html +0 -116
- package/docs/interfaces/LiveReact.html +0 -52
package/dist/realsee-live.esm.js
CHANGED
|
@@ -1,99 +1,9 @@
|
|
|
1
1
|
import JSBridge from '@realsee/jsbridge-x';
|
|
2
|
-
import { DefaultModality, ConsoleLogger, LogLevel, DefaultDeviceController, MeetingSessionStatusCode, MeetingSessionConfiguration, DefaultMeetingSession } from 'amazon-chime-sdk-js';
|
|
3
2
|
import TRTC from 'trtc-js-sdk';
|
|
4
|
-
import
|
|
3
|
+
import { DefaultModality, ConsoleLogger, LogLevel as LogLevel$1, DefaultDeviceController, MeetingSessionConfiguration, DefaultMeetingSession, MeetingSessionStatusCode } from 'amazon-chime-sdk-js';
|
|
4
|
+
import React, { createContext } from 'react';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
Copyright (c) Microsoft Corporation.
|
|
8
|
-
|
|
9
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
-
purpose with or without fee is hereby granted.
|
|
11
|
-
|
|
12
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
-
***************************************************************************** */
|
|
20
|
-
/* global Reflect, Promise */
|
|
21
|
-
|
|
22
|
-
var extendStatics = function(d, b) {
|
|
23
|
-
extendStatics = Object.setPrototypeOf ||
|
|
24
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
25
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
26
|
-
return extendStatics(d, b);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
function __extends(d, b) {
|
|
30
|
-
if (typeof b !== "function" && b !== null)
|
|
31
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
32
|
-
extendStatics(d, b);
|
|
33
|
-
function __() { this.constructor = d; }
|
|
34
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var __assign = function() {
|
|
38
|
-
__assign = Object.assign || function __assign(t) {
|
|
39
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
40
|
-
s = arguments[i];
|
|
41
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
42
|
-
}
|
|
43
|
-
return t;
|
|
44
|
-
};
|
|
45
|
-
return __assign.apply(this, arguments);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
49
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
50
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
51
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
52
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
53
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
54
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function __generator(thisArg, body) {
|
|
59
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
60
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
61
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
62
|
-
function step(op) {
|
|
63
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
64
|
-
while (_) try {
|
|
65
|
-
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;
|
|
66
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
67
|
-
switch (op[0]) {
|
|
68
|
-
case 0: case 1: t = op; break;
|
|
69
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
70
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
71
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
72
|
-
default:
|
|
73
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
74
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
75
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
76
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
77
|
-
if (t[2]) _.ops.pop();
|
|
78
|
-
_.trys.pop(); continue;
|
|
79
|
-
}
|
|
80
|
-
op = body.call(thisArg, _);
|
|
81
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
82
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function __spreadArray(to, from, pack) {
|
|
87
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
88
|
-
if (ar || !(i in from)) {
|
|
89
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
90
|
-
ar[i] = from[i];
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
var EVENT_SYMBOL = Symbol('$$REALSEE_LIVE_EVENT$$');
|
|
6
|
+
const EVENT_SYMBOL = Symbol('$$REALSEE_LIVE_EVENT$$');
|
|
97
7
|
function __generateEventIfNotExisted(instance) {
|
|
98
8
|
if (!instance[EVENT_SYMBOL]) {
|
|
99
9
|
instance[EVENT_SYMBOL] = {};
|
|
@@ -116,17 +26,15 @@ function __removeEventIfNotExisted(instance) {
|
|
|
116
26
|
* }>()
|
|
117
27
|
* ```
|
|
118
28
|
*/
|
|
119
|
-
|
|
120
|
-
function Subscribe() {
|
|
121
|
-
}
|
|
29
|
+
class Subscribe {
|
|
122
30
|
/**
|
|
123
31
|
* 判断是否注册了事件
|
|
124
32
|
* @param name 事件类型
|
|
125
33
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
34
|
+
hasListener(name) {
|
|
35
|
+
const events = __generateEventIfNotExisted(this);
|
|
128
36
|
return events && events[name] && events[name].length > 0;
|
|
129
|
-
}
|
|
37
|
+
}
|
|
130
38
|
/**
|
|
131
39
|
* 注册事件
|
|
132
40
|
* @param name 事件类型
|
|
@@ -136,14 +44,13 @@ var Subscribe = /** @class */ (function () {
|
|
|
136
44
|
* @template K 预设的监听事件名称
|
|
137
45
|
* @template C 回调函数函数上下文
|
|
138
46
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
var events = __generateEventIfNotExisted(this);
|
|
47
|
+
on(name, callback, once) {
|
|
48
|
+
const events = __generateEventIfNotExisted(this);
|
|
142
49
|
if (!events[name])
|
|
143
50
|
events[name] = [];
|
|
144
51
|
events[name].push([callback, once || false]);
|
|
145
|
-
return
|
|
146
|
-
}
|
|
52
|
+
return () => this.off(name, callback);
|
|
53
|
+
}
|
|
147
54
|
/**
|
|
148
55
|
* 注册事件(是否只执行一次)
|
|
149
56
|
* @param name 事件类型
|
|
@@ -152,9 +59,9 @@ var Subscribe = /** @class */ (function () {
|
|
|
152
59
|
* @template K 预设的监听事件名称
|
|
153
60
|
* @template C 回调函数函数上下文
|
|
154
61
|
*/
|
|
155
|
-
|
|
62
|
+
once(name, callback) {
|
|
156
63
|
return this.on(name, callback, true);
|
|
157
|
-
}
|
|
64
|
+
}
|
|
158
65
|
/**
|
|
159
66
|
* 解除事件
|
|
160
67
|
*
|
|
@@ -164,19 +71,19 @@ var Subscribe = /** @class */ (function () {
|
|
|
164
71
|
* @param callback 事件回调函数
|
|
165
72
|
* @template K 预设的监听事件名称
|
|
166
73
|
*/
|
|
167
|
-
|
|
74
|
+
off(name, callback) {
|
|
168
75
|
if (name === undefined) {
|
|
169
76
|
__removeEventIfNotExisted(this);
|
|
170
77
|
return;
|
|
171
78
|
}
|
|
172
|
-
|
|
79
|
+
const events = __generateEventIfNotExisted(this);
|
|
173
80
|
if (!events[name])
|
|
174
81
|
events[name] = [];
|
|
175
82
|
if (callback === undefined) {
|
|
176
83
|
events[name].length = 0;
|
|
177
84
|
return;
|
|
178
85
|
}
|
|
179
|
-
|
|
86
|
+
let index = 0;
|
|
180
87
|
for (; index < events[name].length; index++) {
|
|
181
88
|
if (events[name][index][0] === callback)
|
|
182
89
|
break;
|
|
@@ -184,7 +91,7 @@ var Subscribe = /** @class */ (function () {
|
|
|
184
91
|
if (index < events[name].length) {
|
|
185
92
|
events[name].splice(index, 1);
|
|
186
93
|
}
|
|
187
|
-
}
|
|
94
|
+
}
|
|
188
95
|
/**
|
|
189
96
|
* 触发事件
|
|
190
97
|
* @param name 事件类型
|
|
@@ -192,38 +99,52 @@ var Subscribe = /** @class */ (function () {
|
|
|
192
99
|
* @returns canceled 是否被触发取消
|
|
193
100
|
* @template K 预设的监听事件名称
|
|
194
101
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
var event = events[name] || [];
|
|
203
|
-
for (var _a = 0, _b = event.slice(); _a < _b.length; _a++) {
|
|
204
|
-
var one = _b[_a];
|
|
205
|
-
var callback = one[0], _c = one[1], once = _c === void 0 ? false : _c;
|
|
206
|
-
var result = callback.apply(void 0, data);
|
|
102
|
+
emit(name, ...data) {
|
|
103
|
+
let canceled = false;
|
|
104
|
+
const events = __generateEventIfNotExisted(this);
|
|
105
|
+
const event = events[name] || [];
|
|
106
|
+
for (let one of event.slice()) {
|
|
107
|
+
const [callback, once = false] = one;
|
|
108
|
+
const result = callback(...data);
|
|
207
109
|
if (once)
|
|
208
110
|
this.off(name, callback);
|
|
209
111
|
if (result === false)
|
|
210
112
|
canceled = true;
|
|
211
113
|
}
|
|
212
114
|
return canceled;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
}());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
216
117
|
|
|
217
118
|
/**
|
|
218
119
|
* rtc 基础抽象类
|
|
219
120
|
*/
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
121
|
+
class CoreRTC extends Subscribe {
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/******************************************************************************
|
|
125
|
+
Copyright (c) Microsoft Corporation.
|
|
126
|
+
|
|
127
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
128
|
+
purpose with or without fee is hereby granted.
|
|
129
|
+
|
|
130
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
131
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
132
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
133
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
134
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
135
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
136
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
137
|
+
***************************************************************************** */
|
|
138
|
+
|
|
139
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
140
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
141
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
142
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
143
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
144
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
145
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
146
|
+
});
|
|
147
|
+
}
|
|
227
148
|
|
|
228
149
|
/**
|
|
229
150
|
* rtc 类型
|
|
@@ -263,231 +184,199 @@ function uuid() {
|
|
|
263
184
|
S4()).toLowerCase();
|
|
264
185
|
}
|
|
265
186
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
_this._getVoiceSign = function () {
|
|
187
|
+
class BrowserRTC extends CoreRTC {
|
|
188
|
+
constructor(options) {
|
|
189
|
+
super();
|
|
190
|
+
this.type = RTCType.RealseeBrowserRTC;
|
|
191
|
+
this.joined = false;
|
|
192
|
+
this.micro = false;
|
|
193
|
+
this.voiceId = '';
|
|
194
|
+
this._getVoiceSign = () => {
|
|
275
195
|
throw new Error('方法 getVoiceSign 未实现');
|
|
276
196
|
};
|
|
277
|
-
|
|
278
|
-
|
|
197
|
+
this.$dom = document.createElement('div');
|
|
198
|
+
this._trtc = {
|
|
279
199
|
client: null,
|
|
280
200
|
stream: null,
|
|
281
201
|
};
|
|
282
|
-
|
|
283
|
-
var createClientOptions, result;
|
|
284
|
-
var _this = this;
|
|
202
|
+
this.join = (options) => __awaiter(this, void 0, void 0, function* () {
|
|
285
203
|
var _a;
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
})];
|
|
321
|
-
case 3:
|
|
322
|
-
// 5. 初始化本地流
|
|
323
|
-
result = _b.sent();
|
|
324
|
-
return [4 /*yield*/, new Promise(function (resolve) {
|
|
325
|
-
var _a;
|
|
326
|
-
(_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); });
|
|
327
|
-
})];
|
|
328
|
-
case 4:
|
|
329
|
-
// 6. 发布本地流
|
|
330
|
-
result = _b.sent();
|
|
331
|
-
this.joined = result;
|
|
332
|
-
if (this.joined)
|
|
333
|
-
this.emit('joined');
|
|
334
|
-
return [2 /*return*/, result];
|
|
335
|
-
}
|
|
204
|
+
this.emit('joinWillStart');
|
|
205
|
+
const createClientOptions = yield this._getVoiceSign({
|
|
206
|
+
voiceId: options.voiceId,
|
|
207
|
+
roomId: options.roomId,
|
|
208
|
+
userId: options.userId,
|
|
209
|
+
});
|
|
210
|
+
// 1. 创建client
|
|
211
|
+
this._trtc.client = TRTC.createClient(Object.assign({ mode: 'rtc' }, createClientOptions));
|
|
212
|
+
(_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.enableAudioVolumeEvaluation();
|
|
213
|
+
// 2. 订阅事件
|
|
214
|
+
this._registerRtcEvent();
|
|
215
|
+
// 3. 加入语音房间
|
|
216
|
+
let result = yield new Promise((resolve) => {
|
|
217
|
+
var _a;
|
|
218
|
+
(_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.join({ roomId: Number(options.voiceId) }).then(() => resolve(true)).catch(() => resolve(false));
|
|
219
|
+
});
|
|
220
|
+
this.joined = result;
|
|
221
|
+
if (!result)
|
|
222
|
+
return false; // 进房失败
|
|
223
|
+
// 4. 创建本地流
|
|
224
|
+
this._trtc.stream = TRTC.createStream({
|
|
225
|
+
userId: createClientOptions.userId,
|
|
226
|
+
audio: true,
|
|
227
|
+
video: false,
|
|
228
|
+
});
|
|
229
|
+
// 5. 初始化本地流
|
|
230
|
+
result = yield new Promise((resolve) => {
|
|
231
|
+
var _a;
|
|
232
|
+
(_a = this._trtc.stream) === null || _a === void 0 ? void 0 : _a.initialize().then(() => resolve(true)).catch(() => resolve(false));
|
|
233
|
+
});
|
|
234
|
+
// 6. 发布本地流
|
|
235
|
+
result = yield new Promise((resolve) => {
|
|
236
|
+
var _a;
|
|
237
|
+
(_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.publish(this._trtc.stream).then(() => resolve(true)).catch(() => resolve(false));
|
|
336
238
|
});
|
|
337
|
-
|
|
338
|
-
|
|
239
|
+
this.joined = result;
|
|
240
|
+
if (this.joined)
|
|
241
|
+
this.emit('joined');
|
|
242
|
+
return result;
|
|
243
|
+
});
|
|
244
|
+
this._handleStreamAdded = (event) => {
|
|
339
245
|
var _a;
|
|
340
|
-
|
|
246
|
+
const remoteStream = event.stream;
|
|
341
247
|
console.log('远端流增加: ' + remoteStream.getId());
|
|
342
248
|
//订阅远端流
|
|
343
|
-
(_a =
|
|
249
|
+
(_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.subscribe(remoteStream);
|
|
344
250
|
};
|
|
345
|
-
|
|
346
|
-
|
|
251
|
+
this._handleStreamSubscribed = (event) => {
|
|
252
|
+
const remoteStream = event.stream;
|
|
347
253
|
console.log('远端流订阅成功:' + remoteStream.getId());
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
254
|
+
const playId = remoteStream.getId();
|
|
255
|
+
const domId = `rs-rtc-remote_stream-${playId}`;
|
|
256
|
+
const dom = document.createElement('div');
|
|
351
257
|
dom.id = domId;
|
|
352
|
-
|
|
258
|
+
this.$dom.appendChild(dom);
|
|
353
259
|
// 播放远端流
|
|
354
260
|
remoteStream.play(domId);
|
|
355
261
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
return _this;
|
|
262
|
+
this._getVoiceSign = options.getVoiceSign;
|
|
263
|
+
this._initParentDom();
|
|
359
264
|
}
|
|
360
|
-
|
|
361
|
-
this.$dom.id =
|
|
265
|
+
_initParentDom() {
|
|
266
|
+
this.$dom.id = `rs-rtc-${uuid()}`;
|
|
362
267
|
this.$dom.style.display = 'none';
|
|
363
268
|
document.body.appendChild(this.$dom);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
|
|
368
|
-
var _this = this;
|
|
269
|
+
}
|
|
270
|
+
quit() {
|
|
271
|
+
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
369
272
|
var _a, _b;
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
(_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); });
|
|
384
|
-
return [2 /*return*/];
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
}); });
|
|
388
|
-
};
|
|
389
|
-
BrowserRTC.prototype.detectMicro = function () {
|
|
390
|
-
return new Promise(function (resolve) {
|
|
391
|
-
var rule = { audio: true, video: false };
|
|
273
|
+
this.joined = false;
|
|
274
|
+
if (this._trtc.stream) {
|
|
275
|
+
yield ((_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.unpublish(this._trtc.stream));
|
|
276
|
+
this._trtc.stream.stop();
|
|
277
|
+
this._trtc.stream.close();
|
|
278
|
+
this._trtc.stream = null;
|
|
279
|
+
}
|
|
280
|
+
(_b = this._trtc.client) === null || _b === void 0 ? void 0 : _b.leave().then(() => (this._trtc.client = null)).then(() => resolve(true)).catch(() => resolve(false));
|
|
281
|
+
}));
|
|
282
|
+
}
|
|
283
|
+
detectMicro() {
|
|
284
|
+
return new Promise((resolve) => {
|
|
285
|
+
const rule = { audio: true, video: false };
|
|
392
286
|
try {
|
|
393
287
|
navigator.mediaDevices
|
|
394
288
|
.getUserMedia(rule)
|
|
395
|
-
.then(
|
|
396
|
-
.catch(
|
|
289
|
+
.then(() => resolve(true))
|
|
290
|
+
.catch(() => resolve(false));
|
|
397
291
|
}
|
|
398
292
|
catch (e) {
|
|
399
293
|
console.error(e);
|
|
400
294
|
resolve(false);
|
|
401
295
|
}
|
|
402
296
|
});
|
|
403
|
-
}
|
|
404
|
-
|
|
297
|
+
}
|
|
298
|
+
toggleMicro(flag) {
|
|
405
299
|
var _a, _b, _c, _d;
|
|
406
300
|
return Promise.resolve((flag
|
|
407
301
|
? (_b = (_a = this._trtc) === null || _a === void 0 ? void 0 : _a.stream) === null || _b === void 0 ? void 0 : _b.unmuteAudio()
|
|
408
302
|
: (_d = (_c = this._trtc) === null || _c === void 0 ? void 0 : _c.stream) === null || _d === void 0 ? void 0 : _d.muteAudio()) || false);
|
|
409
|
-
}
|
|
410
|
-
|
|
303
|
+
}
|
|
304
|
+
shock() {
|
|
411
305
|
throw new Error('Method not implemented.');
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
var _this = this;
|
|
306
|
+
}
|
|
307
|
+
_registerRtcEvent() {
|
|
415
308
|
var _a, _b, _c, _d;
|
|
416
309
|
(_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.on('stream-added', this._handleStreamAdded);
|
|
417
310
|
(_b = this._trtc.client) === null || _b === void 0 ? void 0 : _b.on('stream-subscribed', this._handleStreamSubscribed);
|
|
418
|
-
(_c = this._trtc.client) === null || _c === void 0 ? void 0 : _c.on('audio-volume',
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
};
|
|
425
|
-
return BrowserRTC;
|
|
426
|
-
}(CoreRTC));
|
|
311
|
+
(_c = this._trtc.client) === null || _c === void 0 ? void 0 : _c.on('audio-volume', (event) => this.emit('userVolumes', [
|
|
312
|
+
{ userId: event.userId, audioVolume: event.audioVolume },
|
|
313
|
+
]));
|
|
314
|
+
(_d = this._trtc.client) === null || _d === void 0 ? void 0 : _d.on('error', (event) => this.emit('error', event));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
427
317
|
|
|
428
318
|
/**
|
|
429
319
|
* amazon-chime-sdk-js 适配的rtc实现
|
|
430
320
|
*/
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
_this._getVoiceSign = function () {
|
|
321
|
+
class BrowserRTC4Chime extends CoreRTC {
|
|
322
|
+
constructor(options) {
|
|
323
|
+
super();
|
|
324
|
+
this.type = RTCType.RealseeBrowserChimeRTC;
|
|
325
|
+
this.joined = false;
|
|
326
|
+
this.micro = false;
|
|
327
|
+
this.voiceId = '';
|
|
328
|
+
this.userId = '';
|
|
329
|
+
this.deviceChangeObserver = {};
|
|
330
|
+
this.audioVideoObserver = {};
|
|
331
|
+
this._getVoiceSign = () => {
|
|
443
332
|
throw new Error('方法 getVoiceSign 未实现');
|
|
444
333
|
};
|
|
445
|
-
|
|
446
|
-
|
|
334
|
+
this.$dom = document.createElement('div');
|
|
335
|
+
this.$audio = document.createElement('audio');
|
|
447
336
|
/**
|
|
448
337
|
* 对audio标签初始化
|
|
449
338
|
*/
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
document.body.appendChild(
|
|
339
|
+
this._initDom = () => {
|
|
340
|
+
this.$audio.id = `rs-rtc-${uuid()}`;
|
|
341
|
+
this.$dom.id = `rs-rtc-${uuid()}`;
|
|
342
|
+
this.$dom.appendChild(this.$audio);
|
|
343
|
+
document.body.appendChild(this.$dom);
|
|
455
344
|
};
|
|
456
345
|
/**
|
|
457
346
|
* 初始化事件监听器
|
|
458
347
|
*/
|
|
459
|
-
|
|
348
|
+
this.initObservers = () => {
|
|
460
349
|
// 输入输出设备变化的监听器
|
|
461
|
-
|
|
462
|
-
audioInputsChanged:
|
|
350
|
+
this.deviceChangeObserver = {
|
|
351
|
+
audioInputsChanged: (freshAudioInputDeviceList) => {
|
|
463
352
|
// An array of MediaDeviceInfo objects
|
|
464
|
-
freshAudioInputDeviceList === null || freshAudioInputDeviceList === void 0 ? void 0 : freshAudioInputDeviceList.forEach(
|
|
465
|
-
|
|
353
|
+
freshAudioInputDeviceList === null || freshAudioInputDeviceList === void 0 ? void 0 : freshAudioInputDeviceList.forEach((mediaDeviceInfo) => {
|
|
354
|
+
this.logger.info(`Device ID: ${mediaDeviceInfo.deviceId} Microphone: ${mediaDeviceInfo.label}`);
|
|
466
355
|
});
|
|
467
356
|
},
|
|
468
|
-
audioOutputsChanged:
|
|
469
|
-
|
|
357
|
+
audioOutputsChanged: (freshAudioOutputDeviceList) => {
|
|
358
|
+
this.logger.info(`Audio outputs updated: ${freshAudioOutputDeviceList}`);
|
|
470
359
|
},
|
|
471
|
-
videoInputsChanged:
|
|
472
|
-
|
|
360
|
+
videoInputsChanged: (freshVideoInputDeviceList) => {
|
|
361
|
+
this.logger.info(`Video inputs updated: ${freshVideoInputDeviceList}`);
|
|
473
362
|
},
|
|
474
|
-
audioInputMuteStateChanged:
|
|
475
|
-
|
|
363
|
+
audioInputMuteStateChanged: (device, muted) => {
|
|
364
|
+
this.logger.info(`Device ${device.toString()} ${muted ? 'is muted in hardware' : 'is not muted'}`);
|
|
476
365
|
},
|
|
477
366
|
};
|
|
478
367
|
// 流变化监听器
|
|
479
|
-
|
|
480
|
-
audioVideoDidStart:
|
|
481
|
-
|
|
368
|
+
this.audioVideoObserver = {
|
|
369
|
+
audioVideoDidStart: () => {
|
|
370
|
+
this.logger.info('Started');
|
|
482
371
|
},
|
|
483
|
-
audioVideoDidStop:
|
|
372
|
+
audioVideoDidStop: (sessionStatus) => {
|
|
484
373
|
// See the "Stopping a session" section for details.
|
|
485
|
-
|
|
374
|
+
this.logger.info(`Stopped with a session status code: ${sessionStatus.statusCode()}`);
|
|
486
375
|
},
|
|
487
|
-
audioVideoDidStartConnecting:
|
|
376
|
+
audioVideoDidStartConnecting: (reconnecting) => {
|
|
488
377
|
if (reconnecting) {
|
|
489
378
|
// e.g. the WiFi connection is dropped.
|
|
490
|
-
|
|
379
|
+
this.logger.info('Attempting to reconnect');
|
|
491
380
|
}
|
|
492
381
|
},
|
|
493
382
|
};
|
|
@@ -495,15 +384,15 @@ var BrowserRTC4Chime = /** @class */ (function (_super) {
|
|
|
495
384
|
/**
|
|
496
385
|
* 注册rtc事件
|
|
497
386
|
*/
|
|
498
|
-
|
|
387
|
+
this._registerRtcEvent = () => {
|
|
499
388
|
var _a, _b, _c, _d, _e, _f;
|
|
500
|
-
|
|
389
|
+
const 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) || '';
|
|
501
390
|
if (presentAttendeeId) {
|
|
502
391
|
// 处理音量变化
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
392
|
+
const roster = new Map();
|
|
393
|
+
const getUserVolumes = () => {
|
|
394
|
+
const result = [];
|
|
395
|
+
roster.forEach((v, k) => {
|
|
507
396
|
result.push({
|
|
508
397
|
userId: v.userId,
|
|
509
398
|
volume: v.muted || v.signalStrength === 0 || !Boolean(v.volume)
|
|
@@ -513,208 +402,180 @@ var BrowserRTC4Chime = /** @class */ (function (_super) {
|
|
|
513
402
|
});
|
|
514
403
|
return result;
|
|
515
404
|
};
|
|
516
|
-
(_d =
|
|
405
|
+
(_d = this.meetingSession) === null || _d === void 0 ? void 0 : _d.audioVideo.realtimeSubscribeToAttendeeIdPresence((presentAttendeeId, present, externalUserId) => {
|
|
517
406
|
var _a;
|
|
518
407
|
if (!present) {
|
|
519
|
-
|
|
520
|
-
|
|
408
|
+
roster.delete(presentAttendeeId);
|
|
409
|
+
this.emit('userVolumes', getUserVolumes());
|
|
521
410
|
return;
|
|
522
411
|
}
|
|
523
|
-
(_a =
|
|
524
|
-
|
|
412
|
+
(_a = this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.realtimeSubscribeToVolumeIndicator(presentAttendeeId, (attendeeId, volume, muted, signalStrength) => {
|
|
413
|
+
const baseAttendeeId = new DefaultModality(attendeeId).base();
|
|
525
414
|
if (baseAttendeeId !== attendeeId) {
|
|
526
415
|
// Optional: Do not include the content attendee (attendee-id#content) in the roster.
|
|
527
416
|
// See the "Screen and content share" section for details.
|
|
528
417
|
return;
|
|
529
418
|
}
|
|
530
|
-
|
|
419
|
+
roster.set(attendeeId, {
|
|
531
420
|
userId: externalUserId || attendeeId,
|
|
532
|
-
volume
|
|
533
|
-
muted
|
|
534
|
-
signalStrength
|
|
421
|
+
volume,
|
|
422
|
+
muted,
|
|
423
|
+
signalStrength,
|
|
535
424
|
});
|
|
536
|
-
|
|
425
|
+
this.emit('userVolumes', getUserVolumes());
|
|
537
426
|
});
|
|
538
427
|
});
|
|
539
428
|
// 弱网
|
|
540
|
-
(_e =
|
|
541
|
-
|
|
429
|
+
(_e = this.meetingSession) === null || _e === void 0 ? void 0 : _e.audioVideo.realtimeSubscribeToVolumeIndicator(presentAttendeeId, (attendeeId, volume, muted, signalStrength) => {
|
|
430
|
+
const baseAttendeeId = new DefaultModality(attendeeId).base();
|
|
542
431
|
if (baseAttendeeId === attendeeId) {
|
|
543
432
|
if (signalStrength !== null && signalStrength !== 1) {
|
|
544
|
-
|
|
433
|
+
this.emit('weakNetwork');
|
|
545
434
|
}
|
|
546
435
|
}
|
|
547
436
|
});
|
|
548
437
|
// 报错
|
|
549
|
-
(_f =
|
|
438
|
+
(_f = this.meetingSession) === null || _f === void 0 ? void 0 : _f.audioVideo.realtimeSubscribeToFatalError((error) => this.emit('error', error));
|
|
550
439
|
}
|
|
551
440
|
};
|
|
552
441
|
// 挂载签名钩子
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
return _this;
|
|
442
|
+
this._getVoiceSign = options.getVoiceSign;
|
|
443
|
+
this._initDom();
|
|
444
|
+
this.logger = new ConsoleLogger('WebRTCLogger', options.logLevel || LogLevel$1.OFF);
|
|
445
|
+
this.deviceController = new DefaultDeviceController(this.logger);
|
|
446
|
+
this.initObservers();
|
|
559
447
|
}
|
|
560
448
|
/**
|
|
561
449
|
* 加入语音会议
|
|
562
450
|
* @param options
|
|
563
451
|
* @returns
|
|
564
452
|
*/
|
|
565
|
-
|
|
566
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
return [4 /*yield*/, this.meetingSession.audioVideo.chooseVideoInputDevice(null)];
|
|
624
|
-
case 4:
|
|
625
|
-
_d.sent();
|
|
626
|
-
return [4 /*yield*/, this.meetingSession.audioVideo.chooseAudioInputDevice(((_c = this.audioInput) === null || _c === void 0 ? void 0 : _c.deviceId) || 'default')];
|
|
627
|
-
case 5:
|
|
628
|
-
_d.sent();
|
|
629
|
-
this.meetingSession.audioVideo.start();
|
|
630
|
-
return [3 /*break*/, 7];
|
|
631
|
-
case 6:
|
|
632
|
-
e_1 = _d.sent();
|
|
633
|
-
this.emit('error', e_1);
|
|
634
|
-
this.logger.error(e_1.message);
|
|
635
|
-
success(false);
|
|
636
|
-
return [3 /*break*/, 7];
|
|
637
|
-
case 7: return [2 /*return*/];
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
}); })];
|
|
641
|
-
});
|
|
453
|
+
join(options) {
|
|
454
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
455
|
+
return new Promise((success, fail) => __awaiter(this, void 0, void 0, function* () {
|
|
456
|
+
var _a;
|
|
457
|
+
this.emit('joinWillStart');
|
|
458
|
+
try {
|
|
459
|
+
// 取签名
|
|
460
|
+
const { sdkAppId, userId, roomId, userSig } = yield this._getVoiceSign(Object.assign(Object.assign({}, options), { roomId: options.roomId || 0 }));
|
|
461
|
+
this.userId = userId;
|
|
462
|
+
const { attendence, vendor_wrapper, } = JSON.parse(decodeURIComponent(userSig));
|
|
463
|
+
// 初始化配置
|
|
464
|
+
const configuration = new MeetingSessionConfiguration({
|
|
465
|
+
Meeting: vendor_wrapper,
|
|
466
|
+
}, {
|
|
467
|
+
Attendee: {
|
|
468
|
+
ExternalUserId: attendence.external_user_id,
|
|
469
|
+
AttendeeId: attendence.attendee_id,
|
|
470
|
+
JoinToken: attendence.join_token,
|
|
471
|
+
},
|
|
472
|
+
});
|
|
473
|
+
// 初始化会议会话
|
|
474
|
+
this.meetingSession = new DefaultMeetingSession(configuration, this.logger, this.deviceController);
|
|
475
|
+
// 注册事件
|
|
476
|
+
this._registerRtcEvent();
|
|
477
|
+
// 绑定监听器
|
|
478
|
+
this.meetingSession.audioVideo.addDeviceChangeObserver(this.deviceChangeObserver);
|
|
479
|
+
this.meetingSession.audioVideo.addObserver(this.audioVideoObserver);
|
|
480
|
+
// 绑定播放器
|
|
481
|
+
this.meetingSession.audioVideo.bindAudioElement(this.$audio);
|
|
482
|
+
const observer = {
|
|
483
|
+
audioVideoDidStart: () => {
|
|
484
|
+
var _a;
|
|
485
|
+
(_a = this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.realtimeMuteLocalAudio();
|
|
486
|
+
this.joined = true;
|
|
487
|
+
this.emit('joined');
|
|
488
|
+
success(true);
|
|
489
|
+
},
|
|
490
|
+
audioVideoDidStop: () => {
|
|
491
|
+
this.joined = false;
|
|
492
|
+
success(false);
|
|
493
|
+
},
|
|
494
|
+
};
|
|
495
|
+
this.meetingSession.audioVideo.addObserver(observer);
|
|
496
|
+
// 选择语音输入设备
|
|
497
|
+
const audioInputDevices = yield this.deviceController.listAudioInputDevices(true);
|
|
498
|
+
const defaultAudioInput = audioInputDevices.find((device) => device.deviceId === 'default');
|
|
499
|
+
const otherAudioInput = audioInputDevices.find((device) => device.deviceId !== '');
|
|
500
|
+
this.audioInput = defaultAudioInput || otherAudioInput;
|
|
501
|
+
yield this.meetingSession.audioVideo.chooseVideoInputDevice(null);
|
|
502
|
+
yield this.meetingSession.audioVideo.chooseAudioInputDevice(((_a = this.audioInput) === null || _a === void 0 ? void 0 : _a.deviceId) || 'default');
|
|
503
|
+
this.meetingSession.audioVideo.start();
|
|
504
|
+
}
|
|
505
|
+
catch (e) {
|
|
506
|
+
this.emit('error', e);
|
|
507
|
+
this.logger.error(e.message);
|
|
508
|
+
success(false);
|
|
509
|
+
}
|
|
510
|
+
}));
|
|
642
511
|
});
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
var _this = this;
|
|
512
|
+
}
|
|
513
|
+
quit() {
|
|
646
514
|
if (!this.joined)
|
|
647
515
|
return Promise.resolve(true);
|
|
648
|
-
return new Promise(
|
|
516
|
+
return new Promise((success, fail) => {
|
|
649
517
|
var _a, _b;
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
audioVideoDidStop:
|
|
653
|
-
|
|
518
|
+
this.joined = false;
|
|
519
|
+
const observer = {
|
|
520
|
+
audioVideoDidStop: (sessionStatus) => {
|
|
521
|
+
const sessionStatusCode = sessionStatus.statusCode();
|
|
654
522
|
if (sessionStatusCode === MeetingSessionStatusCode.Left) {
|
|
655
523
|
/*
|
|
656
524
|
- You called meetingSession.audioVideo.stop().
|
|
657
525
|
- When closing a browser window or page, Chime SDK attempts to leave the session.
|
|
658
526
|
*/
|
|
659
|
-
|
|
527
|
+
this.logger.info('You left the session');
|
|
660
528
|
success(true);
|
|
661
529
|
}
|
|
662
530
|
else {
|
|
663
|
-
|
|
531
|
+
this.logger.info(`Stopped with a session status code: ${sessionStatusCode}`);
|
|
664
532
|
success(true);
|
|
665
533
|
}
|
|
666
534
|
},
|
|
667
535
|
};
|
|
668
|
-
(_a =
|
|
669
|
-
(_b =
|
|
670
|
-
});
|
|
671
|
-
};
|
|
672
|
-
BrowserRTC4Chime.prototype.detectMicro = function () {
|
|
673
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
674
|
-
var _this = this;
|
|
675
|
-
return __generator(this, function (_a) {
|
|
676
|
-
return [2 /*return*/, new Promise(function (resolve) {
|
|
677
|
-
var rule = { audio: true, video: false };
|
|
678
|
-
try {
|
|
679
|
-
navigator.mediaDevices
|
|
680
|
-
.getUserMedia(rule)
|
|
681
|
-
.then(function () { return resolve(true); })
|
|
682
|
-
.catch(function () { return resolve(false); });
|
|
683
|
-
}
|
|
684
|
-
catch (e) {
|
|
685
|
-
_this.logger.error(e.message);
|
|
686
|
-
resolve(false);
|
|
687
|
-
}
|
|
688
|
-
})];
|
|
689
|
-
});
|
|
536
|
+
(_a = this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.addObserver(observer);
|
|
537
|
+
(_b = this.meetingSession) === null || _b === void 0 ? void 0 : _b.audioVideo.stop();
|
|
690
538
|
});
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
(_b = this.meetingSession) === null || _b === void 0 ? void 0 : _b.audioVideo.realtimeMuteLocalAudio();
|
|
702
|
-
}
|
|
703
|
-
muted = (_c = this.meetingSession) === null || _c === void 0 ? void 0 : _c.audioVideo.realtimeIsLocalAudioMuted();
|
|
704
|
-
if (muted !== undefined) {
|
|
705
|
-
return [2 /*return*/, flag !== muted];
|
|
539
|
+
}
|
|
540
|
+
detectMicro() {
|
|
541
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
542
|
+
return new Promise((resolve) => {
|
|
543
|
+
const rule = { audio: true, video: false };
|
|
544
|
+
try {
|
|
545
|
+
navigator.mediaDevices
|
|
546
|
+
.getUserMedia(rule)
|
|
547
|
+
.then(() => resolve(true))
|
|
548
|
+
.catch(() => resolve(false));
|
|
706
549
|
}
|
|
707
|
-
|
|
708
|
-
|
|
550
|
+
catch (e) {
|
|
551
|
+
this.logger.error(e.message);
|
|
552
|
+
resolve(false);
|
|
709
553
|
}
|
|
710
554
|
});
|
|
711
555
|
});
|
|
712
|
-
}
|
|
713
|
-
|
|
556
|
+
}
|
|
557
|
+
toggleMicro(flag) {
|
|
558
|
+
var _a, _b, _c;
|
|
559
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
560
|
+
if (flag) {
|
|
561
|
+
(_a = this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.realtimeUnmuteLocalAudio();
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
(_b = this.meetingSession) === null || _b === void 0 ? void 0 : _b.audioVideo.realtimeMuteLocalAudio();
|
|
565
|
+
}
|
|
566
|
+
const muted = (_c = this.meetingSession) === null || _c === void 0 ? void 0 : _c.audioVideo.realtimeIsLocalAudioMuted();
|
|
567
|
+
if (muted !== undefined) {
|
|
568
|
+
return flag !== muted;
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
shock() {
|
|
714
576
|
throw new Error('Method not implemented.');
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
}(CoreRTC));
|
|
577
|
+
}
|
|
578
|
+
}
|
|
718
579
|
|
|
719
580
|
/**
|
|
720
581
|
* rtc加入返回值code枚举
|
|
@@ -739,122 +600,98 @@ var RTCJoinedInfoCodeEnum;
|
|
|
739
600
|
RTCJoinedInfoCodeEnum[RTCJoinedInfoCodeEnum["NoMicroPermission"] = 3] = "NoMicroPermission";
|
|
740
601
|
})(RTCJoinedInfoCodeEnum || (RTCJoinedInfoCodeEnum = {}));
|
|
741
602
|
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
603
|
+
class VRWebViewRTC extends CoreRTC {
|
|
604
|
+
constructor({ jsBridge, getVoiceSign }) {
|
|
605
|
+
super();
|
|
606
|
+
this.type = RTCType.RealseeVRWebViewRTC;
|
|
607
|
+
this.joined = false;
|
|
608
|
+
this.micro = false;
|
|
609
|
+
this.voiceId = '';
|
|
610
|
+
this.options = { jsBridge, getVoiceSign };
|
|
611
|
+
// TO-DO: 在微信小程序下有个音量上报的BUG会导致消息体过大从而jsbridge异常断开
|
|
612
|
+
if (this.jsBridge.webViewType !== 'WxMiniProgramWebView') {
|
|
613
|
+
this.jsBridge.callAndListen('live/userVolumes', (userVolumes) => {
|
|
614
|
+
this.emit('userVolumes', userVolumes);
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
this.jsBridge.callAndListen('live/weakNetwork', (weakNetwork) => {
|
|
756
618
|
if (weakNetwork)
|
|
757
|
-
|
|
619
|
+
this.emit('weakNetwork');
|
|
758
620
|
});
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
switch (_c.label) {
|
|
773
|
-
case 0:
|
|
774
|
-
this.emit('joinWillStart');
|
|
775
|
-
return [4 /*yield*/, this.options.getVoiceSign(options)];
|
|
776
|
-
case 1:
|
|
777
|
-
_a = _c.sent(), sdkAppId = _a.sdkAppId, userId = _a.userId, userSig = _a.userSig;
|
|
778
|
-
this.type = options.type;
|
|
779
|
-
return [4 /*yield*/, this.jsBridge.callAndBackfeed("live/join?sdkAppID=".concat(sdkAppId, "&userID=").concat(userId, "&roomID=").concat(Number(options.voiceId), "&userSig=").concat(userSig))];
|
|
780
|
-
case 2:
|
|
781
|
-
_b = _c.sent(), res = _b[0], error = _b[1];
|
|
782
|
-
if (!res) {
|
|
783
|
-
this.emit('error', error ? error : new Error('加入房间失败:未知异常。'));
|
|
784
|
-
this.joined = false;
|
|
785
|
-
}
|
|
786
|
-
else {
|
|
787
|
-
if (res.code === RTCJoinedInfoCodeEnum.Success) {
|
|
788
|
-
this.emit('joined');
|
|
789
|
-
this.joined = true;
|
|
790
|
-
}
|
|
791
|
-
else {
|
|
792
|
-
this.emit('error', res);
|
|
793
|
-
this.joined = false;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
return [2 /*return*/, this.joined];
|
|
621
|
+
}
|
|
622
|
+
get jsBridge() {
|
|
623
|
+
return this.options.jsBridge;
|
|
624
|
+
}
|
|
625
|
+
join(options) {
|
|
626
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
627
|
+
try {
|
|
628
|
+
this.emit('joinWillStart');
|
|
629
|
+
const { sdkAppId, userId, userSig } = yield this.options.getVoiceSign(options);
|
|
630
|
+
if (!(Boolean(sdkAppId) && Boolean(userId) && Boolean(userSig))) {
|
|
631
|
+
this.emit('error', new Error('加入房间失败:rtc 签名请求异常'));
|
|
632
|
+
this.joined = false;
|
|
633
|
+
return this.joined;
|
|
797
634
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
}
|
|
635
|
+
this.type = options.type;
|
|
636
|
+
const [res, error] = yield this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${sdkAppId}&userID=${userId}&roomID=${Number(options.voiceId)}&userSig=${userSig}`);
|
|
637
|
+
if (!res) {
|
|
638
|
+
this.emit('error', error ? error : new Error('加入房间失败:未知异常。'));
|
|
639
|
+
this.joined = false;
|
|
640
|
+
}
|
|
641
|
+
else {
|
|
642
|
+
if (res.code === RTCJoinedInfoCodeEnum.Success) {
|
|
643
|
+
this.emit('joined');
|
|
644
|
+
this.joined = true;
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
this.emit('error', res);
|
|
812
648
|
this.joined = false;
|
|
813
|
-
|
|
649
|
+
}
|
|
814
650
|
}
|
|
815
|
-
|
|
651
|
+
return this.joined;
|
|
652
|
+
}
|
|
653
|
+
catch (e) {
|
|
654
|
+
this.emit('error', new Error('加入房间失败:' + e.message));
|
|
655
|
+
this.joined = false;
|
|
656
|
+
return this.joined;
|
|
657
|
+
}
|
|
816
658
|
});
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
if (res === null) {
|
|
827
|
-
this.emit('error', error ? error : new Error('麦克风监测异常!'));
|
|
828
|
-
return [2 /*return*/, false];
|
|
829
|
-
}
|
|
830
|
-
return [2 /*return*/, res];
|
|
831
|
-
}
|
|
832
|
-
});
|
|
659
|
+
}
|
|
660
|
+
quit() {
|
|
661
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
662
|
+
const [res, error] = yield this.jsBridge.callAndBackfeed('live/quit');
|
|
663
|
+
if (res === null) {
|
|
664
|
+
this.emit('error', error ? error : new Error('退出房间失败:未知异常。'));
|
|
665
|
+
}
|
|
666
|
+
this.joined = false;
|
|
667
|
+
return !!res;
|
|
833
668
|
});
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
if (res === null) {
|
|
844
|
-
this.emit('error', error ? error : new Error('麦克风监测异常!'));
|
|
845
|
-
return [2 /*return*/, false];
|
|
846
|
-
}
|
|
847
|
-
this.micro = res;
|
|
848
|
-
return [2 /*return*/, res];
|
|
849
|
-
}
|
|
850
|
-
});
|
|
669
|
+
}
|
|
670
|
+
detectMicro() {
|
|
671
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
672
|
+
const [res, error] = yield this.jsBridge.detectMicro();
|
|
673
|
+
if (res === null) {
|
|
674
|
+
this.emit('error', error ? error : new Error('麦克风监测异常!'));
|
|
675
|
+
return false;
|
|
676
|
+
}
|
|
677
|
+
return res;
|
|
851
678
|
});
|
|
852
|
-
}
|
|
853
|
-
|
|
679
|
+
}
|
|
680
|
+
toggleMicro(flag) {
|
|
681
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
682
|
+
const [res, error] = yield this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${!!flag ? 1 : 0}`);
|
|
683
|
+
if (res === null) {
|
|
684
|
+
this.emit('error', error ? error : new Error('麦克风监测异常!'));
|
|
685
|
+
return false;
|
|
686
|
+
}
|
|
687
|
+
this.micro = res;
|
|
688
|
+
return res;
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
shock() {
|
|
854
692
|
this.jsBridge.shock(1);
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
}(CoreRTC));
|
|
693
|
+
}
|
|
694
|
+
}
|
|
858
695
|
|
|
859
696
|
/**
|
|
860
697
|
* WebSocket 通信指令
|
|
@@ -939,8 +776,8 @@ var MicroStatus;
|
|
|
939
776
|
*/
|
|
940
777
|
function parseLiveMsg(jsonTxt) {
|
|
941
778
|
try {
|
|
942
|
-
|
|
943
|
-
|
|
779
|
+
const msg = JSON.parse(jsonTxt);
|
|
780
|
+
const resMsg = {
|
|
944
781
|
code: msg.code,
|
|
945
782
|
message: msg.message,
|
|
946
783
|
command: msg.command,
|
|
@@ -951,11 +788,11 @@ function parseLiveMsg(jsonTxt) {
|
|
|
951
788
|
triggerUserID: msg.trigger_user_id,
|
|
952
789
|
data: msg.data || {},
|
|
953
790
|
};
|
|
954
|
-
|
|
791
|
+
const undefinedKeys = Object.keys(resMsg).filter((key) => resMsg[key] === undefined);
|
|
955
792
|
if (undefinedKeys.length > 0) {
|
|
956
|
-
console.warn(
|
|
793
|
+
console.warn(`推送数据格式异常:${undefinedKeys.join(" ")} 值不存在!`);
|
|
957
794
|
}
|
|
958
|
-
return
|
|
795
|
+
return resMsg;
|
|
959
796
|
}
|
|
960
797
|
catch (error) {
|
|
961
798
|
// notcare? 过滤掉所有不符合规范的数据
|
|
@@ -963,6 +800,23 @@ function parseLiveMsg(jsonTxt) {
|
|
|
963
800
|
}
|
|
964
801
|
}
|
|
965
802
|
|
|
803
|
+
var LiveState;
|
|
804
|
+
(function (LiveState) {
|
|
805
|
+
LiveState[LiveState["NOTINITIALIZED"] = -1] = "NOTINITIALIZED";
|
|
806
|
+
/**
|
|
807
|
+
* 正在链接中
|
|
808
|
+
*/
|
|
809
|
+
LiveState[LiveState["CONNECTING"] = 0] = "CONNECTING";
|
|
810
|
+
/**
|
|
811
|
+
* 已经链接并且可以通讯
|
|
812
|
+
*/
|
|
813
|
+
LiveState[LiveState["OPEN"] = 1] = "OPEN";
|
|
814
|
+
/**
|
|
815
|
+
* 连接已关闭或者链接失败
|
|
816
|
+
*/
|
|
817
|
+
LiveState[LiveState["CLOSED"] = 3] = "CLOSED";
|
|
818
|
+
})(LiveState || (LiveState = {}));
|
|
819
|
+
|
|
966
820
|
/**
|
|
967
821
|
* 用户当前状态枚举。
|
|
968
822
|
*/
|
|
@@ -1092,20 +946,45 @@ function parseWSClsErr(code) {
|
|
|
1092
946
|
return WebSocketCloseError.Err_unknown;
|
|
1093
947
|
}
|
|
1094
948
|
|
|
949
|
+
function getDefaultExportFromCjs (x) {
|
|
950
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
function createCommonjsModule(fn) {
|
|
954
|
+
var module = { exports: {} };
|
|
955
|
+
return fn(module, module.exports), module.exports;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
var LogLevel_1 = createCommonjsModule(function (module, exports) {
|
|
959
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
960
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
961
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
962
|
+
exports.LogLevel = void 0;
|
|
963
|
+
var LogLevel;
|
|
964
|
+
(function (LogLevel) {
|
|
965
|
+
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
966
|
+
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
967
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
968
|
+
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
969
|
+
LogLevel[LogLevel["OFF"] = 4] = "OFF";
|
|
970
|
+
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
971
|
+
exports.default = LogLevel;
|
|
972
|
+
|
|
973
|
+
});
|
|
974
|
+
|
|
975
|
+
var LogLevel = /*@__PURE__*/getDefaultExportFromCjs(LogLevel_1);
|
|
976
|
+
|
|
1095
977
|
function appendUri(uri, query) {
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
var newQuery = Object.keys(query).reduce(function (accu, curr, idx) {
|
|
1099
|
-
return "".concat(accu).concat((idx === 0 && !hasQuery) ? '?' : '&').concat(curr, "=").concat(query[curr]);
|
|
1100
|
-
}, '');
|
|
978
|
+
const hasQuery = uri.indexOf('?') !== -1;
|
|
979
|
+
const newQuery = Object.keys(query).reduce((accu, curr, idx) => `${accu}${(idx === 0 && !hasQuery) ? '?' : '&'}${curr}=${query[curr]}`, '');
|
|
1101
980
|
return uri + newQuery;
|
|
1102
981
|
}
|
|
1103
982
|
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
983
|
+
const userAgent = globalThis.navigator.userAgent;
|
|
984
|
+
const isAndroid = /android/gi.test(userAgent);
|
|
985
|
+
const isIOS = /iPhone|iPad\s+OS/gi.test(userAgent);
|
|
986
|
+
const isWxMiniProgram = /MicroMessenger/gi.test(userAgent) && /miniProgram/gi.test(userAgent);
|
|
987
|
+
const isRealseeVRWebview = /realsee/gi.test(userAgent);
|
|
1109
988
|
|
|
1110
989
|
/**
|
|
1111
990
|
* 判断是否是真实的对象类型
|
|
@@ -1137,12 +1016,12 @@ function baseIsEqual(value, other) {
|
|
|
1137
1016
|
* @returns
|
|
1138
1017
|
*/
|
|
1139
1018
|
function objEqualShallow(value, other) {
|
|
1140
|
-
|
|
1141
|
-
|
|
1019
|
+
const valueProps = Object.getOwnPropertyNames(value);
|
|
1020
|
+
const otherProps = Object.getOwnPropertyNames(other);
|
|
1142
1021
|
if (valueProps.length !== otherProps.length)
|
|
1143
1022
|
return false;
|
|
1144
|
-
for (
|
|
1145
|
-
|
|
1023
|
+
for (let i = 0, len = valueProps.length; i < len; i++) {
|
|
1024
|
+
const propName = valueProps[i];
|
|
1146
1025
|
if (!baseIsEqual(value[propName], other[propName]))
|
|
1147
1026
|
return false;
|
|
1148
1027
|
}
|
|
@@ -1157,7 +1036,7 @@ function objEqualShallow(value, other) {
|
|
|
1157
1036
|
function arrayEqualShallow(value, other) {
|
|
1158
1037
|
if (value.length !== other.length)
|
|
1159
1038
|
return false;
|
|
1160
|
-
for (
|
|
1039
|
+
for (let i = 0, len = value.length; i < len; i++) {
|
|
1161
1040
|
if (!baseIsEqual(value[i], other[i]))
|
|
1162
1041
|
return false;
|
|
1163
1042
|
}
|
|
@@ -1202,7 +1081,7 @@ function isDeepEqual(value, other) {
|
|
|
1202
1081
|
function arrayEqualDeep(value, other) {
|
|
1203
1082
|
if (value.length !== other.length)
|
|
1204
1083
|
return false;
|
|
1205
|
-
for (
|
|
1084
|
+
for (let i = 0, len = value.length; i < len; i++) {
|
|
1206
1085
|
if (!isDeepEqual(value[i], other[i]))
|
|
1207
1086
|
return false;
|
|
1208
1087
|
}
|
|
@@ -1215,12 +1094,12 @@ function arrayEqualDeep(value, other) {
|
|
|
1215
1094
|
* @returns
|
|
1216
1095
|
*/
|
|
1217
1096
|
function objEqualDeep(value, other) {
|
|
1218
|
-
|
|
1219
|
-
|
|
1097
|
+
const valueProps = Object.getOwnPropertyNames(value);
|
|
1098
|
+
const otherProps = Object.getOwnPropertyNames(other);
|
|
1220
1099
|
if (valueProps.length !== otherProps.length)
|
|
1221
1100
|
return false;
|
|
1222
|
-
for (
|
|
1223
|
-
|
|
1101
|
+
for (let i = 0, len = valueProps.length; i < len; i++) {
|
|
1102
|
+
const propName = valueProps[i];
|
|
1224
1103
|
if (!isDeepEqual(value[propName], other[propName]))
|
|
1225
1104
|
return false;
|
|
1226
1105
|
}
|
|
@@ -1234,995 +1113,1325 @@ function objEqualDeep(value, other) {
|
|
|
1234
1113
|
* @returns {boolean} 是否相等。
|
|
1235
1114
|
*/
|
|
1236
1115
|
function equal(value, other, opt) {
|
|
1237
|
-
if (opt === void 0) { opt = { deep: false }; }
|
|
1238
1116
|
if (!opt.deep)
|
|
1239
1117
|
return isShallowEqual(value, other);
|
|
1240
1118
|
return isDeepEqual(value, other);
|
|
1241
1119
|
}
|
|
1242
1120
|
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1121
|
+
/**
|
|
1122
|
+
* 输出格式化日志
|
|
1123
|
+
*/
|
|
1124
|
+
// 获取当前时间
|
|
1125
|
+
const getTime = () => {
|
|
1126
|
+
const date = new Date();
|
|
1127
|
+
const year = date.getFullYear();
|
|
1128
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0'); //月份是从0开始的
|
|
1129
|
+
const day = date.getDate().toString().padStart(2, '0');
|
|
1130
|
+
const hour = date.getHours().toString().padStart(2, '0');
|
|
1131
|
+
const min = date.getMinutes().toString().padStart(2, '0');
|
|
1132
|
+
const sec = date.getSeconds().toString().padStart(2, '0');
|
|
1133
|
+
const ms = date.getMilliseconds();
|
|
1134
|
+
return `[${year}-${month}-${day} ${hour}:${min}:${sec}.${ms}]`;
|
|
1135
|
+
};
|
|
1136
|
+
var LOG_LEVEL;
|
|
1137
|
+
(function (LOG_LEVEL) {
|
|
1138
|
+
LOG_LEVEL["info"] = "INFO";
|
|
1139
|
+
LOG_LEVEL["log"] = "LOG";
|
|
1140
|
+
LOG_LEVEL["error"] = "ERROR";
|
|
1141
|
+
LOG_LEVEL["warn"] = "WARN";
|
|
1142
|
+
})(LOG_LEVEL || (LOG_LEVEL = {}));
|
|
1143
|
+
// 输出日志
|
|
1144
|
+
const echo = (logLevel, args = []) => {
|
|
1145
|
+
args.unshift(`Realsee Live ${getTime()} <${logLevel}> `);
|
|
1146
|
+
switch (logLevel) {
|
|
1147
|
+
case LOG_LEVEL.info:
|
|
1148
|
+
return console.info(...args);
|
|
1149
|
+
case LOG_LEVEL.error:
|
|
1150
|
+
return console.error(...args);
|
|
1151
|
+
case LOG_LEVEL.warn:
|
|
1152
|
+
return console.warn(...args);
|
|
1153
|
+
default:
|
|
1154
|
+
return console.log(...args);
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
const log = (...args) => echo(LOG_LEVEL.log, args);
|
|
1158
|
+
const info = (...args) => echo(LOG_LEVEL.info, args);
|
|
1159
|
+
const error = (...args) => echo(LOG_LEVEL.error, args);
|
|
1160
|
+
const warn = (...args) => echo(LOG_LEVEL.warn, args);
|
|
1161
|
+
const logger = {
|
|
1162
|
+
log,
|
|
1163
|
+
info,
|
|
1164
|
+
error,
|
|
1165
|
+
warn,
|
|
1166
|
+
};
|
|
1167
|
+
var logger$1 = logger;
|
|
1168
|
+
|
|
1169
|
+
/**
|
|
1170
|
+
* 具有鲁棒性的WebSocket封装
|
|
1171
|
+
* 1、自动重连
|
|
1172
|
+
* 2、可根据网络情况进行重连
|
|
1173
|
+
*/
|
|
1174
|
+
class RobustWebSocket extends Subscribe {
|
|
1175
|
+
constructor(options) {
|
|
1176
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
1177
|
+
super();
|
|
1178
|
+
this._readyState = WebSocketState.NOTINITIALIZED;
|
|
1179
|
+
this._options = {
|
|
1180
|
+
timeout: 10000,
|
|
1181
|
+
shouldReconnect: (event, ws) => {
|
|
1182
|
+
if (event.code === 1008 || event.code === 1011)
|
|
1183
|
+
return;
|
|
1184
|
+
return [0, 3000, 10000][ws.attempts];
|
|
1185
|
+
},
|
|
1186
|
+
should1000Reconnect: false,
|
|
1187
|
+
ignoreConnectivityEvents: false,
|
|
1188
|
+
automaticOpen: false,
|
|
1189
|
+
};
|
|
1190
|
+
this._attempts = 0;
|
|
1191
|
+
this._reconnects = -1;
|
|
1192
|
+
this._reconnectWhenOnlineAgain = false;
|
|
1193
|
+
this._explicitlyClosed = false;
|
|
1194
|
+
this._connectivityEventsAttached = false;
|
|
1250
1195
|
/**
|
|
1251
|
-
*
|
|
1196
|
+
* 做一个健康检查
|
|
1252
1197
|
*/
|
|
1253
|
-
this.
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
break;
|
|
1198
|
+
this._healthCheck = () => __awaiter(this, void 0, void 0, function* () {
|
|
1199
|
+
if (this._realWebSocket &&
|
|
1200
|
+
this._realWebSocket.readyState !== this._readyState) {
|
|
1201
|
+
this._readyState = this._realWebSocket.readyState;
|
|
1202
|
+
// 太惨了,断网的时候,ws不会直接closed,而是处于closing的状态
|
|
1203
|
+
if (this._readyState === WebSocketState.CLOSING) {
|
|
1204
|
+
this.emit('closing');
|
|
1261
1205
|
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1206
|
+
}
|
|
1207
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1208
|
+
this._heathCheckTimer = requestAnimationFrame(this._healthCheck);
|
|
1209
|
+
});
|
|
1210
|
+
/**
|
|
1211
|
+
* 清理健康检查
|
|
1212
|
+
*/
|
|
1213
|
+
this._clearHeathCheckIfNeed = () => {
|
|
1214
|
+
if (this._heathCheckTimer) {
|
|
1215
|
+
cancelAnimationFrame(this._heathCheckTimer);
|
|
1216
|
+
this._heathCheckTimer = undefined;
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
/**
|
|
1220
|
+
* 开启健康检查
|
|
1221
|
+
*/
|
|
1222
|
+
this._startHealthCheck = () => {
|
|
1223
|
+
this._clearHeathCheckIfNeed();
|
|
1224
|
+
this._heathCheckTimer = requestAnimationFrame(this._healthCheck);
|
|
1225
|
+
};
|
|
1226
|
+
/**
|
|
1227
|
+
* 停止健康检查
|
|
1228
|
+
*/
|
|
1229
|
+
this._stopHealthCheck = () => {
|
|
1230
|
+
this._clearHeathCheckIfNeed();
|
|
1269
1231
|
};
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1232
|
+
/**
|
|
1233
|
+
* 清理连接中的请求
|
|
1234
|
+
*/
|
|
1235
|
+
this._clearPendingReconnectIfNeeded = () => {
|
|
1236
|
+
if (this._pendingReconnect) {
|
|
1237
|
+
clearTimeout(this._pendingReconnect);
|
|
1238
|
+
this._pendingReconnect = undefined;
|
|
1276
1239
|
}
|
|
1277
|
-
return true;
|
|
1278
1240
|
};
|
|
1279
1241
|
/**
|
|
1280
|
-
*
|
|
1242
|
+
* 当网页连接上网络进行重连
|
|
1243
|
+
* @param event
|
|
1281
1244
|
*/
|
|
1282
|
-
this.
|
|
1283
|
-
if (
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
_this.webSocket.removeEventListener('open', _this.onEvtOpnListener);
|
|
1287
|
-
_this.onEvtOpnListener = undefined;
|
|
1245
|
+
this._online = (event) => {
|
|
1246
|
+
if (this._reconnectWhenOnlineAgain) {
|
|
1247
|
+
this._clearPendingReconnectIfNeeded();
|
|
1248
|
+
this._reconnect(event);
|
|
1288
1249
|
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1250
|
+
};
|
|
1251
|
+
/**
|
|
1252
|
+
* 当网页断开网络进行关闭
|
|
1253
|
+
*/
|
|
1254
|
+
this._offline = () => {
|
|
1255
|
+
var _a;
|
|
1256
|
+
this._reconnectWhenOnlineAgain = true;
|
|
1257
|
+
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(1000, 'offline');
|
|
1258
|
+
};
|
|
1259
|
+
/**
|
|
1260
|
+
* 解除网络监听事件
|
|
1261
|
+
*/
|
|
1262
|
+
this._detachConnectivityEvents = () => {
|
|
1263
|
+
if (this._connectivityEventsAttached) {
|
|
1264
|
+
globalThis === null || globalThis === void 0 ? void 0 : globalThis.removeEventListener('online', this._online);
|
|
1265
|
+
globalThis === null || globalThis === void 0 ? void 0 : globalThis.removeEventListener('offline', this._offline);
|
|
1266
|
+
this._connectivityEventsAttached = false;
|
|
1292
1267
|
}
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1268
|
+
};
|
|
1269
|
+
/**
|
|
1270
|
+
* 注册网络监听事件
|
|
1271
|
+
*/
|
|
1272
|
+
this._attachConnectivityEvents = () => {
|
|
1273
|
+
if (!this._connectivityEventsAttached) {
|
|
1274
|
+
globalThis === null || globalThis === void 0 ? void 0 : globalThis.addEventListener('online', this._online);
|
|
1275
|
+
globalThis === null || globalThis === void 0 ? void 0 : globalThis.addEventListener('offline', this._offline);
|
|
1276
|
+
this._connectivityEventsAttached = true;
|
|
1296
1277
|
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1278
|
+
};
|
|
1279
|
+
/**
|
|
1280
|
+
* 发送消息
|
|
1281
|
+
* @param data
|
|
1282
|
+
* @returns
|
|
1283
|
+
*/
|
|
1284
|
+
this.send = (data) => {
|
|
1285
|
+
var _a, _b, _c;
|
|
1286
|
+
if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) === ((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.OPEN)) {
|
|
1287
|
+
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.send(data);
|
|
1300
1288
|
}
|
|
1301
|
-
_this.webSocket.close();
|
|
1302
|
-
_this.webSocket = undefined;
|
|
1303
|
-
return true;
|
|
1304
1289
|
};
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
if (code === 'SUCCESS') {
|
|
1317
|
-
switch (command) {
|
|
1318
|
-
/**
|
|
1319
|
-
* 自己的状态变化
|
|
1320
|
-
*/
|
|
1321
|
-
case Command.SelfUserInfo: {
|
|
1322
|
-
var selfInfo = data;
|
|
1323
|
-
if (equal(this.selfUserInfo, selfInfo, { deep: true }))
|
|
1324
|
-
return;
|
|
1325
|
-
this.selfUserInfo = selfInfo;
|
|
1326
|
-
live.emit('selfInfoUpdate', this.selfUserInfo, frontRequestId);
|
|
1327
|
-
break;
|
|
1328
|
-
}
|
|
1329
|
-
/**
|
|
1330
|
-
* 房间信息变化
|
|
1331
|
-
*/
|
|
1332
|
-
case Command.RoomInfo: {
|
|
1333
|
-
var roomInfo = data;
|
|
1334
|
-
this.roomInfo = Object.assign({}, roomInfo);
|
|
1335
|
-
live.emit('readyKeyframeSync', (roomInfo.last_frame || {}));
|
|
1336
|
-
break;
|
|
1337
|
-
}
|
|
1338
|
-
/**
|
|
1339
|
-
* 语音信息变化
|
|
1340
|
-
*/
|
|
1341
|
-
case Command.RTCInfo: {
|
|
1342
|
-
var _d = data, voiceId = _d.voice_id, type = _d.type;
|
|
1343
|
-
/* 如果已经进入语音房间,则不重复进入 --> "RTCInfo" 指令可能会下发多次 */
|
|
1344
|
-
if (live.$RTC.joined) {
|
|
1345
|
-
break;
|
|
1346
|
-
}
|
|
1347
|
-
live.$RTC.join({
|
|
1348
|
-
voiceId: voiceId,
|
|
1349
|
-
userId: ((_a = this.selfUserInfo) === null || _a === void 0 ? void 0 : _a.id) || '',
|
|
1350
|
-
roomId: (_b = this.roomInfo) === null || _b === void 0 ? void 0 : _b.info.room_code,
|
|
1351
|
-
type: type,
|
|
1352
|
-
});
|
|
1353
|
-
// 加入房间后 麦克风默认就开启了:需要发个指令。
|
|
1354
|
-
live.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserMicroStatus, {
|
|
1355
|
-
status: MicroStatus.OPEN,
|
|
1356
|
-
});
|
|
1357
|
-
break;
|
|
1358
|
-
}
|
|
1359
|
-
/**
|
|
1360
|
-
* 房间用户列表变化
|
|
1361
|
-
*/
|
|
1362
|
-
case Command.UserList: {
|
|
1363
|
-
var userList = data;
|
|
1364
|
-
this.userList = userList;
|
|
1365
|
-
live.emit('userListUpdate', this.userList, frontRequestId);
|
|
1366
|
-
break;
|
|
1367
|
-
}
|
|
1368
|
-
/**
|
|
1369
|
-
* 自定义事件广播
|
|
1370
|
-
*/
|
|
1371
|
-
case Command.CustomEvent: {
|
|
1372
|
-
var evtMsg = data;
|
|
1373
|
-
live.emit('broadcast', evtMsg, frontRequestId);
|
|
1374
|
-
break;
|
|
1375
|
-
}
|
|
1376
|
-
/**
|
|
1377
|
-
* 帧数据同步
|
|
1378
|
-
*/
|
|
1379
|
-
case Command.KeyframeSync: {
|
|
1380
|
-
var remoteKeyframes_1 = data;
|
|
1381
|
-
// 此处做一层 diff,仅跟本地数据不一致的情况下才广播数据。
|
|
1382
|
-
var keyframes = Object.keys(remoteKeyframes_1).reduce(function (accu, curr) {
|
|
1383
|
-
var _a;
|
|
1384
|
-
if (equal(remoteKeyframes_1[curr], _this.keyframes[curr], { deep: true })) {
|
|
1385
|
-
return accu;
|
|
1386
|
-
}
|
|
1387
|
-
var params = [
|
|
1388
|
-
remoteKeyframes_1[curr],
|
|
1389
|
-
_this.keyframes[curr],
|
|
1390
|
-
frontRequestId,
|
|
1391
|
-
];
|
|
1392
|
-
var evtName = curr;
|
|
1393
|
-
(_a = live.keyframes).emit.apply(_a, __spreadArray([evtName], params, false));
|
|
1394
|
-
_this.keyframes[curr] = remoteKeyframes_1[curr];
|
|
1395
|
-
accu[curr] = remoteKeyframes_1[curr];
|
|
1396
|
-
return accu;
|
|
1397
|
-
}, {});
|
|
1398
|
-
live.emit('keyframes', keyframes, frontRequestId);
|
|
1399
|
-
break;
|
|
1400
|
-
}
|
|
1401
|
-
/**
|
|
1402
|
-
* 内置消息
|
|
1403
|
-
*/
|
|
1404
|
-
case Command.BuiltinMsg: {
|
|
1405
|
-
var builtinMsg = data;
|
|
1406
|
-
live.emit('builtinEvent', builtinMsg);
|
|
1407
|
-
if (builtinMsg.event_type === BuiltinEventType.UserChange) {
|
|
1408
|
-
live.emit('userChange', builtinMsg);
|
|
1409
|
-
}
|
|
1410
|
-
if (builtinMsg.event_type === BuiltinEventType.RoomChange) {
|
|
1411
|
-
live.emit('roomChange', builtinMsg);
|
|
1412
|
-
}
|
|
1413
|
-
/**
|
|
1414
|
-
* 下发指令自己操作麦克风
|
|
1415
|
-
*/
|
|
1416
|
-
if (builtinMsg.event_type === BuiltinEventType.UserChange &&
|
|
1417
|
-
builtinMsg.action === BuiltinActionType.UserMicroStatus) {
|
|
1418
|
-
live.toggleMicro(builtinMsg.data.status === MicroStatus.OPEN);
|
|
1419
|
-
}
|
|
1420
|
-
/**
|
|
1421
|
-
* 如果下发指令退出房间,则 关闭麦克风 及 销毁 WebSocket
|
|
1422
|
-
*/
|
|
1423
|
-
if (builtinMsg.event_type === BuiltinEventType.RoomChange &&
|
|
1424
|
-
builtinMsg.action === BuiltinActionType.RoomClose) {
|
|
1425
|
-
(_c = this.options.rtc) === null || _c === void 0 ? void 0 : _c.quit();
|
|
1426
|
-
this.disposeWebSocket();
|
|
1427
|
-
}
|
|
1428
|
-
break;
|
|
1429
|
-
}
|
|
1430
|
-
/**
|
|
1431
|
-
* 被踢出房间
|
|
1432
|
-
*/
|
|
1433
|
-
case Command.UserKickOut: {
|
|
1434
|
-
live.emit('kickOut');
|
|
1435
|
-
break;
|
|
1436
|
-
}
|
|
1437
|
-
/**
|
|
1438
|
-
* 其它未知广播
|
|
1439
|
-
*/
|
|
1440
|
-
default: {
|
|
1441
|
-
console.warn('unknown command: ', command);
|
|
1442
|
-
}
|
|
1290
|
+
/**
|
|
1291
|
+
* 关闭连接
|
|
1292
|
+
* @param code 代码
|
|
1293
|
+
* @param reason 原因
|
|
1294
|
+
* @returns
|
|
1295
|
+
*/
|
|
1296
|
+
this.close = (code, reason) => {
|
|
1297
|
+
var _a;
|
|
1298
|
+
if (typeof code !== 'number') {
|
|
1299
|
+
reason = code;
|
|
1300
|
+
code = 1000;
|
|
1443
1301
|
}
|
|
1302
|
+
this._clearPendingReconnectIfNeeded();
|
|
1303
|
+
this._reconnectWhenOnlineAgain = false;
|
|
1304
|
+
this._explicitlyClosed = true;
|
|
1305
|
+
this._detachConnectivityEvents();
|
|
1306
|
+
return (_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(code, reason);
|
|
1307
|
+
};
|
|
1308
|
+
/**
|
|
1309
|
+
* 进行ws连接
|
|
1310
|
+
*/
|
|
1311
|
+
this.open = (url) => {
|
|
1312
|
+
var _a, _b;
|
|
1313
|
+
if (url) {
|
|
1314
|
+
this._url = url;
|
|
1315
|
+
}
|
|
1316
|
+
if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) !== WebSocket.OPEN &&
|
|
1317
|
+
((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.readyState) !== WebSocket.CONNECTING) {
|
|
1318
|
+
this._clearPendingReconnectIfNeeded();
|
|
1319
|
+
this._reconnectWhenOnlineAgain = false;
|
|
1320
|
+
this._explicitlyClosed = false;
|
|
1321
|
+
this._createWebSocket();
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
/**
|
|
1325
|
+
* 创建ws连接
|
|
1326
|
+
*/
|
|
1327
|
+
this._createWebSocket = () => {
|
|
1328
|
+
var _a, _b, _c;
|
|
1329
|
+
const newUrl = typeof this._url === 'string' ? this._url : (_a = this._url) === null || _a === void 0 ? void 0 : _a.call(this, this);
|
|
1330
|
+
if (!newUrl)
|
|
1331
|
+
return;
|
|
1332
|
+
this._pendingReconnect = undefined;
|
|
1333
|
+
this._removeWebSocketEvent();
|
|
1334
|
+
this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
|
|
1335
|
+
this._attempts = this._attempts + 1;
|
|
1336
|
+
this.emit('connecting', new CustomEvent('connecting', {
|
|
1337
|
+
detail: { attempts: this._attempts, reconnects: this._reconnects },
|
|
1338
|
+
}));
|
|
1339
|
+
const timeoutCallback = () => {
|
|
1340
|
+
this._connectTimeout = undefined;
|
|
1341
|
+
this._detachConnectivityEvents();
|
|
1342
|
+
this.emit('timeout', new CustomEvent('connecting', {
|
|
1343
|
+
detail: {
|
|
1344
|
+
attempts: this._attempts,
|
|
1345
|
+
reconnects: this._reconnects,
|
|
1346
|
+
},
|
|
1347
|
+
}));
|
|
1348
|
+
};
|
|
1349
|
+
this._connectTimeout = setTimeout(timeoutCallback, (_b = this._options) === null || _b === void 0 ? void 0 : _b.timeout);
|
|
1350
|
+
this._dispatchWebSocketEvent();
|
|
1351
|
+
if (!((_c = this._options) === null || _c === void 0 ? void 0 : _c.ignoreConnectivityEvents)) {
|
|
1352
|
+
this._attachConnectivityEvents();
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
/**
|
|
1356
|
+
* 断开ws事件
|
|
1357
|
+
*/
|
|
1358
|
+
this._removeWebSocketEvent = () => {
|
|
1359
|
+
var _a, _b, _c, _d;
|
|
1360
|
+
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
|
|
1361
|
+
(_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
|
|
1362
|
+
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
|
|
1363
|
+
(_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
|
|
1364
|
+
};
|
|
1365
|
+
/**
|
|
1366
|
+
* 分发ws事件
|
|
1367
|
+
*/
|
|
1368
|
+
this._dispatchWebSocketEvent = () => {
|
|
1369
|
+
var _a, _b, _c, _d;
|
|
1370
|
+
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.addEventListener('open', this._webSocketOpenHandler);
|
|
1371
|
+
(_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.addEventListener('close', this._webSocketCloseHandler);
|
|
1372
|
+
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.addEventListener('error', this._webSocketErrorHandler);
|
|
1373
|
+
(_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.addEventListener('message', this._webSocketMessageHandler);
|
|
1374
|
+
};
|
|
1375
|
+
/**
|
|
1376
|
+
* ws连接事件
|
|
1377
|
+
* @returns
|
|
1378
|
+
*/
|
|
1379
|
+
this._webSocketOpenHandler = (event) => {
|
|
1380
|
+
if (this._connectTimeout) {
|
|
1381
|
+
clearTimeout(this._connectTimeout);
|
|
1382
|
+
this._connectTimeout = undefined;
|
|
1383
|
+
}
|
|
1384
|
+
const reconnects = ++this._reconnects;
|
|
1385
|
+
const attempts = this._attempts;
|
|
1386
|
+
this._attempts = 0;
|
|
1387
|
+
this._reconnectWhenOnlineAgain = false;
|
|
1388
|
+
this._startHealthCheck();
|
|
1389
|
+
return this.emit('open', Object.assign(event, { detail: { reconnects, attempts } }));
|
|
1390
|
+
};
|
|
1391
|
+
/**
|
|
1392
|
+
* ws 关闭事件
|
|
1393
|
+
* @param event
|
|
1394
|
+
* @returns
|
|
1395
|
+
*/
|
|
1396
|
+
this._webSocketCloseHandler = (event) => {
|
|
1397
|
+
this._reconnect(event);
|
|
1398
|
+
this._stopHealthCheck();
|
|
1399
|
+
return this.emit('close', event);
|
|
1400
|
+
};
|
|
1401
|
+
/**
|
|
1402
|
+
* ws 异常
|
|
1403
|
+
* @param event
|
|
1404
|
+
* @returns
|
|
1405
|
+
*/
|
|
1406
|
+
this._webSocketErrorHandler = (event) => {
|
|
1407
|
+
return this.emit('error', new CustomEvent('error', { detail: { error: event } }));
|
|
1408
|
+
};
|
|
1409
|
+
/**
|
|
1410
|
+
* ws消息
|
|
1411
|
+
* @param event
|
|
1412
|
+
* @returns
|
|
1413
|
+
*/
|
|
1414
|
+
this._webSocketMessageHandler = (event) => {
|
|
1415
|
+
return this.emit('message', event);
|
|
1416
|
+
};
|
|
1417
|
+
if (options) {
|
|
1418
|
+
this.setOptions(options);
|
|
1444
1419
|
}
|
|
1445
|
-
|
|
1446
|
-
|
|
1420
|
+
this._startHealthCheck();
|
|
1421
|
+
}
|
|
1422
|
+
get attempts() {
|
|
1423
|
+
return this._attempts;
|
|
1424
|
+
}
|
|
1425
|
+
setOptions(options) {
|
|
1426
|
+
if (!options)
|
|
1427
|
+
return;
|
|
1428
|
+
this._url = options.url;
|
|
1429
|
+
this._protocols = options.protocols;
|
|
1430
|
+
const opts = Object.assign(this._options, options.robustOptions || {});
|
|
1431
|
+
if (typeof (opts === null || opts === void 0 ? void 0 : opts.timeout) !== 'number') {
|
|
1432
|
+
throw new Error('timeout must be the number of milliseconds to timeout a connection attempt');
|
|
1447
1433
|
}
|
|
1448
|
-
|
|
1434
|
+
if (typeof (opts === null || opts === void 0 ? void 0 : opts.shouldReconnect) !== 'function') {
|
|
1435
|
+
throw new Error('shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.');
|
|
1436
|
+
}
|
|
1437
|
+
this._options = opts;
|
|
1438
|
+
if (this._options.automaticOpen) {
|
|
1439
|
+
this._createWebSocket();
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* 进行重连
|
|
1444
|
+
* @param event
|
|
1445
|
+
* @returns
|
|
1446
|
+
*/
|
|
1447
|
+
_reconnect(event) {
|
|
1448
|
+
var _a, _b, _c, _d;
|
|
1449
|
+
if ((!((_a = this._options) === null || _a === void 0 ? void 0 : _a.should1000Reconnect) && event.code === 1000) ||
|
|
1450
|
+
this._explicitlyClosed) {
|
|
1451
|
+
this._attempts = 0;
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
if (((_b = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _b === void 0 ? void 0 : _b.onLine) === false) {
|
|
1455
|
+
this._reconnectWhenOnlineAgain = true;
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
const delay = (_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.shouldReconnect) === null || _d === void 0 ? void 0 : _d.call(_c, event, this);
|
|
1459
|
+
if (typeof delay === 'number') {
|
|
1460
|
+
this._pendingReconnect = setTimeout(this._createWebSocket, delay);
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
class LiveController extends Subscribe {
|
|
1466
|
+
constructor() {
|
|
1467
|
+
super();
|
|
1468
|
+
/**
|
|
1469
|
+
* ws代理器
|
|
1470
|
+
*/
|
|
1471
|
+
this._ws = new RobustWebSocket({
|
|
1472
|
+
url: '',
|
|
1473
|
+
robustOptions: { timeout: 180000 },
|
|
1474
|
+
});
|
|
1475
|
+
/**
|
|
1476
|
+
* 带看连接状态
|
|
1477
|
+
*/
|
|
1478
|
+
this._state = LiveState.NOTINITIALIZED;
|
|
1479
|
+
/**
|
|
1480
|
+
* 添加事件监听
|
|
1481
|
+
*/
|
|
1482
|
+
this._addWebSocketEventListeners = () => {
|
|
1483
|
+
this._ws.on('close', this._handleCloseEvent);
|
|
1484
|
+
this._ws.on('closing', this._handleClosingEvent);
|
|
1485
|
+
this._ws.on('connecting', this._handleConnectingEvent);
|
|
1486
|
+
this._ws.on('error', this._handleErrorEvent);
|
|
1487
|
+
this._ws.on('message', this._handleMessageEvent);
|
|
1488
|
+
this._ws.on('open', this._handleOpenEvent);
|
|
1489
|
+
this._ws.on('timeout', this._handleTimeoutEvent);
|
|
1490
|
+
};
|
|
1491
|
+
/**
|
|
1492
|
+
* 移除事件监听
|
|
1493
|
+
*/
|
|
1494
|
+
this._removeWebSocketEventListeners = () => {
|
|
1495
|
+
this._ws.off('close', this._handleCloseEvent);
|
|
1496
|
+
this._ws.off('closing', this._handleClosingEvent);
|
|
1497
|
+
this._ws.off('connecting', this._handleConnectingEvent);
|
|
1498
|
+
this._ws.off('error', this._handleErrorEvent);
|
|
1499
|
+
this._ws.off('message', this._handleMessageEvent);
|
|
1500
|
+
this._ws.off('open', this._handleOpenEvent);
|
|
1501
|
+
this._ws.off('timeout', this._handleTimeoutEvent);
|
|
1502
|
+
};
|
|
1503
|
+
/**
|
|
1504
|
+
* 处理房间关闭事件
|
|
1505
|
+
* @param event
|
|
1506
|
+
*/
|
|
1507
|
+
this._handleCloseEvent = (event) => {
|
|
1508
|
+
logger$1.info(`live room closed bacause of ${event.code}-${event.reason || parseWSClsErr(event.code)}`);
|
|
1509
|
+
this.state = LiveState.CLOSED;
|
|
1510
|
+
};
|
|
1511
|
+
/**
|
|
1512
|
+
* 处理房间正在关闭事件(这个时候可能是断网了)
|
|
1513
|
+
*/
|
|
1514
|
+
this._handleClosingEvent = () => {
|
|
1515
|
+
var _a;
|
|
1516
|
+
logger$1.info(`live room is closing, onLine:`, (_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _a === void 0 ? void 0 : _a.onLine);
|
|
1517
|
+
this.state = LiveState.CLOSED;
|
|
1518
|
+
};
|
|
1519
|
+
/**
|
|
1520
|
+
* 连接中
|
|
1521
|
+
* @param event
|
|
1522
|
+
*/
|
|
1523
|
+
this._handleConnectingEvent = () => {
|
|
1524
|
+
logger$1.info(`live room is connecting`);
|
|
1525
|
+
this.state = LiveState.CONNECTING;
|
|
1526
|
+
};
|
|
1527
|
+
/**
|
|
1528
|
+
* 连接发送异常
|
|
1529
|
+
* @param event
|
|
1530
|
+
*/
|
|
1531
|
+
this._handleErrorEvent = (event) => {
|
|
1532
|
+
logger$1.error(`live room error`, event);
|
|
1533
|
+
this.state = LiveState.CLOSED;
|
|
1534
|
+
};
|
|
1535
|
+
/**
|
|
1536
|
+
* 接收到消息
|
|
1537
|
+
* @param event
|
|
1538
|
+
*/
|
|
1539
|
+
this._handleMessageEvent = (event) => {
|
|
1540
|
+
// logger.info('live room received message ', event.data);
|
|
1541
|
+
let message = (() => {
|
|
1542
|
+
try {
|
|
1543
|
+
return JSON.parse(event.data);
|
|
1544
|
+
}
|
|
1545
|
+
catch (e) {
|
|
1546
|
+
return event.data;
|
|
1547
|
+
}
|
|
1548
|
+
})();
|
|
1549
|
+
this.emit('message', message);
|
|
1550
|
+
};
|
|
1551
|
+
/**
|
|
1552
|
+
* 连接建立成功
|
|
1553
|
+
* @param event
|
|
1554
|
+
*/
|
|
1555
|
+
this._handleOpenEvent = (event) => {
|
|
1556
|
+
logger$1.info('live room open', event.detail);
|
|
1557
|
+
this.state = LiveState.OPEN;
|
|
1558
|
+
if (event.detail.reconnects > 0) {
|
|
1559
|
+
this.emit('reconnected', event.detail);
|
|
1560
|
+
}
|
|
1561
|
+
};
|
|
1562
|
+
/**
|
|
1563
|
+
* 处理超时
|
|
1564
|
+
* @param event
|
|
1565
|
+
*/
|
|
1566
|
+
this._handleTimeoutEvent = (event) => {
|
|
1567
|
+
logger$1.error('live room connect timeout!', event.detail);
|
|
1568
|
+
this.state = LiveState.CLOSED;
|
|
1569
|
+
};
|
|
1570
|
+
/**
|
|
1571
|
+
* 释放资源,释放之后需要重新实例化
|
|
1572
|
+
* @returns
|
|
1573
|
+
*/
|
|
1574
|
+
this.dispose = () => __awaiter(this, void 0, void 0, function* () {
|
|
1575
|
+
this._removeWebSocketEventListeners();
|
|
1576
|
+
return yield this.close('live room close by controller disposed!');
|
|
1577
|
+
});
|
|
1578
|
+
/**
|
|
1579
|
+
* 开启房间链接
|
|
1580
|
+
* @param url 房间链接
|
|
1581
|
+
* @returns
|
|
1582
|
+
*/
|
|
1583
|
+
this.open = (url) => this._ws.open(url);
|
|
1584
|
+
/**
|
|
1585
|
+
* 关闭房间
|
|
1586
|
+
* @param code
|
|
1587
|
+
* @param reason
|
|
1588
|
+
*/
|
|
1589
|
+
this.close = (code, reason) => new Promise((resolve) => {
|
|
1590
|
+
this._ws.once('close', () => resolve(true));
|
|
1591
|
+
this._ws.close(code, reason);
|
|
1592
|
+
});
|
|
1593
|
+
this._addWebSocketEventListeners();
|
|
1594
|
+
}
|
|
1595
|
+
set state(state) {
|
|
1596
|
+
const prevState = JSON.parse(JSON.stringify(this._state));
|
|
1597
|
+
this._state = state;
|
|
1598
|
+
this.emit('stateChange', this.state, prevState);
|
|
1599
|
+
}
|
|
1600
|
+
get state() {
|
|
1601
|
+
return this._state;
|
|
1602
|
+
}
|
|
1449
1603
|
/**
|
|
1450
1604
|
* 发送数据
|
|
1451
1605
|
* @param data
|
|
1452
1606
|
*/
|
|
1453
|
-
|
|
1454
|
-
if (
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1607
|
+
sendMessage(data = '') {
|
|
1608
|
+
if (data === undefined || data === null || data === '') {
|
|
1609
|
+
throw new Error('live message is empty!');
|
|
1610
|
+
}
|
|
1611
|
+
if (this.state === LiveState.OPEN) {
|
|
1612
|
+
return this._ws.send(JSON.stringify(data));
|
|
1613
|
+
}
|
|
1614
|
+
else {
|
|
1615
|
+
throw new Error('live has not yet been initialized!');
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1462
1619
|
|
|
1463
|
-
|
|
1464
|
-
|
|
1620
|
+
const unimplementedGetVoiceSign = (params) => Promise.reject('unimplemented method GetVoiceSign');
|
|
1621
|
+
const createLiveMsg = (command, data = {}, toUserIds = []) => ({
|
|
1622
|
+
command,
|
|
1623
|
+
front_request_id: uuid(),
|
|
1624
|
+
data: Object.assign(Object.assign({}, data), { to_user_ids: Array.isArray(toUserIds) ? toUserIds : [toUserIds] }),
|
|
1625
|
+
});
|
|
1626
|
+
const _clearLiveInstanceIfNeed = () => {
|
|
1627
|
+
var _a, _b;
|
|
1628
|
+
if (window === null || window === void 0 ? void 0 : window.__Realsee_Live__) {
|
|
1629
|
+
(_b = (_a = window === null || window === void 0 ? void 0 : window.__Realsee_Live__) === null || _a === void 0 ? void 0 : _a.dispose) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1630
|
+
window.__Realsee_Live__ = null;
|
|
1631
|
+
}
|
|
1465
1632
|
};
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1633
|
+
class Live extends Subscribe {
|
|
1634
|
+
constructor(opts) {
|
|
1635
|
+
var _a;
|
|
1636
|
+
super();
|
|
1637
|
+
/**
|
|
1638
|
+
* 带看的配置
|
|
1639
|
+
*/
|
|
1640
|
+
this._options = {};
|
|
1641
|
+
/**
|
|
1642
|
+
* 帧数据监听
|
|
1643
|
+
*/
|
|
1644
|
+
this.keyframes = new Subscribe();
|
|
1645
|
+
/**
|
|
1646
|
+
* 内置的一些数据
|
|
1647
|
+
*/
|
|
1648
|
+
this._buildInData = {
|
|
1649
|
+
keyframes: {},
|
|
1650
|
+
};
|
|
1651
|
+
/**
|
|
1652
|
+
* 根据键值取帧数据
|
|
1653
|
+
* @param key 帧数据的键值
|
|
1654
|
+
* @returns
|
|
1655
|
+
*/
|
|
1656
|
+
this.getFramesByKey = (key) => this.snapshot[key];
|
|
1657
|
+
/**
|
|
1658
|
+
* 发送帧数据(需要能够被序列化)
|
|
1659
|
+
* @param key 帧数据键值
|
|
1660
|
+
* @param frame 帧数据本体
|
|
1661
|
+
* @returns
|
|
1662
|
+
*/
|
|
1663
|
+
this.sendKeyframe = (key, frame) => {
|
|
1664
|
+
if (this.state !== LiveState.OPEN)
|
|
1665
|
+
return false;
|
|
1666
|
+
this._buildInData.keyframes = Object.assign(Object.assign({}, this._buildInData.keyframes), { [key]: frame });
|
|
1667
|
+
const liveMsg = createLiveMsg(Command.KeyframeSync, this.snapshot);
|
|
1668
|
+
try {
|
|
1669
|
+
this._controller.sendMessage(liveMsg);
|
|
1670
|
+
return true;
|
|
1671
|
+
}
|
|
1672
|
+
catch (e) {
|
|
1673
|
+
logger$1.error(e);
|
|
1674
|
+
return false;
|
|
1675
|
+
}
|
|
1676
|
+
};
|
|
1677
|
+
/**
|
|
1678
|
+
* 带看控制器
|
|
1679
|
+
*/
|
|
1680
|
+
this._controller = new LiveController();
|
|
1681
|
+
/**
|
|
1682
|
+
* 添加带看控制的事件监听
|
|
1683
|
+
*/
|
|
1684
|
+
this._addLiveControllerEventListeners = () => {
|
|
1685
|
+
this._controller.on('stateChange', this._handleStateChange);
|
|
1686
|
+
this._controller.on('message', this._handleMessage);
|
|
1687
|
+
};
|
|
1688
|
+
/**
|
|
1689
|
+
* 移除带看控制的事件监听
|
|
1690
|
+
*/
|
|
1691
|
+
this._removeLiveControllerEventListeners = () => {
|
|
1692
|
+
this._controller.off('stateChange', this._handleStateChange);
|
|
1693
|
+
this._controller.off('message', this._handleMessage);
|
|
1694
|
+
};
|
|
1695
|
+
/**
|
|
1696
|
+
* 带看状态变化
|
|
1697
|
+
* @param state
|
|
1698
|
+
* @returns
|
|
1699
|
+
*/
|
|
1700
|
+
this._handleStateChange = (state, prevState) => this.emit('stateChange', state, prevState);
|
|
1701
|
+
/**
|
|
1702
|
+
* 消息接收
|
|
1703
|
+
* @param liveMsg
|
|
1704
|
+
*/
|
|
1705
|
+
this._handleMessage = (liveMsg) => __awaiter(this, void 0, void 0, function* () {
|
|
1706
|
+
var _b, _c, _d, _e, _f, _g;
|
|
1707
|
+
if (typeof liveMsg === 'object') {
|
|
1708
|
+
const { command, data, frontRequestId, code, message } = liveMsg;
|
|
1709
|
+
if (code === 'SUCCESS') {
|
|
1710
|
+
switch (command) {
|
|
1711
|
+
/**
|
|
1712
|
+
* 自己的状态变化
|
|
1713
|
+
*/
|
|
1714
|
+
case Command.SelfUserInfo: {
|
|
1715
|
+
const selfInfo = data;
|
|
1716
|
+
if (!equal(this.selfInfo, selfInfo, { deep: true })) {
|
|
1717
|
+
this._buildInData.selfInfo = selfInfo;
|
|
1718
|
+
this.emit('selfInfoUpdate', this._buildInData.selfInfo, frontRequestId);
|
|
1510
1719
|
}
|
|
1511
|
-
liveController.options.rtc = new VRWebViewRTC({
|
|
1512
|
-
jsBridge: jsBridge,
|
|
1513
|
-
getVoiceSign: getVoiceSign,
|
|
1514
|
-
});
|
|
1515
1720
|
break;
|
|
1516
1721
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
});
|
|
1722
|
+
/**
|
|
1723
|
+
* 房间信息变化
|
|
1724
|
+
*/
|
|
1725
|
+
case Command.RoomInfo: {
|
|
1726
|
+
const roomInfo = data;
|
|
1727
|
+
this._buildInData.roomInfo = Object.assign({}, roomInfo);
|
|
1728
|
+
this.emit('readyKeyframeSync', (roomInfo.last_frame || {}));
|
|
1523
1729
|
break;
|
|
1524
1730
|
}
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
}
|
|
1731
|
+
/**
|
|
1732
|
+
* 语音信息变化
|
|
1733
|
+
*/
|
|
1734
|
+
case Command.RTCInfo: {
|
|
1735
|
+
const { voice_id: voiceId, type } = data;
|
|
1736
|
+
this._buildInData.rtcInfo = { voiceId, type };
|
|
1737
|
+
if (!((_b = this.$RTC) === null || _b === void 0 ? void 0 : _b.joined)) {
|
|
1738
|
+
const result = yield ((_c = this.$RTC) === null || _c === void 0 ? void 0 : _c.join({
|
|
1739
|
+
voiceId,
|
|
1740
|
+
userId: ((_d = this.selfInfo) === null || _d === void 0 ? void 0 : _d.id) || '',
|
|
1741
|
+
roomId: (_e = this.roomInfo) === null || _e === void 0 ? void 0 : _e.info.room_code,
|
|
1742
|
+
type,
|
|
1743
|
+
}));
|
|
1744
|
+
if (result) {
|
|
1745
|
+
const status = (_f = this._options.initialMicroStatus) !== null && _f !== void 0 ? _f : MicroStatus.OPEN;
|
|
1746
|
+
yield ((_g = this.$RTC) === null || _g === void 0 ? void 0 : _g.toggleMicro(status === MicroStatus.OPEN));
|
|
1747
|
+
}
|
|
1748
|
+
else {
|
|
1749
|
+
logger$1.error('加入语音房间失败');
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
else {
|
|
1753
|
+
logger$1.warn('已加入语音房间,无需重复加入!');
|
|
1754
|
+
}
|
|
1755
|
+
break;
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* 房间用户列表变化
|
|
1759
|
+
*/
|
|
1760
|
+
case Command.UserList: {
|
|
1761
|
+
const userList = data;
|
|
1762
|
+
this._buildInData.userList = userList;
|
|
1763
|
+
this.emit('userListUpdate', this.userList, frontRequestId);
|
|
1764
|
+
break;
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* 自定义事件广播
|
|
1768
|
+
*/
|
|
1769
|
+
case Command.CustomEvent: {
|
|
1770
|
+
const evtMsg = data;
|
|
1771
|
+
this.emit('broadcast', evtMsg, frontRequestId);
|
|
1530
1772
|
break;
|
|
1531
1773
|
}
|
|
1774
|
+
/**
|
|
1775
|
+
* 帧数据同步
|
|
1776
|
+
*/
|
|
1777
|
+
case Command.KeyframeSync: {
|
|
1778
|
+
const remoteKeyframes = data;
|
|
1779
|
+
// 此处做一层 diff,仅跟本地数据不一致的情况下才广播数据。
|
|
1780
|
+
const keyframes = Object.keys(remoteKeyframes).reduce((accu, curr) => {
|
|
1781
|
+
if (equal(remoteKeyframes[curr], this._buildInData.keyframes[curr], {
|
|
1782
|
+
deep: true,
|
|
1783
|
+
})) {
|
|
1784
|
+
return accu;
|
|
1785
|
+
}
|
|
1786
|
+
const params = [
|
|
1787
|
+
remoteKeyframes[curr],
|
|
1788
|
+
this._buildInData.keyframes[curr],
|
|
1789
|
+
frontRequestId,
|
|
1790
|
+
];
|
|
1791
|
+
const evtName = curr;
|
|
1792
|
+
this.keyframes.emit(evtName, ...params);
|
|
1793
|
+
this._buildInData.keyframes[curr] = remoteKeyframes[curr];
|
|
1794
|
+
accu[curr] = remoteKeyframes[curr];
|
|
1795
|
+
return accu;
|
|
1796
|
+
}, {});
|
|
1797
|
+
this.emit('keyframes', keyframes, frontRequestId);
|
|
1798
|
+
break;
|
|
1799
|
+
}
|
|
1800
|
+
/**
|
|
1801
|
+
* 内置消息
|
|
1802
|
+
*/
|
|
1803
|
+
case Command.BuiltinMsg: {
|
|
1804
|
+
const builtinMsg = data;
|
|
1805
|
+
this.emit('builtinEvent', builtinMsg);
|
|
1806
|
+
if (builtinMsg.event_type === BuiltinEventType.UserChange) {
|
|
1807
|
+
this.emit('userChange', builtinMsg);
|
|
1808
|
+
}
|
|
1809
|
+
if (builtinMsg.event_type === BuiltinEventType.RoomChange) {
|
|
1810
|
+
this.emit('roomChange', builtinMsg);
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* 下发指令自己操作麦克风
|
|
1814
|
+
*/
|
|
1815
|
+
if (builtinMsg.event_type === BuiltinEventType.UserChange &&
|
|
1816
|
+
builtinMsg.action === BuiltinActionType.UserMicroStatus) {
|
|
1817
|
+
yield this.toggleMicro(builtinMsg.data.status === MicroStatus.OPEN);
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1820
|
+
* 如果下发指令退出房间,则 关闭麦克风 及 销毁 WebSocket
|
|
1821
|
+
*/
|
|
1822
|
+
if (builtinMsg.event_type === BuiltinEventType.RoomChange &&
|
|
1823
|
+
builtinMsg.action === BuiltinActionType.RoomClose) {
|
|
1824
|
+
yield this.exit();
|
|
1825
|
+
}
|
|
1826
|
+
break;
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* 被踢出房间
|
|
1830
|
+
*/
|
|
1831
|
+
case Command.UserKickOut: {
|
|
1832
|
+
this.emit('kickOut');
|
|
1833
|
+
break;
|
|
1834
|
+
}
|
|
1835
|
+
/**
|
|
1836
|
+
* 其它未知广播
|
|
1837
|
+
*/
|
|
1532
1838
|
default: {
|
|
1533
|
-
|
|
1839
|
+
console.warn('unknown command: ', command);
|
|
1534
1840
|
}
|
|
1535
1841
|
}
|
|
1536
1842
|
}
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
if (!options.getVoiceSign) {
|
|
1540
|
-
throw new Error('GetVoiceSign method must be passed when using built-in RTC instances');
|
|
1541
|
-
}
|
|
1542
|
-
var getVoiceSign = (_b = options.getVoiceSign) !== null && _b !== void 0 ? _b : unimplementedGetVoiceSign;
|
|
1543
|
-
if (!jsBridge) {
|
|
1544
|
-
throw new Error('jsBridge instance must be passed when using built-in RTC instances');
|
|
1545
|
-
}
|
|
1546
|
-
// vrwebview 默认
|
|
1547
|
-
if ((isRealseeVRWebview && (isAndroid || isIOS)) || isWxMiniProgram) {
|
|
1548
|
-
liveController.options.rtc = new VRWebViewRTC({
|
|
1549
|
-
jsBridge: jsBridge,
|
|
1550
|
-
getVoiceSign: getVoiceSign,
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
else {
|
|
1554
|
-
// 其它终端使用
|
|
1555
|
-
liveController.options.rtc =
|
|
1556
|
-
options.builtInRTCType === BuiltInRTCType.RealseeXChimeRTC
|
|
1557
|
-
? new BrowserRTC4Chime({ getVoiceSign: getVoiceSign })
|
|
1558
|
-
: new BrowserRTC({ getVoiceSign: getVoiceSign });
|
|
1559
|
-
}
|
|
1843
|
+
else {
|
|
1844
|
+
this.emit('error', liveMsg);
|
|
1560
1845
|
}
|
|
1561
1846
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1847
|
+
});
|
|
1848
|
+
/**
|
|
1849
|
+
* 清理带看缓存的数据
|
|
1850
|
+
*/
|
|
1851
|
+
this._clearLiveData = () => {
|
|
1852
|
+
this._buildInData = { keyframes: {} };
|
|
1853
|
+
};
|
|
1854
|
+
/**
|
|
1855
|
+
* 连接带看
|
|
1856
|
+
* @param options
|
|
1857
|
+
* @returns
|
|
1858
|
+
*/
|
|
1859
|
+
this.connect = (options = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
1860
|
+
var _h, _j, _k, _l;
|
|
1861
|
+
// 检查 url 和 票据获取接口实现
|
|
1862
|
+
this._options.url = (_j = (_h = options.url) !== null && _h !== void 0 ? _h : this._options.url) !== null && _j !== void 0 ? _j : '';
|
|
1863
|
+
this._options.getTicket = (_k = options.getTicket) !== null && _k !== void 0 ? _k : this._options.getTicket;
|
|
1864
|
+
this._options.initialMicroStatus =
|
|
1865
|
+
(_l = options.rtcMicStatus) !== null && _l !== void 0 ? _l : this._options.initialMicroStatus;
|
|
1866
|
+
if (!/^ws(s):\/\//.test(this._options.url) ||
|
|
1867
|
+
typeof this._options.getTicket !== 'function') {
|
|
1868
|
+
if (!/^ws(s):\/\//.test(this._options.url)) {
|
|
1869
|
+
return new Error('Illegal realsee live room link');
|
|
1870
|
+
}
|
|
1871
|
+
if (typeof this._options.getTicket !== 'function') {
|
|
1872
|
+
return new Error('getTicket muse be function');
|
|
1873
|
+
}
|
|
1874
|
+
return false;
|
|
1564
1875
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1876
|
+
const { force = false } = options;
|
|
1877
|
+
// 检测一下麦克风权限,hack
|
|
1878
|
+
if (this._options.rtc && this._options.jsBridge) {
|
|
1879
|
+
const res = yield this._options.jsBridge.detectMicro();
|
|
1880
|
+
if (!res) {
|
|
1881
|
+
return new Error('Failed to obtain microphone authorization');
|
|
1882
|
+
}
|
|
1568
1883
|
}
|
|
1569
|
-
//
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1884
|
+
// 检查是否已有实例在使用
|
|
1885
|
+
const currentState = this.state;
|
|
1886
|
+
if (currentState === LiveState.CONNECTING ||
|
|
1887
|
+
currentState === LiveState.OPEN) {
|
|
1888
|
+
if (force) {
|
|
1889
|
+
try {
|
|
1890
|
+
yield this._controller.close('force close by connect');
|
|
1891
|
+
}
|
|
1892
|
+
catch (e) {
|
|
1893
|
+
console.warn(e);
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
else {
|
|
1897
|
+
return new Error('已有Live实例正在连接中,请勿重复连接!');
|
|
1898
|
+
}
|
|
1583
1899
|
}
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
});
|
|
1593
|
-
Object.defineProperty(LiveTpl.prototype, "readyState", {
|
|
1594
|
-
get: function () {
|
|
1595
|
-
liveController.checkReadyState(this);
|
|
1596
|
-
return liveController.readyState;
|
|
1597
|
-
},
|
|
1598
|
-
enumerable: false,
|
|
1599
|
-
configurable: true
|
|
1900
|
+
// 建立连接
|
|
1901
|
+
this._clearLiveData();
|
|
1902
|
+
const url = appendUri(this._options.url, {
|
|
1903
|
+
ticket: yield this._options.getTicket(),
|
|
1904
|
+
force: Number(!!force),
|
|
1905
|
+
});
|
|
1906
|
+
this._controller.open(url);
|
|
1907
|
+
return true;
|
|
1600
1908
|
});
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1909
|
+
/**
|
|
1910
|
+
* 退出带看
|
|
1911
|
+
* @returns
|
|
1912
|
+
*/
|
|
1913
|
+
this.exit = () => __awaiter(this, void 0, void 0, function* () {
|
|
1914
|
+
var _m;
|
|
1915
|
+
this._clearLiveData();
|
|
1916
|
+
try {
|
|
1917
|
+
/** 退出强制关闭语音 */
|
|
1918
|
+
(_m = this.$RTC) === null || _m === void 0 ? void 0 : _m.quit();
|
|
1919
|
+
yield this.updateStatus(BuiltinEventType.RoomChange, BuiltinActionType.RoomClose, {});
|
|
1920
|
+
}
|
|
1921
|
+
catch (e) {
|
|
1922
|
+
logger$1.warn(e);
|
|
1923
|
+
}
|
|
1924
|
+
return yield this._controller.close('user exit');
|
|
1608
1925
|
});
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1926
|
+
/**
|
|
1927
|
+
* 销毁带看
|
|
1928
|
+
* @returns
|
|
1929
|
+
*/
|
|
1930
|
+
this.dispose = () => __awaiter(this, void 0, void 0, function* () {
|
|
1931
|
+
this._removeLiveControllerEventListeners();
|
|
1932
|
+
this._clearLiveData();
|
|
1933
|
+
return yield this._controller.dispose();
|
|
1615
1934
|
});
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1935
|
+
/**
|
|
1936
|
+
* 设置自己的用户信息
|
|
1937
|
+
* @param userInfo
|
|
1938
|
+
* @returns
|
|
1939
|
+
*/
|
|
1940
|
+
this.setSelfInfo = (userInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
1941
|
+
return yield this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserInfo, userInfo);
|
|
1622
1942
|
});
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1943
|
+
// 仅用于用户自己的麦克风控制
|
|
1944
|
+
this.toggleMicro = (microStatus) => __awaiter(this, void 0, void 0, function* () {
|
|
1945
|
+
var _o, _p, _q;
|
|
1946
|
+
if (!((_p = (_o = this.selfInfo) === null || _o === void 0 ? void 0 : _o.permission) === null || _p === void 0 ? void 0 : _p.control_own_micro))
|
|
1947
|
+
return false;
|
|
1948
|
+
const result = yield ((_q = this.$RTC) === null || _q === void 0 ? void 0 : _q.toggleMicro(microStatus));
|
|
1949
|
+
if (result) {
|
|
1950
|
+
yield this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserMicroStatus, {
|
|
1951
|
+
status: microStatus ? MicroStatus.OPEN : MicroStatus.CLOSE,
|
|
1952
|
+
}, []);
|
|
1953
|
+
}
|
|
1954
|
+
return result;
|
|
1629
1955
|
});
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1956
|
+
/**
|
|
1957
|
+
* 控制别人的麦
|
|
1958
|
+
* @param microStatus
|
|
1959
|
+
* @param toUserIds
|
|
1960
|
+
* @returns
|
|
1961
|
+
*/
|
|
1962
|
+
this.forbidMicro = (microStatus, toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1963
|
+
var _r, _s;
|
|
1964
|
+
if (typeof this._options.canForbidUserMicro === 'function' &&
|
|
1965
|
+
!this._options.canForbidUserMicro(toUserIds)) {
|
|
1966
|
+
return false;
|
|
1967
|
+
}
|
|
1968
|
+
if (!((_s = (_r = this.selfInfo) === null || _r === void 0 ? void 0 : _r.permission) === null || _s === void 0 ? void 0 : _s.control_other_micro)) {
|
|
1969
|
+
return false;
|
|
1970
|
+
}
|
|
1971
|
+
return yield this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserMicroStatus, {
|
|
1972
|
+
status: microStatus,
|
|
1973
|
+
}, toUserIds);
|
|
1636
1974
|
});
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1975
|
+
/**
|
|
1976
|
+
* 控制别人的同步全量帧数据权限
|
|
1977
|
+
* @param sync
|
|
1978
|
+
* @param toUserIds
|
|
1979
|
+
* @returns
|
|
1980
|
+
*/
|
|
1981
|
+
this.forbidSync = (sync, toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1982
|
+
var _t, _u;
|
|
1983
|
+
if (typeof this._options.canForbidUserSync === 'function' &&
|
|
1984
|
+
!this._options.canForbidUserSync(toUserIds)) {
|
|
1985
|
+
return false;
|
|
1986
|
+
}
|
|
1987
|
+
if (!((_u = (_t = this.selfInfo) === null || _t === void 0 ? void 0 : _t.permission) === null || _u === void 0 ? void 0 : _u.control_other_sync)) {
|
|
1988
|
+
return false;
|
|
1989
|
+
}
|
|
1990
|
+
return yield this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserPermission, { sync_frame: sync }, toUserIds);
|
|
1643
1991
|
});
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
case 1:
|
|
1655
|
-
_a.trys.push([1, 3, , 4]);
|
|
1656
|
-
return [4 /*yield*/, this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserInfo, userInfo)];
|
|
1657
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
1658
|
-
case 3:
|
|
1659
|
-
error_1 = _a.sent();
|
|
1660
|
-
return [2 /*return*/, error_1];
|
|
1661
|
-
case 4: return [2 /*return*/];
|
|
1662
|
-
}
|
|
1663
|
-
});
|
|
1664
|
-
});
|
|
1665
|
-
};
|
|
1666
|
-
LiveTpl.prototype.getFramesByKey = function (key) {
|
|
1667
|
-
return liveController.keyframes[key];
|
|
1668
|
-
};
|
|
1669
|
-
LiveTpl.prototype.sendKeyframe = function (key, frame) {
|
|
1670
|
-
if (this.readyState !== WebSocketState.OPEN) {
|
|
1671
|
-
return new Error('The connection is not open and ready to communicate.');
|
|
1992
|
+
/**
|
|
1993
|
+
* 把用户踢出带看
|
|
1994
|
+
* @param toUserIds
|
|
1995
|
+
* @returns
|
|
1996
|
+
*/
|
|
1997
|
+
this.kick = (toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1998
|
+
var _v, _w;
|
|
1999
|
+
if (typeof this._options.canForbidUserKick === 'function' &&
|
|
2000
|
+
!this._options.canForbidUserKick(toUserIds)) {
|
|
2001
|
+
return false;
|
|
1672
2002
|
}
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
liveController.sendMessage(liveMsg);
|
|
1676
|
-
return true;
|
|
1677
|
-
};
|
|
1678
|
-
LiveTpl.prototype.broadcast = function (data, toUserIds, timeout) {
|
|
1679
|
-
var _this = this;
|
|
1680
|
-
if (this.readyState !== WebSocketState.OPEN) {
|
|
1681
|
-
return new Error('The connection is not open and ready to communicate.');
|
|
2003
|
+
if (!((_w = (_v = this.selfInfo) === null || _v === void 0 ? void 0 : _v.permission) === null || _w === void 0 ? void 0 : _w.change_other_status)) {
|
|
2004
|
+
return false;
|
|
1682
2005
|
}
|
|
1683
|
-
return
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1723
|
-
return __generator(this, function (_c) {
|
|
1724
|
-
switch (_c.label) {
|
|
1725
|
-
case 0:
|
|
1726
|
-
if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.control_own_micro))
|
|
1727
|
-
return [2 /*return*/, false];
|
|
1728
|
-
return [4 /*yield*/, this.$RTC.toggleMicro(microStatus)];
|
|
1729
|
-
case 1:
|
|
1730
|
-
_c.sent();
|
|
1731
|
-
return [4 /*yield*/, this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserMicroStatus, {
|
|
1732
|
-
status: microStatus ? MicroStatus.OPEN : MicroStatus.CLOSE,
|
|
1733
|
-
}, [])];
|
|
1734
|
-
case 2: return [2 /*return*/, _c.sent()];
|
|
2006
|
+
return yield this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserStatus, {
|
|
2007
|
+
status: 'KICK_OUT',
|
|
2008
|
+
}, toUserIds);
|
|
2009
|
+
});
|
|
2010
|
+
this._addLiveControllerEventListeners();
|
|
2011
|
+
this._options = Object.assign({ initialMicroStatus: MicroStatus.OPEN }, opts);
|
|
2012
|
+
// 第一步检查jsbridge
|
|
2013
|
+
this._options.jsBridge = (() => {
|
|
2014
|
+
if (opts.jsBridge)
|
|
2015
|
+
return opts.jsBridge;
|
|
2016
|
+
if (opts.useBuiltInJsBridge)
|
|
2017
|
+
return new JSBridge();
|
|
2018
|
+
return undefined;
|
|
2019
|
+
})();
|
|
2020
|
+
// 第二步检查getVoiceSign
|
|
2021
|
+
this._options.getVoiceSign = (_a = opts.getVoiceSign) !== null && _a !== void 0 ? _a : unimplementedGetVoiceSign;
|
|
2022
|
+
// 第二步检查rtc
|
|
2023
|
+
this._options.rtc = (() => {
|
|
2024
|
+
// 优先取rtc实例
|
|
2025
|
+
if (opts.rtc)
|
|
2026
|
+
return opts.rtc;
|
|
2027
|
+
// 取指定的内部rtc类型
|
|
2028
|
+
if (opts.rtcType) {
|
|
2029
|
+
if (!opts.getVoiceSign) {
|
|
2030
|
+
logger$1.error('GetVoiceSign method must be passed when using built-in RTC instances');
|
|
2031
|
+
}
|
|
2032
|
+
switch (opts.rtcType) {
|
|
2033
|
+
case RTCType.RealseeVRWebViewRTC: {
|
|
2034
|
+
// 内置的 VRWebViewRTC
|
|
2035
|
+
if (this._options.jsBridge) {
|
|
2036
|
+
return new VRWebViewRTC({
|
|
2037
|
+
jsBridge: this._options.jsBridge,
|
|
2038
|
+
getVoiceSign: this._options.getVoiceSign,
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
else {
|
|
2042
|
+
logger$1.error('JsBridge instance must be passed when using built-in VRWebViewRTC instances');
|
|
2043
|
+
return undefined;
|
|
2044
|
+
}
|
|
1735
2045
|
}
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
return __generator(this, function (_c) {
|
|
1743
|
-
switch (_c.label) {
|
|
1744
|
-
case 0:
|
|
1745
|
-
if (liveController.options.canForbidUserMicro &&
|
|
1746
|
-
!liveController.options.canForbidUserMicro(toUserIds)) {
|
|
1747
|
-
return [2 /*return*/, false];
|
|
1748
|
-
}
|
|
1749
|
-
if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.control_other_micro)) {
|
|
1750
|
-
return [2 /*return*/, false];
|
|
1751
|
-
}
|
|
1752
|
-
return [4 /*yield*/, this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserMicroStatus, {
|
|
1753
|
-
status: microStatus,
|
|
1754
|
-
}, toUserIds)];
|
|
1755
|
-
case 1: return [2 /*return*/, _c.sent()];
|
|
2046
|
+
case RTCType.RealseeBrowserChimeRTC: {
|
|
2047
|
+
// 内置的 RealseeBrowserChimeRTC
|
|
2048
|
+
return new BrowserRTC4Chime({
|
|
2049
|
+
getVoiceSign: this._options.getVoiceSign,
|
|
2050
|
+
logLevel: opts.__debug__ ? LogLevel.DEBUG : LogLevel.ERROR,
|
|
2051
|
+
});
|
|
1756
2052
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
*/
|
|
1763
|
-
LiveTpl.prototype.forbidSync = function (sync, toUserIds) {
|
|
1764
|
-
var _a, _b;
|
|
1765
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1766
|
-
return __generator(this, function (_c) {
|
|
1767
|
-
switch (_c.label) {
|
|
1768
|
-
case 0:
|
|
1769
|
-
if (liveController.options.canForbidUserSync &&
|
|
1770
|
-
!liveController.options.canForbidUserSync(toUserIds)) {
|
|
1771
|
-
return [2 /*return*/, false];
|
|
1772
|
-
}
|
|
1773
|
-
if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.control_other_sync)) {
|
|
1774
|
-
return [2 /*return*/, false];
|
|
1775
|
-
}
|
|
1776
|
-
return [4 /*yield*/, this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserPermission, { sync_frame: sync }, toUserIds)];
|
|
1777
|
-
case 1: return [2 /*return*/, _c.sent()];
|
|
2053
|
+
case RTCType.RealseeBrowserRTC: {
|
|
2054
|
+
// 内置的 RealseeBrowserRTC
|
|
2055
|
+
return new BrowserRTC({
|
|
2056
|
+
getVoiceSign: this._options.getVoiceSign,
|
|
2057
|
+
});
|
|
1778
2058
|
}
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
LiveTpl.prototype.kick = function (toUserIds) {
|
|
1783
|
-
var _a, _b;
|
|
1784
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1785
|
-
return __generator(this, function (_c) {
|
|
1786
|
-
switch (_c.label) {
|
|
1787
|
-
case 0:
|
|
1788
|
-
if (liveController.options.canForbidUserKick &&
|
|
1789
|
-
!liveController.options.canForbidUserKick(toUserIds)) {
|
|
1790
|
-
return [2 /*return*/, false];
|
|
1791
|
-
}
|
|
1792
|
-
if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.change_other_status)) {
|
|
1793
|
-
return [2 /*return*/, false];
|
|
1794
|
-
}
|
|
1795
|
-
return [4 /*yield*/, this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserStatus, {
|
|
1796
|
-
status: 'KICK_OUT',
|
|
1797
|
-
}, toUserIds)];
|
|
1798
|
-
case 1: return [2 /*return*/, _c.sent()];
|
|
2059
|
+
default: {
|
|
2060
|
+
logger$1.error('unknown built-in RTC type');
|
|
2061
|
+
return undefined;
|
|
1799
2062
|
}
|
|
1800
|
-
}
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
this
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
_a.sent();
|
|
1814
|
-
return [3 /*break*/, 3];
|
|
1815
|
-
case 2:
|
|
1816
|
-
e_1 = _a.sent();
|
|
1817
|
-
console.log(e_1);
|
|
1818
|
-
return [3 /*break*/, 3];
|
|
1819
|
-
case 3: return [2 /*return*/, liveController.dispose()];
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
// 都不满足时取内置
|
|
2066
|
+
if (opts.useBuiltInRTC) {
|
|
2067
|
+
if (!opts.getVoiceSign) {
|
|
2068
|
+
logger$1.error('GetVoiceSign method must be passed when using built-in RTC instances');
|
|
2069
|
+
}
|
|
2070
|
+
if (this._options.jsBridge) {
|
|
2071
|
+
if ((isRealseeVRWebview && (isAndroid || isIOS)) || isWxMiniProgram) {
|
|
2072
|
+
return new VRWebViewRTC({
|
|
2073
|
+
jsBridge: this._options.jsBridge,
|
|
2074
|
+
getVoiceSign: this._options.getVoiceSign,
|
|
2075
|
+
});
|
|
1820
2076
|
}
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
var _d;
|
|
1829
|
-
var _this = this;
|
|
1830
|
-
return __generator(this, function (_e) {
|
|
1831
|
-
switch (_e.label) {
|
|
1832
|
-
case 0: return [4 /*yield*/, this.$RTC.detectMicro()];
|
|
1833
|
-
case 1:
|
|
1834
|
-
microAuth = _e.sent();
|
|
1835
|
-
if (!microAuth) {
|
|
1836
|
-
error = new Error('系统监测麦克风未授权~');
|
|
1837
|
-
this.emit('ws.error', { type: WebSocketErrorType.MicroAuth, error: error });
|
|
1838
|
-
return [2 /*return*/, error];
|
|
1839
|
-
}
|
|
1840
|
-
// WebSocket 正在连接中,规避重复连接
|
|
1841
|
-
if (liveController.connecting) {
|
|
1842
|
-
error = new Error('WebSocket 正在连接中,请勿重复连接 ...');
|
|
1843
|
-
this.emit('ws.error', {
|
|
1844
|
-
type: WebSocketErrorType.DuplicateConnect,
|
|
1845
|
-
error: error,
|
|
1846
|
-
});
|
|
1847
|
-
return [2 /*return*/, error];
|
|
1848
|
-
}
|
|
1849
|
-
force = options.force;
|
|
1850
|
-
if (!force) {
|
|
1851
|
-
if (this.readyState === WebSocketState.CONNECTING ||
|
|
1852
|
-
this.readyState === WebSocketState.OPEN) {
|
|
1853
|
-
return [2 /*return*/, true];
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
// WebSocket URL 逻辑
|
|
1857
|
-
if (options.url) {
|
|
1858
|
-
liveController.options.url = options.url;
|
|
1859
|
-
}
|
|
1860
|
-
if (options.getTicket) {
|
|
1861
|
-
liveController.options.getTicket = options.getTicket;
|
|
1862
|
-
}
|
|
1863
|
-
if (!liveController.options.url ||
|
|
1864
|
-
!liveController.options.url.startsWith('ws')) {
|
|
1865
|
-
error = new Error("WebSocket URL \u672A\u914D\u7F6E\u6216\u683C\u5F0F\u4E0D\u5408\u6CD5\uFF1A\"".concat(liveController.options.url, "\""));
|
|
1866
|
-
this.emit('ws.error', { type: WebSocketErrorType.IllegalURL, error: error });
|
|
1867
|
-
return [2 /*return*/, error];
|
|
1868
|
-
}
|
|
1869
|
-
if (!liveController.options.getTicket) {
|
|
1870
|
-
error = new Error("getTicket() \u672A\u914D\u7F6E!");
|
|
1871
|
-
this.emit('ws.error', { type: WebSocketErrorType.IllegalArgs, error: error });
|
|
1872
|
-
return [2 /*return*/, error];
|
|
1873
|
-
}
|
|
1874
|
-
// 连接锁
|
|
1875
|
-
liveController.connecting = true;
|
|
1876
|
-
// 连接前销毁之前绑定的事件
|
|
1877
|
-
liveController.disposeWebSocket();
|
|
1878
|
-
this.emit('ws.beforeConnect');
|
|
1879
|
-
if (!(force || options.url || !this.url)) return [3 /*break*/, 3];
|
|
1880
|
-
_b = appendUri;
|
|
1881
|
-
_c = [liveController.options.url];
|
|
1882
|
-
_d = {};
|
|
1883
|
-
return [4 /*yield*/, liveController.options.getTicket()];
|
|
1884
|
-
case 2:
|
|
1885
|
-
_a = _b.apply(void 0, _c.concat([(_d.ticket = _e.sent(),
|
|
1886
|
-
_d.force = Number(!!force),
|
|
1887
|
-
_d)]));
|
|
1888
|
-
return [3 /*break*/, 4];
|
|
1889
|
-
case 3:
|
|
1890
|
-
_a = this.url;
|
|
1891
|
-
_e.label = 4;
|
|
1892
|
-
case 4:
|
|
1893
|
-
url = _a;
|
|
1894
|
-
liveController.webSocket = new WebSocket(url);
|
|
1895
|
-
liveController.onEvtOpnListener = function () {
|
|
1896
|
-
liveController.checkReadyState(_this);
|
|
1897
|
-
_this.emit('ws.afterConnect');
|
|
1898
|
-
};
|
|
1899
|
-
liveController.onEvtMsgListener = function (evt) {
|
|
1900
|
-
liveController.checkReadyState(_this);
|
|
1901
|
-
try {
|
|
1902
|
-
var liveMsg = parseLiveMsg(evt.data);
|
|
1903
|
-
if (liveMsg === false)
|
|
1904
|
-
return;
|
|
1905
|
-
liveController.handleMessage(liveMsg, _this);
|
|
1906
|
-
}
|
|
1907
|
-
catch (error) {
|
|
1908
|
-
// 未知错误
|
|
1909
|
-
_this.emit('ws.error', {
|
|
1910
|
-
type: WebSocketErrorType.Unknown,
|
|
1911
|
-
error: error,
|
|
1912
|
-
target: evt,
|
|
1913
|
-
});
|
|
1914
|
-
}
|
|
1915
|
-
};
|
|
1916
|
-
liveController.onEvtErrListener = function (evt) {
|
|
1917
|
-
live.emit('ws.error', { type: WebSocketErrorType.Error, target: evt });
|
|
1918
|
-
liveController.checkReadyState(_this);
|
|
1919
|
-
};
|
|
1920
|
-
liveController.onEvtCLEListener = function (evt) {
|
|
1921
|
-
liveController.checkReadyState(_this);
|
|
1922
|
-
var code = Number(evt.code);
|
|
1923
|
-
if (code === 1000)
|
|
1924
|
-
return;
|
|
1925
|
-
// 异常退出不一定会触发'error'事件,根据 evt.code 一些类型的退出也算是 error 行为
|
|
1926
|
-
var errMsg = parseWSClsErr(code);
|
|
1927
|
-
live.emit('ws.error', {
|
|
1928
|
-
target: evt,
|
|
1929
|
-
type: WebSocketErrorType.Close,
|
|
1930
|
-
closeError: errMsg,
|
|
1931
|
-
});
|
|
1932
|
-
};
|
|
1933
|
-
liveController.webSocket.addEventListener('open', liveController.onEvtOpnListener);
|
|
1934
|
-
liveController.webSocket.addEventListener('message', liveController.onEvtMsgListener);
|
|
1935
|
-
liveController.webSocket.addEventListener('error', liveController.onEvtErrListener);
|
|
1936
|
-
liveController.webSocket.addEventListener('close', liveController.onEvtCLEListener);
|
|
1937
|
-
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
1938
|
-
var success = function () {
|
|
1939
|
-
resolve(true);
|
|
1940
|
-
liveController.connecting = false;
|
|
1941
|
-
_this.off('ws.error', fail);
|
|
1942
|
-
};
|
|
1943
|
-
var fail = function (error) {
|
|
1944
|
-
reject(error.error
|
|
1945
|
-
? error.error
|
|
1946
|
-
: new Error('WebSocket connection failed!'));
|
|
1947
|
-
liveController.connecting = false;
|
|
1948
|
-
_this.off('ws.afterConnect', success);
|
|
1949
|
-
};
|
|
1950
|
-
_this.once('ws.afterConnect', success);
|
|
1951
|
-
_this.once('ws.error', fail);
|
|
1952
|
-
})];
|
|
1953
|
-
case 5: return [2 /*return*/, _e.sent()];
|
|
2077
|
+
else {
|
|
2078
|
+
// 其它终端使用
|
|
2079
|
+
return opts.builtInRTCType === BuiltInRTCType.RealseeXChimeRTC
|
|
2080
|
+
? new BrowserRTC4Chime({
|
|
2081
|
+
getVoiceSign: this._options.getVoiceSign,
|
|
2082
|
+
})
|
|
2083
|
+
: new BrowserRTC({ getVoiceSign: this._options.getVoiceSign });
|
|
1954
2084
|
}
|
|
1955
|
-
}
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
2085
|
+
}
|
|
2086
|
+
else {
|
|
2087
|
+
logger$1.error('jsBridge instance must be passed when using built-in RTC instances');
|
|
2088
|
+
return undefined;
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
return undefined;
|
|
2092
|
+
})();
|
|
2093
|
+
if (!this._options.rtc) {
|
|
2094
|
+
logger$1.warn('unused rtc');
|
|
2095
|
+
}
|
|
2096
|
+
// 第三步进行自动连接
|
|
2097
|
+
if (this._options.url && this._options.getTicket) {
|
|
2098
|
+
this.connect();
|
|
2099
|
+
}
|
|
2100
|
+
if (this._options.__debug__) {
|
|
2101
|
+
Object.assign(window, { $liveController: this._controller, $live: this });
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
get options() {
|
|
2105
|
+
return Object.freeze(this._options || {});
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* 带看状态
|
|
2109
|
+
*/
|
|
2110
|
+
get state() {
|
|
2111
|
+
return this._controller.state;
|
|
2112
|
+
}
|
|
2113
|
+
/**
|
|
2114
|
+
* 兼容老逻辑
|
|
2115
|
+
* @deprecated 请直接读取 state 属性字段,未来将移除该属性
|
|
2116
|
+
*/
|
|
2117
|
+
get readyState() {
|
|
2118
|
+
return this._controller.state;
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* 获取当前WebSocket连接的URL。(注意:这个是WebSocket连接的完整连接,附带一些query参数)。
|
|
2122
|
+
* @deprecated 带看不需要关注底层ws的相关信息,未来将移除
|
|
2123
|
+
*/
|
|
2124
|
+
get url() {
|
|
2125
|
+
return this.options.url;
|
|
2126
|
+
}
|
|
2127
|
+
/**
|
|
2128
|
+
* 获取当前live使用的RTC实例
|
|
2129
|
+
*/
|
|
2130
|
+
get $RTC() {
|
|
2131
|
+
return this._options.rtc;
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* 获取当前live使用的jsBridge实例
|
|
2135
|
+
*/
|
|
2136
|
+
get jsBridge() {
|
|
2137
|
+
return this._options.jsBridge;
|
|
2138
|
+
}
|
|
2139
|
+
/**
|
|
2140
|
+
* 当前帧数据快照
|
|
2141
|
+
*/
|
|
2142
|
+
get snapshot() {
|
|
2143
|
+
return this._buildInData.keyframes;
|
|
2144
|
+
}
|
|
2145
|
+
/**
|
|
2146
|
+
* 当前用户信息
|
|
2147
|
+
*/
|
|
2148
|
+
get selfInfo() {
|
|
2149
|
+
return this._buildInData.selfInfo;
|
|
2150
|
+
}
|
|
2151
|
+
/**
|
|
2152
|
+
* 当前用户列表
|
|
2153
|
+
*/
|
|
2154
|
+
get userList() {
|
|
2155
|
+
return this._buildInData.userList || [];
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* 当前带看房间信息
|
|
2159
|
+
*/
|
|
2160
|
+
get roomInfo() {
|
|
2161
|
+
return this._buildInData.roomInfo;
|
|
2162
|
+
}
|
|
2163
|
+
/**
|
|
2164
|
+
* 修改状态
|
|
2165
|
+
* @param evtType
|
|
2166
|
+
* @param atnType
|
|
2167
|
+
* @param status
|
|
2168
|
+
* @param toUserIds
|
|
2169
|
+
* @returns
|
|
2170
|
+
*/
|
|
2171
|
+
updateStatus(evtType, atnType, status, toUserIds) {
|
|
2172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2173
|
+
if (this.state !== LiveState.OPEN)
|
|
2174
|
+
return false;
|
|
2175
|
+
const data = Object.assign({ event_type: evtType, action: atnType }, { data: status });
|
|
2176
|
+
const liveMsg = createLiveMsg(Command.BuiltinMsg, data, toUserIds);
|
|
2177
|
+
try {
|
|
2178
|
+
this._controller.sendMessage(liveMsg);
|
|
2179
|
+
return true;
|
|
2180
|
+
}
|
|
2181
|
+
catch (e) {
|
|
2182
|
+
logger$1.error(e);
|
|
2183
|
+
return false;
|
|
2184
|
+
}
|
|
2185
|
+
});
|
|
2186
|
+
}
|
|
2187
|
+
/**
|
|
2188
|
+
* 自定义广播
|
|
2189
|
+
* @param request 广播请求的数据
|
|
2190
|
+
* @param toUserIds
|
|
2191
|
+
* @param timeout
|
|
2192
|
+
* @returns
|
|
2193
|
+
*/
|
|
2194
|
+
broadcast(request, toUserIds, timeout) {
|
|
2195
|
+
if (this.state !== LiveState.OPEN)
|
|
2196
|
+
return false;
|
|
2197
|
+
return new Promise((resolve, reject) => {
|
|
2198
|
+
const customEvent = createLiveMsg(Command.CustomEvent, request, toUserIds);
|
|
2199
|
+
const front_request_id = customEvent.front_request_id;
|
|
2200
|
+
const timeoutId = timeout
|
|
2201
|
+
? setTimeout(() => {
|
|
2202
|
+
reject(new Error('RESPONSE TIMEOUT'));
|
|
2203
|
+
this.off('broadcast', broadcastRes);
|
|
2204
|
+
}, timeout)
|
|
2205
|
+
: undefined;
|
|
2206
|
+
const broadcastRes = (data, frontRequestId) => {
|
|
2207
|
+
if (frontRequestId !== front_request_id)
|
|
2208
|
+
return;
|
|
2209
|
+
if (timeoutId)
|
|
2210
|
+
clearTimeout(timeoutId);
|
|
2211
|
+
this.off('broadcast', broadcastRes);
|
|
2212
|
+
resolve(data);
|
|
2213
|
+
};
|
|
2214
|
+
this.on('broadcast', broadcastRes);
|
|
2215
|
+
try {
|
|
2216
|
+
this._controller.sendMessage(customEvent);
|
|
2217
|
+
}
|
|
2218
|
+
catch (e) {
|
|
2219
|
+
reject(e);
|
|
2220
|
+
}
|
|
2221
|
+
});
|
|
2222
|
+
}
|
|
1974
2223
|
}
|
|
1975
2224
|
|
|
2225
|
+
/**
|
|
2226
|
+
* 创建`Live`实例
|
|
2227
|
+
* @param opts
|
|
2228
|
+
* @returns
|
|
2229
|
+
*/
|
|
2230
|
+
const createLive = (opts) => {
|
|
2231
|
+
_clearLiveInstanceIfNeed();
|
|
2232
|
+
return new Live(opts);
|
|
2233
|
+
};
|
|
2234
|
+
|
|
1976
2235
|
/**
|
|
1977
2236
|
* 创建 {@link LiveReact} 实例,并提供 `React` 技术栈相关工具链。
|
|
1978
2237
|
*/
|
|
1979
2238
|
function createLiveReact(options) {
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2239
|
+
const LiveContext = createContext(null);
|
|
2240
|
+
const live = createLive(options);
|
|
2241
|
+
const jsBridge = live.jsBridge;
|
|
2242
|
+
const LiveProvider = (props) => (React.createElement(LiveContext.Provider, { value: live }, props.children));
|
|
2243
|
+
/**
|
|
2244
|
+
* 使用live实例
|
|
2245
|
+
* @returns
|
|
2246
|
+
*/
|
|
2247
|
+
const useLiveInstance = () => {
|
|
2248
|
+
const context = React.useContext(LiveContext);
|
|
1988
2249
|
if (!context)
|
|
1989
2250
|
throw new Error('LiveProvider never found.');
|
|
1990
2251
|
return context;
|
|
1991
|
-
}
|
|
2252
|
+
};
|
|
1992
2253
|
/**
|
|
2254
|
+
* 不建议这样使用
|
|
1993
2255
|
* @deprecated
|
|
1994
2256
|
* @returns
|
|
1995
2257
|
*/
|
|
1996
|
-
|
|
1997
|
-
return useLiveInstance();
|
|
1998
|
-
}
|
|
1999
|
-
function useRTCInstance() {
|
|
2000
|
-
var live = useLiveInstance();
|
|
2001
|
-
return live.$RTC;
|
|
2002
|
-
}
|
|
2258
|
+
const unsafe__useLiveInstance = () => useLiveInstance();
|
|
2003
2259
|
/**
|
|
2260
|
+
* 使用rtc实例
|
|
2261
|
+
*/
|
|
2262
|
+
const useRTCInstance = () => useLiveInstance().$RTC;
|
|
2263
|
+
/**
|
|
2264
|
+
* 不建议这样使用
|
|
2004
2265
|
* @deprecated
|
|
2005
2266
|
* @returns
|
|
2006
2267
|
*/
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
React.useEffect(
|
|
2024
|
-
|
|
2025
|
-
live.on('ws.beforeConnect', onWSBeforeConnect);
|
|
2026
|
-
return function () { return live.off('ws.beforeConnect', onWSBeforeConnect); };
|
|
2027
|
-
}, [live]);
|
|
2028
|
-
return state;
|
|
2029
|
-
}
|
|
2030
|
-
function useKeyframeUpdateCallback(name, callback, deps) {
|
|
2031
|
-
if (deps === void 0) { deps = []; }
|
|
2032
|
-
var live = useLiveInstance();
|
|
2033
|
-
var dependencyList = __spreadArray([live, name], deps, true);
|
|
2034
|
-
var dispose = function () { return live.keyframes.off(name, callback); };
|
|
2035
|
-
React.useEffect(function () {
|
|
2036
|
-
live.keyframes.on(name, callback);
|
|
2268
|
+
const unsafe__useRTCInstance = () => useRTCInstance();
|
|
2269
|
+
/**
|
|
2270
|
+
* 带看连接操作
|
|
2271
|
+
*/
|
|
2272
|
+
const useConnect = (options) => __awaiter(this, void 0, void 0, function* () { return yield useLiveInstance().connect(options); });
|
|
2273
|
+
/**
|
|
2274
|
+
*
|
|
2275
|
+
* @param name
|
|
2276
|
+
* @param callback
|
|
2277
|
+
* @param deps
|
|
2278
|
+
* @returns
|
|
2279
|
+
*/
|
|
2280
|
+
function useKeyframeUpdateCallback(key, callback, deps = []) {
|
|
2281
|
+
const live = useLiveInstance();
|
|
2282
|
+
const dependencyList = [live, name, ...deps];
|
|
2283
|
+
const dispose = () => live.keyframes.off(key, callback);
|
|
2284
|
+
React.useEffect(() => {
|
|
2285
|
+
live.keyframes.on(key, callback);
|
|
2037
2286
|
return dispose;
|
|
2038
2287
|
}, dependencyList);
|
|
2039
2288
|
return dispose;
|
|
2040
2289
|
}
|
|
2290
|
+
/**
|
|
2291
|
+
* 带看的一些操作
|
|
2292
|
+
* @returns
|
|
2293
|
+
*/
|
|
2041
2294
|
function useLiveAction() {
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
}, [live]);
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
// (sync: boolean, toUserIds?: string | string[] | undefined) =>
|
|
2055
|
-
// live.forbidSync(sync, toUserIds),
|
|
2056
|
-
// [live],
|
|
2057
|
-
// );
|
|
2058
|
-
var getFramesByKey = React.useCallback(function (key) { return live.getFramesByKey(key); }, [live]);
|
|
2059
|
-
var sendKeyframe = React.useCallback(function (key, frame) {
|
|
2060
|
-
return live.sendKeyframe(key, frame);
|
|
2061
|
-
}, [live]);
|
|
2062
|
-
var setSelfInfo = React.useCallback(function (userInfo) { return live.setSelfInfo(userInfo); }, [live]);
|
|
2063
|
-
var updateStatus = React.useCallback(function (evtType, atnType, status, toUserIds) { return live.updateStatus(evtType, atnType, status, toUserIds); }, [live]);
|
|
2295
|
+
const live = useLiveInstance();
|
|
2296
|
+
const connect = React.useCallback((options) => __awaiter(this, void 0, void 0, function* () { return yield live.connect(options); }), [live]);
|
|
2297
|
+
const toggleMicro = React.useCallback((microStatus) => live.toggleMicro(microStatus), [live]);
|
|
2298
|
+
const broadcast = React.useCallback((data, toUserIds, timeout = 0) => __awaiter(this, void 0, void 0, function* () { return yield live.broadcast(data, toUserIds, timeout); }), [live]);
|
|
2299
|
+
const exit = React.useCallback(() => __awaiter(this, void 0, void 0, function* () { return yield live.exit(); }), [live]);
|
|
2300
|
+
const kick = React.useCallback((toUserIds) => __awaiter(this, void 0, void 0, function* () { return yield live.kick(toUserIds); }), [live]);
|
|
2301
|
+
const forbidMicro = React.useCallback((micro, toUserIds = []) => __awaiter(this, void 0, void 0, function* () { return yield live.forbidMicro(micro, toUserIds); }), [live]);
|
|
2302
|
+
const forbidSync = React.useCallback((sync, toUserIds = []) => live.forbidSync(sync, toUserIds), [live]);
|
|
2303
|
+
const getFramesByKey = React.useCallback((key) => live.getFramesByKey(key), [live]);
|
|
2304
|
+
const sendKeyframe = React.useCallback((key, frame) => live.sendKeyframe(key, frame), [live]);
|
|
2305
|
+
const setSelfInfo = React.useCallback((userInfo) => live.setSelfInfo(userInfo), [live]);
|
|
2306
|
+
const updateStatus = React.useCallback((evtType, atnType, status, toUserIds) => live.updateStatus(evtType, atnType, status, toUserIds), [live]);
|
|
2064
2307
|
return {
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2308
|
+
connect,
|
|
2309
|
+
broadcast,
|
|
2310
|
+
exit,
|
|
2311
|
+
kick,
|
|
2312
|
+
toggleMicro,
|
|
2313
|
+
forbidMicro,
|
|
2314
|
+
forbidSync,
|
|
2315
|
+
sendKeyframe,
|
|
2316
|
+
getFramesByKey,
|
|
2317
|
+
setSelfInfo,
|
|
2318
|
+
updateStatus,
|
|
2075
2319
|
};
|
|
2076
2320
|
}
|
|
2077
2321
|
function useKeyframe(key) {
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
React.useEffect(
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
var evtName = key;
|
|
2085
|
-
var callback = onUpdate;
|
|
2322
|
+
const live = useLiveInstance();
|
|
2323
|
+
const [state, updateState] = React.useState(live.getFramesByKey(key));
|
|
2324
|
+
React.useEffect(() => {
|
|
2325
|
+
const onUpdate = (nextKeyframes) => updateState(nextKeyframes);
|
|
2326
|
+
const evtName = key;
|
|
2327
|
+
const callback = onUpdate;
|
|
2086
2328
|
live.keyframes.on(evtName, callback);
|
|
2087
|
-
return
|
|
2329
|
+
return () => live.keyframes.off(evtName, callback);
|
|
2088
2330
|
}, [live]);
|
|
2089
|
-
|
|
2331
|
+
const setState = React.useCallback((frame) => live.sendKeyframe(key, frame), [live]);
|
|
2090
2332
|
return [state, setState];
|
|
2091
2333
|
}
|
|
2092
|
-
function useLiveEventCallback(name, callback, deps) {
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
React.useEffect(function () {
|
|
2334
|
+
function useLiveEventCallback(name, callback, deps = []) {
|
|
2335
|
+
const live = useLiveInstance();
|
|
2336
|
+
const dispose = () => live.off(name, callback);
|
|
2337
|
+
const dependencyList = [live, name, ...deps];
|
|
2338
|
+
React.useEffect(() => {
|
|
2098
2339
|
live.on(name, callback);
|
|
2099
2340
|
return dispose;
|
|
2100
2341
|
}, dependencyList);
|
|
2101
2342
|
return dispose;
|
|
2102
2343
|
}
|
|
2103
2344
|
/**
|
|
2104
|
-
*
|
|
2345
|
+
* 带看状态
|
|
2105
2346
|
* @returns
|
|
2106
2347
|
*/
|
|
2107
|
-
function
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
React.useEffect(
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
live.on('ws.readyStateUpdate', readyStateUpdate);
|
|
2115
|
-
return function () { return live.off('ws.readyStateUpdate', readyStateUpdate); };
|
|
2348
|
+
function useLiveState() {
|
|
2349
|
+
const live = useLiveInstance();
|
|
2350
|
+
const [state, updateState] = React.useState(live.state);
|
|
2351
|
+
React.useEffect(() => {
|
|
2352
|
+
const stateChange = (state) => updateState(state);
|
|
2353
|
+
live.on('stateChange', stateChange);
|
|
2354
|
+
return () => live.off('stateChange', stateChange);
|
|
2116
2355
|
}, [live]);
|
|
2117
2356
|
return state;
|
|
2118
2357
|
}
|
|
2119
2358
|
function useRTCAction() {
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2359
|
+
const live = useLiveInstance();
|
|
2360
|
+
const join = React.useCallback((options) => live.$RTC.join(options), [live]);
|
|
2361
|
+
const quit = React.useCallback(() => live.$RTC.quit(), [live]);
|
|
2362
|
+
const shock = React.useCallback(() => { var _a, _b; return (_b = (_a = live.$RTC).shock) === null || _b === void 0 ? void 0 : _b.call(_a); }, [live]);
|
|
2363
|
+
const toggleMicro = React.useCallback((flag) => live.$RTC.toggleMicro(flag), [live]);
|
|
2364
|
+
const detectMicro = React.useCallback(() => live.$RTC.detectMicro(), [live]);
|
|
2126
2365
|
return {
|
|
2127
|
-
join
|
|
2128
|
-
quit
|
|
2129
|
-
shock
|
|
2130
|
-
toggleMicro
|
|
2131
|
-
detectMicro
|
|
2366
|
+
join,
|
|
2367
|
+
quit,
|
|
2368
|
+
shock,
|
|
2369
|
+
toggleMicro,
|
|
2370
|
+
detectMicro,
|
|
2132
2371
|
};
|
|
2133
2372
|
}
|
|
2134
|
-
function useRTCEventCallback(name, callback, deps) {
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
React.useEffect(function () {
|
|
2373
|
+
function useRTCEventCallback(name, callback, deps = []) {
|
|
2374
|
+
const live = useLiveInstance();
|
|
2375
|
+
const dispose = () => live.$RTC.off(name, callback);
|
|
2376
|
+
const dependencyList = [live, name, ...deps];
|
|
2377
|
+
React.useEffect(() => {
|
|
2140
2378
|
live.$RTC.on(name, callback);
|
|
2141
2379
|
return dispose;
|
|
2142
2380
|
}, dependencyList);
|
|
2143
2381
|
return dispose;
|
|
2144
2382
|
}
|
|
2145
2383
|
function useSelfInfo() {
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
return updateState(userInfo);
|
|
2151
|
-
};
|
|
2152
|
-
React.useEffect(function () {
|
|
2384
|
+
const live = useLiveInstance();
|
|
2385
|
+
const [state, updateState] = React.useState(live.selfInfo || {});
|
|
2386
|
+
const selfInfoUpdate = (userInfo) => updateState(userInfo);
|
|
2387
|
+
React.useEffect(() => {
|
|
2153
2388
|
live.on('selfInfoUpdate', selfInfoUpdate);
|
|
2154
|
-
return
|
|
2389
|
+
return () => live.off('selfInfoUpdate', selfInfoUpdate);
|
|
2155
2390
|
}, [live]);
|
|
2156
|
-
|
|
2157
|
-
return
|
|
2158
|
-
|
|
2159
|
-
case 0: return [4 /*yield*/, live.setSelfInfo(userInfo)];
|
|
2160
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
2161
|
-
}
|
|
2162
|
-
});
|
|
2163
|
-
}); }, [live]);
|
|
2391
|
+
const setState = React.useCallback((userInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
2392
|
+
return yield live.setSelfInfo(userInfo);
|
|
2393
|
+
}), [live]);
|
|
2164
2394
|
return [state, setState];
|
|
2165
2395
|
}
|
|
2166
|
-
function
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
React.useEffect(
|
|
2170
|
-
|
|
2396
|
+
function useKeyframesSnapshot() {
|
|
2397
|
+
const live = useLiveInstance();
|
|
2398
|
+
const [state, setState] = React.useState(live.snapshot);
|
|
2399
|
+
React.useEffect(() => {
|
|
2400
|
+
const onKeyframes = (keyframes) => setState(keyframes);
|
|
2171
2401
|
live.on('keyframes', onKeyframes);
|
|
2172
|
-
return
|
|
2402
|
+
return () => live.off('keyframes', onKeyframes);
|
|
2173
2403
|
});
|
|
2174
2404
|
return state;
|
|
2175
2405
|
}
|
|
2176
2406
|
function useUserList() {
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
React.useEffect(
|
|
2407
|
+
const live = useLiveInstance();
|
|
2408
|
+
const [state, updateState] = React.useState(live.userList);
|
|
2409
|
+
const userListUpdate = (userList) => updateState(userList);
|
|
2410
|
+
React.useEffect(() => {
|
|
2181
2411
|
live.on('userListUpdate', userListUpdate);
|
|
2182
|
-
return
|
|
2412
|
+
return () => live.off('userListUpdate', userListUpdate);
|
|
2183
2413
|
}, [live]);
|
|
2184
2414
|
return state;
|
|
2185
2415
|
}
|
|
2186
|
-
/**
|
|
2187
|
-
*
|
|
2188
|
-
* @param name
|
|
2189
|
-
* @param callback
|
|
2190
|
-
* @param deps
|
|
2191
|
-
* @returns
|
|
2192
|
-
* @deprecated
|
|
2193
|
-
*/
|
|
2194
|
-
function useWebSocketEventCallback(name, callback, deps) {
|
|
2195
|
-
if (deps === void 0) { deps = []; }
|
|
2196
|
-
var live = useLiveInstance();
|
|
2197
|
-
var dispose = function () { return live.off(name, callback); };
|
|
2198
|
-
var dependencyList = __spreadArray([live, name], deps, true);
|
|
2199
|
-
React.useEffect(function () {
|
|
2200
|
-
live.on(name, callback);
|
|
2201
|
-
return dispose;
|
|
2202
|
-
}, dependencyList);
|
|
2203
|
-
return dispose;
|
|
2204
|
-
}
|
|
2205
2416
|
return {
|
|
2206
|
-
live
|
|
2207
|
-
jsBridge
|
|
2208
|
-
LiveProvider
|
|
2209
|
-
unsafe__useLiveInstance
|
|
2210
|
-
unsafe__useRTCInstance
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
useUserList: useUserList,
|
|
2223
|
-
useWebSocketEventCallback: useWebSocketEventCallback,
|
|
2417
|
+
live,
|
|
2418
|
+
jsBridge,
|
|
2419
|
+
LiveProvider,
|
|
2420
|
+
unsafe__useLiveInstance,
|
|
2421
|
+
unsafe__useRTCInstance,
|
|
2422
|
+
useConnect,
|
|
2423
|
+
useKeyframe,
|
|
2424
|
+
useKeyframeUpdateCallback,
|
|
2425
|
+
useLiveAction,
|
|
2426
|
+
useLiveEventCallback,
|
|
2427
|
+
useLiveState,
|
|
2428
|
+
useRTCAction,
|
|
2429
|
+
useRTCEventCallback,
|
|
2430
|
+
useSelfInfo,
|
|
2431
|
+
useKeyframesSnapshot,
|
|
2432
|
+
useUserList,
|
|
2224
2433
|
};
|
|
2225
2434
|
}
|
|
2226
2435
|
|
|
2227
|
-
export { BrowserRTC, BrowserRTC4Chime, BuiltInRTCType, BuiltinActionType, BuiltinEventType, Command, CoreRTC, MemUserStatus, MicroStatus, RTCJoinedInfoCodeEnum, RTCType, UserStatus, VRWebViewRTC, WebSocketCloseError, WebSocketErrorType, WebSocketState, createLive, createLiveReact, parseLiveMsg, parseWSClsErr };
|
|
2436
|
+
export { BrowserRTC, BrowserRTC4Chime, BuiltInRTCType, BuiltinActionType, BuiltinEventType, Command, CoreRTC, LiveState, MemUserStatus, MicroStatus, RTCJoinedInfoCodeEnum, RTCType, UserStatus, VRWebViewRTC, WebSocketCloseError, WebSocketErrorType, WebSocketState, createLive, createLiveReact, parseLiveMsg, parseWSClsErr };
|
|
2228
2437
|
//# sourceMappingURL=realsee-live.esm.js.map
|