@realsee/live 0.5.0-alpha.9 → 0.5.2-dev.2

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.
Files changed (33) hide show
  1. package/dist/live/controller.d.ts +1 -1
  2. package/dist/live/createLive.d.ts +1 -1
  3. package/dist/live/createLiveReact.d.ts +4 -4
  4. package/dist/live/live.d.ts +2 -2
  5. package/dist/realsee-live.cjs.development.js +155 -150
  6. package/dist/realsee-live.cjs.development.js.map +1 -1
  7. package/dist/realsee-live.cjs.production.js +1 -1
  8. package/dist/realsee-live.cjs.production.js.map +1 -1
  9. package/dist/realsee-live.esm.js +156 -151
  10. package/dist/realsee-live.esm.js.map +1 -1
  11. package/dist/realsee-live.umd.development.js +2342 -2228
  12. package/dist/realsee-live.umd.development.js.map +1 -1
  13. package/dist/realsee-live.umd.production.js +1 -1
  14. package/dist/realsee-live.umd.production.js.map +1 -1
  15. package/dist/rtc/BrowserRTC.d.ts +1 -0
  16. package/dist/typings/live/EventType.d.ts +3 -3
  17. package/dist/typings/live/GetVoiceSign.d.ts +1 -1
  18. package/dist/typings/live/LiveConnectOptions.d.ts +1 -1
  19. package/dist/typings/live/LiveMsg.d.ts +3 -3
  20. package/dist/typings/live/RoomInfo.d.ts +1 -1
  21. package/dist/typings/live/UserInfo.d.ts +20 -3
  22. package/dist/typings/live/UserVolume.d.ts +1 -1
  23. package/dist/typings/live/WebSocket.d.ts +1 -1
  24. package/dist/typings/react/RTCActionReactCallback.d.ts +1 -1
  25. package/dist/typings/rtc/eventType.d.ts +1 -1
  26. package/dist/typings/rtc/protocol.d.ts +5 -0
  27. package/dist/utils/RobustWebSocket.d.ts +5 -5
  28. package/dist/utils/subscribe.d.ts +1 -1
  29. package/docs/assets/search.js +1 -1
  30. package/docs/classes/BrowserRTC.html +10 -10
  31. package/docs/interfaces/RTCProtocol.html +12 -10
  32. package/docs/modules.html +12 -6
  33. package/package.json +17 -15
@@ -1,7 +1,7 @@
1
1
  import JSBridge from '@realsee/jsbridge-x';
2
2
  import TRTC from 'trtc-js-sdk';
3
3
  import { DefaultModality, ConsoleLogger, LogLevel as LogLevel$1, DefaultDeviceController, MeetingSessionConfiguration, DefaultMeetingSession, MeetingSessionStatusCode } from 'amazon-chime-sdk-js';
4
- import React, { createContext, useCallback } from 'react';
4
+ import React, { createContext } from 'react';
5
5
 
6
6
  const EVENT_SYMBOL = Symbol('$$REALSEE_LIVE_EVENT$$');
7
7
  function __generateEventIfNotExisted(instance) {
@@ -161,6 +161,54 @@ var BuiltInRTCType;
161
161
  BuiltInRTCType["RealseeXChimeRTC"] = "chime";
162
162
  })(BuiltInRTCType || (BuiltInRTCType = {}));
163
163
 
164
+ /**
165
+ * 输出格式化日志
166
+ */
167
+ // 获取当前时间
168
+ const getTime = () => {
169
+ const date = new Date();
170
+ const year = date.getFullYear();
171
+ const month = (date.getMonth() + 1).toString().padStart(2, '0'); //月份是从0开始的
172
+ const day = date.getDate().toString().padStart(2, '0');
173
+ const hour = date.getHours().toString().padStart(2, '0');
174
+ const min = date.getMinutes().toString().padStart(2, '0');
175
+ const sec = date.getSeconds().toString().padStart(2, '0');
176
+ const ms = date.getMilliseconds();
177
+ return `[${year}-${month}-${day} ${hour}:${min}:${sec}.${ms}]`;
178
+ };
179
+ var LOG_LEVEL;
180
+ (function (LOG_LEVEL) {
181
+ LOG_LEVEL["info"] = "INFO";
182
+ LOG_LEVEL["log"] = "LOG";
183
+ LOG_LEVEL["error"] = "ERROR";
184
+ LOG_LEVEL["warn"] = "WARN";
185
+ })(LOG_LEVEL || (LOG_LEVEL = {}));
186
+ // 输出日志
187
+ const echo = (logLevel, args = []) => {
188
+ args.unshift(`Realsee Live ${getTime()} <${logLevel}> `);
189
+ switch (logLevel) {
190
+ case LOG_LEVEL.info:
191
+ return console.info(...args);
192
+ case LOG_LEVEL.error:
193
+ return console.error(...args);
194
+ case LOG_LEVEL.warn:
195
+ return console.warn(...args);
196
+ default:
197
+ return console.log(...args);
198
+ }
199
+ };
200
+ const log = (...args) => echo(LOG_LEVEL.log, args);
201
+ const info = (...args) => echo(LOG_LEVEL.info, args);
202
+ const error = (...args) => echo(LOG_LEVEL.error, args);
203
+ const warn = (...args) => echo(LOG_LEVEL.warn, args);
204
+ const logger = {
205
+ log,
206
+ info,
207
+ error,
208
+ warn,
209
+ };
210
+ var logger$1 = logger;
211
+
164
212
  // uuid
165
213
  function S4() {
166
214
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
@@ -194,6 +242,7 @@ class BrowserRTC extends CoreRTC {
194
242
  this._getVoiceSign = () => {
195
243
  throw new Error('方法 getVoiceSign 未实现');
196
244
  };
245
+ this.checkRequirement = () => TRTC.checkSystemRequirements();
197
246
  this.$dom = document.createElement('div');
198
247
  this._trtc = {
199
248
  client: null,
@@ -287,7 +336,10 @@ class BrowserRTC extends CoreRTC {
287
336
  navigator.mediaDevices
288
337
  .getUserMedia(rule)
289
338
  .then(() => resolve(true))
290
- .catch(() => resolve(false));
339
+ .catch((e) => {
340
+ logger$1.error(e.message);
341
+ resolve(false);
342
+ });
291
343
  }
292
344
  catch (e) {
293
345
  console.error(e);
@@ -308,9 +360,10 @@ class BrowserRTC extends CoreRTC {
308
360
  var _a, _b, _c, _d;
309
361
  (_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.on('stream-added', this._handleStreamAdded);
310
362
  (_b = this._trtc.client) === null || _b === void 0 ? void 0 : _b.on('stream-subscribed', this._handleStreamSubscribed);
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
- ]));
363
+ (_c = this._trtc.client) === null || _c === void 0 ? void 0 : _c.on('audio-volume', (event) => this.emit('userVolumes', event.result.map(({ userId, audioVolume }) => ({
364
+ userId,
365
+ audioVolume,
366
+ }))));
314
367
  (_d = this._trtc.client) === null || _d === void 0 ? void 0 : _d.on('error', (event) => this.emit('error', event));
315
368
  }
316
369
  }
@@ -601,6 +654,9 @@ var RTCJoinedInfoCodeEnum;
601
654
  })(RTCJoinedInfoCodeEnum || (RTCJoinedInfoCodeEnum = {}));
602
655
 
603
656
  class VRWebViewRTC extends CoreRTC {
657
+ get jsBridge() {
658
+ return this.options.jsBridge;
659
+ }
604
660
  constructor({ jsBridge, getVoiceSign }) {
605
661
  super();
606
662
  this.type = RTCType.RealseeVRWebViewRTC;
@@ -619,9 +675,6 @@ class VRWebViewRTC extends CoreRTC {
619
675
  this.emit('weakNetwork');
620
676
  });
621
677
  }
622
- get jsBridge() {
623
- return this.options.jsBridge;
624
- }
625
678
  join(options) {
626
679
  return __awaiter(this, void 0, void 0, function* () {
627
680
  try {
@@ -974,7 +1027,7 @@ exports.default = LogLevel;
974
1027
 
975
1028
  var LogLevel = /*@__PURE__*/getDefaultExportFromCjs(LogLevel_1);
976
1029
 
977
- function appendUri(uri, query) {
1030
+ function appendUri(uri, query = {}) {
978
1031
  const hasQuery = uri.indexOf('?') !== -1;
979
1032
  const newQuery = Object.keys(query).reduce((accu, curr, idx) => `${accu}${(idx === 0 && !hasQuery) ? '?' : '&'}${curr}=${query[curr]}`, '');
980
1033
  return uri + newQuery;
@@ -1112,66 +1165,21 @@ function objEqualDeep(value, other) {
1112
1165
  * @param options 可选参数,可选项:`deep` 是否深比较。
1113
1166
  * @returns {boolean} 是否相等。
1114
1167
  */
1115
- function equal(value, other, opt) {
1168
+ function equal(value, other, opt = { deep: false }) {
1116
1169
  if (!opt.deep)
1117
1170
  return isShallowEqual(value, other);
1118
1171
  return isDeepEqual(value, other);
1119
1172
  }
1120
1173
 
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
1174
  /**
1170
1175
  * 具有鲁棒性的WebSocket封装
1171
1176
  * 1、自动重连
1172
1177
  * 2、可根据网络情况进行重连
1173
1178
  */
1174
1179
  class RobustWebSocket extends Subscribe {
1180
+ get attempts() {
1181
+ return this._attempts;
1182
+ }
1175
1183
  constructor(options) {
1176
1184
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
1177
1185
  super();
@@ -1419,9 +1427,6 @@ class RobustWebSocket extends Subscribe {
1419
1427
  }
1420
1428
  this._startHealthCheck();
1421
1429
  }
1422
- get attempts() {
1423
- return this._attempts;
1424
- }
1425
1430
  setOptions(options) {
1426
1431
  if (!options)
1427
1432
  return;
@@ -1463,6 +1468,14 @@ class RobustWebSocket extends Subscribe {
1463
1468
  }
1464
1469
 
1465
1470
  class LiveController extends Subscribe {
1471
+ set state(state) {
1472
+ const prevState = JSON.parse(JSON.stringify(this._state));
1473
+ this._state = state;
1474
+ this.emit('stateChange', this.state, prevState);
1475
+ }
1476
+ get state() {
1477
+ return this._state;
1478
+ }
1466
1479
  constructor() {
1467
1480
  super();
1468
1481
  /**
@@ -1592,14 +1605,6 @@ class LiveController extends Subscribe {
1592
1605
  });
1593
1606
  this._addWebSocketEventListeners();
1594
1607
  }
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
- }
1603
1608
  /**
1604
1609
  * 发送数据
1605
1610
  * @param data
@@ -1631,6 +1636,65 @@ const _clearLiveInstanceIfNeed = () => {
1631
1636
  }
1632
1637
  };
1633
1638
  class Live extends Subscribe {
1639
+ get options() {
1640
+ return Object.freeze(this._options || {});
1641
+ }
1642
+ /**
1643
+ * 带看状态
1644
+ */
1645
+ get state() {
1646
+ return this._controller.state;
1647
+ }
1648
+ /**
1649
+ * 兼容老逻辑
1650
+ * @deprecated 请直接读取 state 属性字段,未来将移除该属性
1651
+ */
1652
+ get readyState() {
1653
+ return this._controller.state;
1654
+ }
1655
+ /**
1656
+ * 获取当前WebSocket连接的URL。(注意:这个是WebSocket连接的完整连接,附带一些query参数)。
1657
+ * @deprecated 带看不需要关注底层ws的相关信息,未来将移除
1658
+ */
1659
+ get url() {
1660
+ return this.options.url;
1661
+ }
1662
+ /**
1663
+ * 获取当前live使用的RTC实例
1664
+ */
1665
+ get $RTC() {
1666
+ return this._options.rtc;
1667
+ }
1668
+ /**
1669
+ * 获取当前live使用的jsBridge实例
1670
+ */
1671
+ get jsBridge() {
1672
+ return this._options.jsBridge;
1673
+ }
1674
+ /**
1675
+ * 当前帧数据快照
1676
+ */
1677
+ get snapshot() {
1678
+ return this._buildInData.keyframes;
1679
+ }
1680
+ /**
1681
+ * 当前用户信息
1682
+ */
1683
+ get selfInfo() {
1684
+ return this._buildInData.selfInfo;
1685
+ }
1686
+ /**
1687
+ * 当前用户列表
1688
+ */
1689
+ get userList() {
1690
+ return this._buildInData.userList || [];
1691
+ }
1692
+ /**
1693
+ * 当前带看房间信息
1694
+ */
1695
+ get roomInfo() {
1696
+ return this._buildInData.roomInfo;
1697
+ }
1634
1698
  constructor(opts) {
1635
1699
  var _a;
1636
1700
  super();
@@ -1705,7 +1769,7 @@ class Live extends Subscribe {
1705
1769
  this._handleMessage = (liveMsg) => __awaiter(this, void 0, void 0, function* () {
1706
1770
  var _b, _c, _d, _e, _f, _g;
1707
1771
  if (typeof liveMsg === 'object') {
1708
- const { command, data, frontRequestId, code, message } = liveMsg;
1772
+ const { command, data = {}, frontRequestId, code, message } = liveMsg;
1709
1773
  if (code === 'SUCCESS') {
1710
1774
  switch (command) {
1711
1775
  /**
@@ -1875,8 +1939,8 @@ class Live extends Subscribe {
1875
1939
  }
1876
1940
  const { force = false } = options;
1877
1941
  // 检测一下麦克风权限,hack
1878
- if (this._options.rtc && this._options.jsBridge) {
1879
- const res = yield this._options.jsBridge.detectMicro();
1942
+ if (this._options.rtc) {
1943
+ const res = yield this._options.rtc.detectMicro();
1880
1944
  if (!res) {
1881
1945
  return new Error('Failed to obtain microphone authorization');
1882
1946
  }
@@ -2101,65 +2165,6 @@ class Live extends Subscribe {
2101
2165
  Object.assign(window, { $liveController: this._controller, $live: this });
2102
2166
  }
2103
2167
  }
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
2168
  /**
2164
2169
  * 修改状态
2165
2170
  * @param evtType
@@ -2255,21 +2260,21 @@ function createLiveReact(options) {
2255
2260
  * @deprecated
2256
2261
  * @returns
2257
2262
  */
2258
- const unsafe__useLiveInstance = useCallback(() => useLiveInstance(), [useLiveInstance]);
2263
+ const unsafe__useLiveInstance = () => live;
2259
2264
  /**
2260
2265
  * 使用rtc实例
2261
2266
  */
2262
- const useRTCInstance = useCallback(() => useLiveInstance().$RTC, [useLiveInstance]);
2267
+ const useRTCInstance = () => live.$RTC;
2263
2268
  /**
2264
2269
  * 不建议这样使用
2265
2270
  * @deprecated
2266
2271
  * @returns
2267
2272
  */
2268
- const unsafe__useRTCInstance = useCallback(() => useRTCInstance(), [useRTCInstance]);
2273
+ const unsafe__useRTCInstance = () => useRTCInstance();
2269
2274
  /**
2270
2275
  * 带看连接操作
2271
2276
  */
2272
- const useConnect = useCallback((options) => __awaiter(this, void 0, void 0, function* () { return yield useLiveInstance().connect(options); }), []);
2277
+ const useConnect = () => (options) => __awaiter(this, void 0, void 0, function* () { return yield live.connect(options); });
2273
2278
  /**
2274
2279
  *
2275
2280
  * @param name
@@ -2293,17 +2298,17 @@ function createLiveReact(options) {
2293
2298
  */
2294
2299
  function useLiveAction() {
2295
2300
  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]);
2301
+ const connect = (options) => __awaiter(this, void 0, void 0, function* () { return yield live.connect(options); });
2302
+ const toggleMicro = (microStatus) => live.toggleMicro(microStatus);
2303
+ const broadcast = (data, toUserIds, timeout = 0) => __awaiter(this, void 0, void 0, function* () { return yield live.broadcast(data, toUserIds, timeout); });
2304
+ const exit = () => __awaiter(this, void 0, void 0, function* () { return yield live.exit(); });
2305
+ const kick = (toUserIds) => __awaiter(this, void 0, void 0, function* () { return yield live.kick(toUserIds); });
2306
+ const forbidMicro = (micro, toUserIds = []) => __awaiter(this, void 0, void 0, function* () { return yield live.forbidMicro(micro, toUserIds); });
2307
+ const forbidSync = (sync, toUserIds = []) => live.forbidSync(sync, toUserIds);
2308
+ const getFramesByKey = (key) => live.getFramesByKey(key);
2309
+ const sendKeyframe = (key, frame) => live.sendKeyframe(key, frame);
2310
+ const setSelfInfo = (userInfo) => live.setSelfInfo(userInfo);
2311
+ const updateStatus = (evtType, atnType, status, toUserIds) => live.updateStatus(evtType, atnType, status, toUserIds);
2307
2312
  return {
2308
2313
  connect,
2309
2314
  broadcast,
@@ -2357,11 +2362,11 @@ function createLiveReact(options) {
2357
2362
  }
2358
2363
  function useRTCAction() {
2359
2364
  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]);
2365
+ const join = (options) => live.$RTC.join(options);
2366
+ const quit = () => live.$RTC.quit();
2367
+ const shock = () => { var _a, _b; return (_b = (_a = live.$RTC).shock) === null || _b === void 0 ? void 0 : _b.call(_a); };
2368
+ const toggleMicro = (flag) => live.$RTC.toggleMicro(flag);
2369
+ const detectMicro = () => live.$RTC.detectMicro();
2365
2370
  return {
2366
2371
  join,
2367
2372
  quit,