@realsee/live 0.5.2-dev.1 → 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.
@@ -2,7 +2,7 @@ import { LiveMsg } from '../typings';
2
2
  import { LiveState } from '../typings/live/LiveState';
3
3
  import { RobustWebSocketEventDetail } from '../utils/RobustWebSocket';
4
4
  import { Subscribe } from '../utils/subscribe';
5
- export declare type LiveControllerEventMap = {
5
+ export type LiveControllerEventMap = {
6
6
  stateChange: (state: LiveState, prevState: LiveState) => void;
7
7
  message: (message: LiveMsg) => void;
8
8
  reconnected: (detail: RobustWebSocketEventDetail) => void;
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { BuiltinActionType, BuiltinEventType, KeyframeTypes, LiveConnectOptions, LiveEventType, LiveOptions, MicroStatus, RTCEventType, RTCType, UserInfo } from '../typings';
3
3
  import { LiveState } from '../typings/live/LiveState';
4
4
  import { Live } from './live';
5
- export declare type LiveProviderPropTypes<KeyframesSnapshot extends Record<string, any>> = {
5
+ export type LiveProviderPropTypes<KeyframesSnapshot extends Record<string, any>> = {
6
6
  children?: React.ReactNode;
7
7
  live?: Live<KeyframesSnapshot>;
8
8
  };
@@ -3,7 +3,7 @@ import { RTCProtocol } from '../rtc';
3
3
  import { EventType, KeyframeTypes, LiveOptions, RoomInfo, RTCType, UserInfo, BuiltinEventType, BuiltinActionType, MicroStatus, LiveConnectOptions } from '../typings';
4
4
  import { LiveState } from '../typings/live/LiveState';
5
5
  import { Subscribe } from '../utils/subscribe';
6
- export declare type LiveBuiltInData<KeyframesSnapshot> = {
6
+ export type LiveBuiltInData<KeyframesSnapshot> = {
7
7
  selfInfo?: UserInfo;
8
8
  userList?: UserInfo[];
9
9
  roomInfo?: RoomInfo;
@@ -171,6 +171,54 @@ exports.BuiltInRTCType = void 0;
171
171
  BuiltInRTCType["RealseeXChimeRTC"] = "chime";
172
172
  })(exports.BuiltInRTCType || (exports.BuiltInRTCType = {}));
173
173
 
174
+ /**
175
+ * 输出格式化日志
176
+ */
177
+ // 获取当前时间
178
+ const getTime = () => {
179
+ const date = new Date();
180
+ const year = date.getFullYear();
181
+ const month = (date.getMonth() + 1).toString().padStart(2, '0'); //月份是从0开始的
182
+ const day = date.getDate().toString().padStart(2, '0');
183
+ const hour = date.getHours().toString().padStart(2, '0');
184
+ const min = date.getMinutes().toString().padStart(2, '0');
185
+ const sec = date.getSeconds().toString().padStart(2, '0');
186
+ const ms = date.getMilliseconds();
187
+ return `[${year}-${month}-${day} ${hour}:${min}:${sec}.${ms}]`;
188
+ };
189
+ var LOG_LEVEL;
190
+ (function (LOG_LEVEL) {
191
+ LOG_LEVEL["info"] = "INFO";
192
+ LOG_LEVEL["log"] = "LOG";
193
+ LOG_LEVEL["error"] = "ERROR";
194
+ LOG_LEVEL["warn"] = "WARN";
195
+ })(LOG_LEVEL || (LOG_LEVEL = {}));
196
+ // 输出日志
197
+ const echo = (logLevel, args = []) => {
198
+ args.unshift(`Realsee Live ${getTime()} <${logLevel}> `);
199
+ switch (logLevel) {
200
+ case LOG_LEVEL.info:
201
+ return console.info(...args);
202
+ case LOG_LEVEL.error:
203
+ return console.error(...args);
204
+ case LOG_LEVEL.warn:
205
+ return console.warn(...args);
206
+ default:
207
+ return console.log(...args);
208
+ }
209
+ };
210
+ const log = (...args) => echo(LOG_LEVEL.log, args);
211
+ const info = (...args) => echo(LOG_LEVEL.info, args);
212
+ const error = (...args) => echo(LOG_LEVEL.error, args);
213
+ const warn = (...args) => echo(LOG_LEVEL.warn, args);
214
+ const logger = {
215
+ log,
216
+ info,
217
+ error,
218
+ warn,
219
+ };
220
+ var logger$1 = logger;
221
+
174
222
  // uuid
175
223
  function S4() {
176
224
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
@@ -298,7 +346,10 @@ class BrowserRTC extends CoreRTC {
298
346
  navigator.mediaDevices
299
347
  .getUserMedia(rule)
300
348
  .then(() => resolve(true))
301
- .catch(() => resolve(false));
349
+ .catch((e) => {
350
+ logger$1.error(e.message);
351
+ resolve(false);
352
+ });
302
353
  }
303
354
  catch (e) {
304
355
  console.error(e);
@@ -613,6 +664,9 @@ exports.RTCJoinedInfoCodeEnum = void 0;
613
664
  })(exports.RTCJoinedInfoCodeEnum || (exports.RTCJoinedInfoCodeEnum = {}));
614
665
 
615
666
  class VRWebViewRTC extends CoreRTC {
667
+ get jsBridge() {
668
+ return this.options.jsBridge;
669
+ }
616
670
  constructor({ jsBridge, getVoiceSign }) {
617
671
  super();
618
672
  this.type = exports.RTCType.RealseeVRWebViewRTC;
@@ -631,9 +685,6 @@ class VRWebViewRTC extends CoreRTC {
631
685
  this.emit('weakNetwork');
632
686
  });
633
687
  }
634
- get jsBridge() {
635
- return this.options.jsBridge;
636
- }
637
688
  join(options) {
638
689
  return __awaiter(this, void 0, void 0, function* () {
639
690
  try {
@@ -986,7 +1037,7 @@ exports.default = LogLevel;
986
1037
 
987
1038
  var LogLevel = /*@__PURE__*/getDefaultExportFromCjs(LogLevel_1);
988
1039
 
989
- function appendUri(uri, query) {
1040
+ function appendUri(uri, query = {}) {
990
1041
  const hasQuery = uri.indexOf('?') !== -1;
991
1042
  const newQuery = Object.keys(query).reduce((accu, curr, idx) => `${accu}${(idx === 0 && !hasQuery) ? '?' : '&'}${curr}=${query[curr]}`, '');
992
1043
  return uri + newQuery;
@@ -1124,66 +1175,21 @@ function objEqualDeep(value, other) {
1124
1175
  * @param options 可选参数,可选项:`deep` 是否深比较。
1125
1176
  * @returns {boolean} 是否相等。
1126
1177
  */
1127
- function equal(value, other, opt) {
1178
+ function equal(value, other, opt = { deep: false }) {
1128
1179
  if (!opt.deep)
1129
1180
  return isShallowEqual(value, other);
1130
1181
  return isDeepEqual(value, other);
1131
1182
  }
1132
1183
 
1133
- /**
1134
- * 输出格式化日志
1135
- */
1136
- // 获取当前时间
1137
- const getTime = () => {
1138
- const date = new Date();
1139
- const year = date.getFullYear();
1140
- const month = (date.getMonth() + 1).toString().padStart(2, '0'); //月份是从0开始的
1141
- const day = date.getDate().toString().padStart(2, '0');
1142
- const hour = date.getHours().toString().padStart(2, '0');
1143
- const min = date.getMinutes().toString().padStart(2, '0');
1144
- const sec = date.getSeconds().toString().padStart(2, '0');
1145
- const ms = date.getMilliseconds();
1146
- return `[${year}-${month}-${day} ${hour}:${min}:${sec}.${ms}]`;
1147
- };
1148
- var LOG_LEVEL;
1149
- (function (LOG_LEVEL) {
1150
- LOG_LEVEL["info"] = "INFO";
1151
- LOG_LEVEL["log"] = "LOG";
1152
- LOG_LEVEL["error"] = "ERROR";
1153
- LOG_LEVEL["warn"] = "WARN";
1154
- })(LOG_LEVEL || (LOG_LEVEL = {}));
1155
- // 输出日志
1156
- const echo = (logLevel, args = []) => {
1157
- args.unshift(`Realsee Live ${getTime()} <${logLevel}> `);
1158
- switch (logLevel) {
1159
- case LOG_LEVEL.info:
1160
- return console.info(...args);
1161
- case LOG_LEVEL.error:
1162
- return console.error(...args);
1163
- case LOG_LEVEL.warn:
1164
- return console.warn(...args);
1165
- default:
1166
- return console.log(...args);
1167
- }
1168
- };
1169
- const log = (...args) => echo(LOG_LEVEL.log, args);
1170
- const info = (...args) => echo(LOG_LEVEL.info, args);
1171
- const error = (...args) => echo(LOG_LEVEL.error, args);
1172
- const warn = (...args) => echo(LOG_LEVEL.warn, args);
1173
- const logger = {
1174
- log,
1175
- info,
1176
- error,
1177
- warn,
1178
- };
1179
- var logger$1 = logger;
1180
-
1181
1184
  /**
1182
1185
  * 具有鲁棒性的WebSocket封装
1183
1186
  * 1、自动重连
1184
1187
  * 2、可根据网络情况进行重连
1185
1188
  */
1186
1189
  class RobustWebSocket extends Subscribe {
1190
+ get attempts() {
1191
+ return this._attempts;
1192
+ }
1187
1193
  constructor(options) {
1188
1194
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call
1189
1195
  super();
@@ -1431,9 +1437,6 @@ class RobustWebSocket extends Subscribe {
1431
1437
  }
1432
1438
  this._startHealthCheck();
1433
1439
  }
1434
- get attempts() {
1435
- return this._attempts;
1436
- }
1437
1440
  setOptions(options) {
1438
1441
  if (!options)
1439
1442
  return;
@@ -1475,6 +1478,14 @@ class RobustWebSocket extends Subscribe {
1475
1478
  }
1476
1479
 
1477
1480
  class LiveController extends Subscribe {
1481
+ set state(state) {
1482
+ const prevState = JSON.parse(JSON.stringify(this._state));
1483
+ this._state = state;
1484
+ this.emit('stateChange', this.state, prevState);
1485
+ }
1486
+ get state() {
1487
+ return this._state;
1488
+ }
1478
1489
  constructor() {
1479
1490
  super();
1480
1491
  /**
@@ -1604,14 +1615,6 @@ class LiveController extends Subscribe {
1604
1615
  });
1605
1616
  this._addWebSocketEventListeners();
1606
1617
  }
1607
- set state(state) {
1608
- const prevState = JSON.parse(JSON.stringify(this._state));
1609
- this._state = state;
1610
- this.emit('stateChange', this.state, prevState);
1611
- }
1612
- get state() {
1613
- return this._state;
1614
- }
1615
1618
  /**
1616
1619
  * 发送数据
1617
1620
  * @param data
@@ -1643,6 +1646,65 @@ const _clearLiveInstanceIfNeed = () => {
1643
1646
  }
1644
1647
  };
1645
1648
  class Live extends Subscribe {
1649
+ get options() {
1650
+ return Object.freeze(this._options || {});
1651
+ }
1652
+ /**
1653
+ * 带看状态
1654
+ */
1655
+ get state() {
1656
+ return this._controller.state;
1657
+ }
1658
+ /**
1659
+ * 兼容老逻辑
1660
+ * @deprecated 请直接读取 state 属性字段,未来将移除该属性
1661
+ */
1662
+ get readyState() {
1663
+ return this._controller.state;
1664
+ }
1665
+ /**
1666
+ * 获取当前WebSocket连接的URL。(注意:这个是WebSocket连接的完整连接,附带一些query参数)。
1667
+ * @deprecated 带看不需要关注底层ws的相关信息,未来将移除
1668
+ */
1669
+ get url() {
1670
+ return this.options.url;
1671
+ }
1672
+ /**
1673
+ * 获取当前live使用的RTC实例
1674
+ */
1675
+ get $RTC() {
1676
+ return this._options.rtc;
1677
+ }
1678
+ /**
1679
+ * 获取当前live使用的jsBridge实例
1680
+ */
1681
+ get jsBridge() {
1682
+ return this._options.jsBridge;
1683
+ }
1684
+ /**
1685
+ * 当前帧数据快照
1686
+ */
1687
+ get snapshot() {
1688
+ return this._buildInData.keyframes;
1689
+ }
1690
+ /**
1691
+ * 当前用户信息
1692
+ */
1693
+ get selfInfo() {
1694
+ return this._buildInData.selfInfo;
1695
+ }
1696
+ /**
1697
+ * 当前用户列表
1698
+ */
1699
+ get userList() {
1700
+ return this._buildInData.userList || [];
1701
+ }
1702
+ /**
1703
+ * 当前带看房间信息
1704
+ */
1705
+ get roomInfo() {
1706
+ return this._buildInData.roomInfo;
1707
+ }
1646
1708
  constructor(opts) {
1647
1709
  var _a;
1648
1710
  super();
@@ -2113,65 +2175,6 @@ class Live extends Subscribe {
2113
2175
  Object.assign(window, { $liveController: this._controller, $live: this });
2114
2176
  }
2115
2177
  }
2116
- get options() {
2117
- return Object.freeze(this._options || {});
2118
- }
2119
- /**
2120
- * 带看状态
2121
- */
2122
- get state() {
2123
- return this._controller.state;
2124
- }
2125
- /**
2126
- * 兼容老逻辑
2127
- * @deprecated 请直接读取 state 属性字段,未来将移除该属性
2128
- */
2129
- get readyState() {
2130
- return this._controller.state;
2131
- }
2132
- /**
2133
- * 获取当前WebSocket连接的URL。(注意:这个是WebSocket连接的完整连接,附带一些query参数)。
2134
- * @deprecated 带看不需要关注底层ws的相关信息,未来将移除
2135
- */
2136
- get url() {
2137
- return this.options.url;
2138
- }
2139
- /**
2140
- * 获取当前live使用的RTC实例
2141
- */
2142
- get $RTC() {
2143
- return this._options.rtc;
2144
- }
2145
- /**
2146
- * 获取当前live使用的jsBridge实例
2147
- */
2148
- get jsBridge() {
2149
- return this._options.jsBridge;
2150
- }
2151
- /**
2152
- * 当前帧数据快照
2153
- */
2154
- get snapshot() {
2155
- return this._buildInData.keyframes;
2156
- }
2157
- /**
2158
- * 当前用户信息
2159
- */
2160
- get selfInfo() {
2161
- return this._buildInData.selfInfo;
2162
- }
2163
- /**
2164
- * 当前用户列表
2165
- */
2166
- get userList() {
2167
- return this._buildInData.userList || [];
2168
- }
2169
- /**
2170
- * 当前带看房间信息
2171
- */
2172
- get roomInfo() {
2173
- return this._buildInData.roomInfo;
2174
- }
2175
2178
  /**
2176
2179
  * 修改状态
2177
2180
  * @param evtType