@realsee/live 0.3.0-alpha.3 → 0.4.0-alpha.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 (147) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/live/controller.d.ts +43 -0
  3. package/{lib → dist/live}/createLive.d.ts +6 -6
  4. package/dist/live/createLiveReact.d.ts +6 -0
  5. package/dist/realsee-live.cjs.development.js +4630 -0
  6. package/dist/realsee-live.cjs.development.js.map +1 -0
  7. package/dist/realsee-live.cjs.js +7 -0
  8. package/dist/realsee-live.cjs.production.js +2 -0
  9. package/dist/realsee-live.cjs.production.js.map +1 -0
  10. package/dist/realsee-live.esm.js +4615 -0
  11. package/dist/realsee-live.esm.js.map +1 -0
  12. package/dist/realsee-live.umd.development.js +52454 -0
  13. package/dist/realsee-live.umd.development.js.map +1 -0
  14. package/dist/realsee-live.umd.production.js +2 -0
  15. package/dist/realsee-live.umd.production.js.map +1 -0
  16. package/{lib/RTC → dist/rtc}/BrowserRTC.d.ts +29 -30
  17. package/{lib/RTC → dist/rtc}/BrowserRTC4Chime.d.ts +55 -53
  18. package/dist/rtc/CoreRTC.d.ts +23 -0
  19. package/{lib/RTC → dist/rtc}/VRWebViewRTC.d.ts +22 -23
  20. package/dist/rtc/index.d.ts +5 -0
  21. package/{lib/typings/Chime → dist/typings/chime}/AttendeeResponse.d.ts +5 -5
  22. package/{lib/typings/Chime → dist/typings/chime}/MeetingResponse.d.ts +12 -12
  23. package/{lib/typings/Chime → dist/typings/chime}/MeetingSessionConfigurationOptions.d.ts +16 -16
  24. package/dist/typings/chime/index.d.ts +3 -0
  25. package/dist/typings/index.d.ts +4 -0
  26. package/{lib/typings → dist/typings/live}/EventType.d.ts +90 -89
  27. package/{lib/typings → dist/typings/live}/GetVoiceSign.d.ts +17 -11
  28. package/{lib/typings → dist/typings/live}/Live.d.ts +123 -122
  29. package/{lib/typings → dist/typings/live}/LiveMsg.d.ts +119 -119
  30. package/{lib/typings → dist/typings/live}/LiveOptions.d.ts +65 -46
  31. package/{lib/typings → dist/typings/live}/RoomInfo.d.ts +13 -13
  32. package/{lib/typings → dist/typings/live}/UserInfo.d.ts +87 -87
  33. package/dist/typings/live/UserVolume.d.ts +7 -0
  34. package/{lib/typings → dist/typings/live}/WebSocket.d.ts +78 -78
  35. package/dist/typings/live/index.d.ts +9 -0
  36. package/{lib/createLiveReact.d.ts → dist/typings/react/LiveReact.d.ts} +162 -160
  37. package/dist/typings/react/RTCActionReactCallback.d.ts +2 -0
  38. package/dist/typings/react/index.d.ts +2 -0
  39. package/dist/typings/rtc/VRWebViewRTCOptions.d.ts +6 -0
  40. package/{lib/typings/RTCEventType.d.ts → dist/typings/rtc/eventType.d.ts} +29 -35
  41. package/dist/typings/rtc/index.d.ts +5 -0
  42. package/{lib/typings/RTCJoinedInfo.d.ts → dist/typings/rtc/joinedInfo.d.ts} +34 -28
  43. package/{lib/typings/RTCProtocol.d.ts → dist/typings/rtc/protocol.d.ts} +53 -42
  44. package/dist/typings/rtc/type.d.ts +8 -0
  45. package/{lib/shared-utils → dist/utils}/appendUri.d.ts +1 -1
  46. package/dist/utils/clientDetector.d.ts +4 -0
  47. package/{lib/shared-utils → dist/utils}/equal.d.ts +10 -11
  48. package/{lib/shared-utils/Subscribe.d.ts → dist/utils/subscribe.d.ts} +75 -76
  49. package/{lib/shared-utils → dist/utils}/uuid.d.ts +4 -4
  50. package/package.json +22 -34
  51. package/docs/.nojekyll +0 -1
  52. package/docs/assets/custom.css +0 -43
  53. package/docs/assets/highlight.css +0 -127
  54. package/docs/assets/icons.css +0 -1043
  55. package/docs/assets/icons.png +0 -0
  56. package/docs/assets/icons@2x.png +0 -0
  57. package/docs/assets/main.js +0 -52
  58. package/docs/assets/search.js +0 -1
  59. package/docs/assets/style.css +0 -1413
  60. package/docs/assets/widgets.png +0 -0
  61. package/docs/assets/widgets@2x.png +0 -0
  62. package/docs/classes/RTCProtocol.BrowserRTC.html +0 -60
  63. package/docs/classes/RTCProtocol.BrowserRTC4Chime.html +0 -66
  64. package/docs/classes/RTCProtocol.RTCExample.html +0 -62
  65. package/docs/classes/RTCProtocol.VRWebViewRTC.html +0 -60
  66. package/docs/classes/shared_utils.Subscribe.html +0 -56
  67. package/docs/enums/RTCProtocol.RTCJoinedInfoCodeEnum.html +0 -9
  68. package/docs/enums/RTCProtocol.RTCType.html +0 -1
  69. package/docs/enums/live.BuiltinActionType.html +0 -15
  70. package/docs/enums/live.BuiltinEventType.html +0 -7
  71. package/docs/enums/live.Command.html +0 -7
  72. package/docs/enums/live.MemUserStatus.html +0 -1
  73. package/docs/enums/live.MicroStatus.html +0 -3
  74. package/docs/enums/live.UserStatus.html +0 -9
  75. package/docs/enums/live.WebSocketCloseError.html +0 -19
  76. package/docs/enums/live.WebSocketErrorType.html +0 -1
  77. package/docs/enums/live.WebSocketState.html +0 -13
  78. package/docs/index.html +0 -382
  79. package/docs/interfaces/RTCProtocol.GetVoiceSignReturnType.html +0 -1
  80. package/docs/interfaces/RTCProtocol.RTCJoinedInfo.html +0 -1
  81. package/docs/interfaces/RTCProtocol.RTCProtocol-1.html +0 -60
  82. package/docs/interfaces/RTCProtocol.VRWebViewRTCOptions.html +0 -1
  83. package/docs/interfaces/live.Live.html +0 -119
  84. package/docs/interfaces/live.LiveOptions.html +0 -22
  85. package/docs/interfaces/live.LiveReact.html +0 -52
  86. package/docs/modules/RTCProtocol.html +0 -17
  87. package/docs/modules/live.html +0 -103
  88. package/docs/modules/shared_utils.html +0 -10
  89. package/docs/modules.html +0 -1
  90. package/lib/RTC/BrowserRTC.js +0 -169
  91. package/lib/RTC/BrowserRTC.js.map +0 -1
  92. package/lib/RTC/BrowserRTC4Chime.js +0 -299
  93. package/lib/RTC/BrowserRTC4Chime.js.map +0 -1
  94. package/lib/RTC/VRWebViewRTC.js +0 -125
  95. package/lib/RTC/VRWebViewRTC.js.map +0 -1
  96. package/lib/RTC/index.d.ts +0 -22
  97. package/lib/RTC/index.js +0 -50
  98. package/lib/RTC/index.js.map +0 -1
  99. package/lib/createLive.js +0 -590
  100. package/lib/createLive.js.map +0 -1
  101. package/lib/createLiveReact.js +0 -212
  102. package/lib/createLiveReact.js.map +0 -1
  103. package/lib/index.d.ts +0 -2
  104. package/lib/index.js +0 -8
  105. package/lib/index.js.map +0 -1
  106. package/lib/shared-utils/Subscribe.js +0 -134
  107. package/lib/shared-utils/Subscribe.js.map +0 -1
  108. package/lib/shared-utils/appendUri.js +0 -13
  109. package/lib/shared-utils/appendUri.js.map +0 -1
  110. package/lib/shared-utils/equal.js +0 -92
  111. package/lib/shared-utils/equal.js.map +0 -1
  112. package/lib/shared-utils/uuid.js +0 -17
  113. package/lib/shared-utils/uuid.js.map +0 -1
  114. package/lib/typings/Chime/AttendeeResponse.js +0 -3
  115. package/lib/typings/Chime/AttendeeResponse.js.map +0 -1
  116. package/lib/typings/Chime/MeetingResponse.js +0 -3
  117. package/lib/typings/Chime/MeetingResponse.js.map +0 -1
  118. package/lib/typings/Chime/MeetingSessionConfigurationOptions.js +0 -3
  119. package/lib/typings/Chime/MeetingSessionConfigurationOptions.js.map +0 -1
  120. package/lib/typings/EventType.js +0 -3
  121. package/lib/typings/EventType.js.map +0 -1
  122. package/lib/typings/GetVoiceSign.js +0 -3
  123. package/lib/typings/GetVoiceSign.js.map +0 -1
  124. package/lib/typings/Live.js +0 -3
  125. package/lib/typings/Live.js.map +0 -1
  126. package/lib/typings/LiveMsg.js +0 -111
  127. package/lib/typings/LiveMsg.js.map +0 -1
  128. package/lib/typings/LiveOptions.js +0 -3
  129. package/lib/typings/LiveOptions.js.map +0 -1
  130. package/lib/typings/RTCEventType.js +0 -3
  131. package/lib/typings/RTCEventType.js.map +0 -1
  132. package/lib/typings/RTCJoinedInfo.js +0 -23
  133. package/lib/typings/RTCJoinedInfo.js.map +0 -1
  134. package/lib/typings/RTCProtocol.js +0 -9
  135. package/lib/typings/RTCProtocol.js.map +0 -1
  136. package/lib/typings/RoomInfo.js +0 -3
  137. package/lib/typings/RoomInfo.js.map +0 -1
  138. package/lib/typings/UserInfo.js +0 -31
  139. package/lib/typings/UserInfo.js.map +0 -1
  140. package/lib/typings/VRWebViewRTCOptions.d.ts +0 -6
  141. package/lib/typings/VRWebViewRTCOptions.js +0 -3
  142. package/lib/typings/VRWebViewRTCOptions.js.map +0 -1
  143. package/lib/typings/WebSocket.js +0 -107
  144. package/lib/typings/WebSocket.js.map +0 -1
  145. package/umd/RTCProtocol.543610f0.js +0 -1
  146. package/umd/createLive.96395a4c.js +0 -1
  147. package/umd/createLiveReact.e1836101.js +0 -1
@@ -0,0 +1,4630 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var amazonChimeSdkJs = require('amazon-chime-sdk-js');
6
+ var TRTC = require('trtc-js-sdk');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var TRTC__default = /*#__PURE__*/_interopDefaultLegacy(TRTC);
11
+
12
+ const EVENT_SYMBOL = Symbol('$$REALSEE_LIVE_EVENT$$');
13
+ function __generateEventIfNotExisted(instance) {
14
+ if (!instance[EVENT_SYMBOL]) {
15
+ instance[EVENT_SYMBOL] = {};
16
+ }
17
+ return instance[EVENT_SYMBOL];
18
+ }
19
+ function __removeEventIfNotExisted(instance) {
20
+ if (!instance[EVENT_SYMBOL]) {
21
+ delete instance[EVENT_SYMBOL];
22
+ }
23
+ }
24
+ /**
25
+ * 监听者模式
26
+ * @template T 预设的监听回调类型
27
+ * @example
28
+ * ```
29
+ * new Subscribe<{
30
+ * "foo": [arg1: number, arg2: string],
31
+ * "bar": [arg: boolean],
32
+ * }>()
33
+ * ```
34
+ */
35
+ class Subscribe {
36
+ /**
37
+ * 判断是否注册了事件
38
+ * @param name 事件类型
39
+ */
40
+ hasListener(name) {
41
+ const events = __generateEventIfNotExisted(this);
42
+ return events && events[name] && events[name].length > 0;
43
+ }
44
+ /**
45
+ * 注册事件
46
+ * @param name 事件类型
47
+ * @param callback 事件回调函数
48
+ * @param once 是否只执行一次
49
+ * @returns 解除事件
50
+ * @template K 预设的监听事件名称
51
+ * @template C 回调函数函数上下文
52
+ */
53
+ on(name, callback, once) {
54
+ const events = __generateEventIfNotExisted(this);
55
+ if (!events[name])
56
+ events[name] = [];
57
+ events[name].push([callback, once || false]);
58
+ return () => this.off(name, callback);
59
+ }
60
+ /**
61
+ * 注册事件(是否只执行一次)
62
+ * @param name 事件类型
63
+ * @param callback 事件回调函数
64
+ * @returns 解除事件
65
+ * @template K 预设的监听事件名称
66
+ * @template C 回调函数函数上下文
67
+ */
68
+ once(name, callback) {
69
+ return this.on(name, callback, true);
70
+ }
71
+ /**
72
+ * 解除事件
73
+ *
74
+ * 如果 name 不传的话解除对应所有事件
75
+ * 如果 name, callback 不传的话解除所有name的所有事件
76
+ * @param name 事件类型
77
+ * @param callback 事件回调函数
78
+ * @template K 预设的监听事件名称
79
+ */
80
+ off(name, callback) {
81
+ if (name === undefined) {
82
+ __removeEventIfNotExisted(this);
83
+ return;
84
+ }
85
+ const events = __generateEventIfNotExisted(this);
86
+ if (!events[name])
87
+ events[name] = [];
88
+ if (callback === undefined) {
89
+ events[name].length = 0;
90
+ return;
91
+ }
92
+ let index = 0;
93
+ for (; index < events[name].length; index++) {
94
+ if (events[name][index][0] === callback)
95
+ break;
96
+ }
97
+ if (index < events[name].length) {
98
+ events[name].splice(index, 1);
99
+ }
100
+ }
101
+ /**
102
+ * 触发事件
103
+ * @param name 事件类型
104
+ * @param data 触发事件的数据
105
+ * @returns canceled 是否被触发取消
106
+ * @template K 预设的监听事件名称
107
+ */
108
+ emit(name, ...data) {
109
+ let canceled = false;
110
+ const events = __generateEventIfNotExisted(this);
111
+ const event = events[name] || [];
112
+ for (let one of event.slice()) {
113
+ const [callback, once = false] = one;
114
+ const result = callback(...data);
115
+ if (once)
116
+ this.off(name, callback);
117
+ if (result === false)
118
+ canceled = true;
119
+ }
120
+ return canceled;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * rtc 基础抽象类
126
+ */
127
+ class CoreRTC extends Subscribe {
128
+ }
129
+
130
+ /**
131
+ * rtc 类型
132
+ */
133
+ exports.RTCType = void 0;
134
+ (function (RTCType) {
135
+ RTCType["RealseeBrowserRTC"] = "RealseeBrowserRTC";
136
+ RTCType["RealseeVRWebViewRTC"] = "RealseeVRWebViewRTC";
137
+ RTCType["RealseeBrowserChimeRTC"] = "RealseeBrowserChimeRTC";
138
+ })(exports.RTCType || (exports.RTCType = {}));
139
+
140
+ // uuid
141
+ function S4() {
142
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
143
+ }
144
+ /**
145
+ * 基于伪随机数生成 **uuid**。
146
+ */
147
+ function uuid() {
148
+ // then to call it, plus stitch in '4' in the third group
149
+ return (S4() +
150
+ S4() +
151
+ '-' +
152
+ S4() +
153
+ '-4' +
154
+ S4().substr(0, 3) +
155
+ '-' +
156
+ S4() +
157
+ '-' +
158
+ S4() +
159
+ S4() +
160
+ S4()).toLowerCase();
161
+ }
162
+
163
+ class BrowserRTC extends CoreRTC {
164
+ constructor(options) {
165
+ super();
166
+ this.type = exports.RTCType.RealseeBrowserRTC;
167
+ this.joined = false;
168
+ this.micro = false;
169
+ this.voiceId = '';
170
+ this._getVoiceSign = () => {
171
+ throw new Error('方法 getVoiceSign 未实现');
172
+ };
173
+ this.$dom = document.createElement('div');
174
+ this._trtc = {
175
+ client: null,
176
+ stream: null,
177
+ };
178
+ this.join = async (options) => {
179
+ var _a;
180
+ this.emit('joinWillStart');
181
+ const createClientOptions = await this._getVoiceSign({
182
+ voiceId: options.voiceId,
183
+ roomId: options.roomId,
184
+ userId: options.userId,
185
+ });
186
+ // 1. 创建client
187
+ this._trtc.client = TRTC__default["default"].createClient({
188
+ mode: 'rtc',
189
+ ...createClientOptions,
190
+ });
191
+ (_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.enableAudioVolumeEvaluation();
192
+ // 2. 订阅事件
193
+ this._registerRtcEvent();
194
+ // 3. 加入语音房间
195
+ let result = await new Promise((resolve) => {
196
+ var _a;
197
+ (_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.join({ roomId: Number(options.voiceId) }).then(() => resolve(true)).catch(() => resolve(false));
198
+ });
199
+ this.joined = result;
200
+ if (!result)
201
+ return false; // 进房失败
202
+ // 4. 创建本地流
203
+ this._trtc.stream = TRTC__default["default"].createStream({
204
+ userId: createClientOptions.userId,
205
+ audio: true,
206
+ video: false,
207
+ });
208
+ // 5. 初始化本地流
209
+ result = await new Promise((resolve) => {
210
+ var _a;
211
+ (_a = this._trtc.stream) === null || _a === void 0 ? void 0 : _a.initialize().then(() => resolve(true)).catch(() => resolve(false));
212
+ });
213
+ // 6. 发布本地流
214
+ result = await new Promise((resolve) => {
215
+ var _a;
216
+ (_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.publish(this._trtc.stream).then(() => resolve(true)).catch(() => resolve(false));
217
+ });
218
+ this.joined = result;
219
+ if (this.joined)
220
+ this.emit('joined');
221
+ return result;
222
+ };
223
+ this._handleStreamAdded = (event) => {
224
+ var _a;
225
+ const remoteStream = event.stream;
226
+ console.log('远端流增加: ' + remoteStream.getId());
227
+ //订阅远端流
228
+ (_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.subscribe(remoteStream);
229
+ };
230
+ this._handleStreamSubscribed = (event) => {
231
+ const remoteStream = event.stream;
232
+ console.log('远端流订阅成功:' + remoteStream.getId());
233
+ const playId = remoteStream.getId();
234
+ const domId = `rs-rtc-remote_stream-${playId}`;
235
+ const dom = document.createElement('div');
236
+ dom.id = domId;
237
+ this.$dom.appendChild(dom);
238
+ // 播放远端流
239
+ remoteStream.play(domId);
240
+ };
241
+ this._getVoiceSign = options.getVoiceSign;
242
+ this._initParentDom();
243
+ }
244
+ _initParentDom() {
245
+ this.$dom.id = `rs-rtc-${uuid()}`;
246
+ this.$dom.style.display = 'none';
247
+ document.body.appendChild(this.$dom);
248
+ }
249
+ quit() {
250
+ return new Promise(async (resolve) => {
251
+ var _a, _b;
252
+ this.joined = false;
253
+ if (this._trtc.stream) {
254
+ await ((_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.unpublish(this._trtc.stream));
255
+ this._trtc.stream.stop();
256
+ this._trtc.stream.close();
257
+ this._trtc.stream = null;
258
+ }
259
+ (_b = this._trtc.client) === null || _b === void 0 ? void 0 : _b.leave().then(() => (this._trtc.client = null)).then(() => resolve(true)).catch(() => resolve(false));
260
+ });
261
+ }
262
+ detectMicro() {
263
+ return new Promise((resolve) => {
264
+ const rule = { audio: true, video: false };
265
+ try {
266
+ navigator.mediaDevices
267
+ .getUserMedia(rule)
268
+ .then(() => resolve(true))
269
+ .catch(() => resolve(false));
270
+ }
271
+ catch (e) {
272
+ console.error(e);
273
+ resolve(false);
274
+ }
275
+ });
276
+ }
277
+ toggleMicro(flag) {
278
+ var _a, _b, _c, _d;
279
+ return Promise.resolve((flag
280
+ ? (_b = (_a = this._trtc) === null || _a === void 0 ? void 0 : _a.stream) === null || _b === void 0 ? void 0 : _b.unmuteAudio()
281
+ : (_d = (_c = this._trtc) === null || _c === void 0 ? void 0 : _c.stream) === null || _d === void 0 ? void 0 : _d.muteAudio()) || false);
282
+ }
283
+ shock() {
284
+ throw new Error('Method not implemented.');
285
+ }
286
+ _registerRtcEvent() {
287
+ var _a, _b, _c, _d;
288
+ (_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.on('stream-added', this._handleStreamAdded);
289
+ (_b = this._trtc.client) === null || _b === void 0 ? void 0 : _b.on('stream-subscribed', this._handleStreamSubscribed);
290
+ (_c = this._trtc.client) === null || _c === void 0 ? void 0 : _c.on('audio-volume', (event) => this.emit('userVolumes', [
291
+ { userId: event.userId, audioVolume: event.audioVolume },
292
+ ]));
293
+ (_d = this._trtc.client) === null || _d === void 0 ? void 0 : _d.on('error', (event) => this.emit('error', event));
294
+ }
295
+ }
296
+
297
+ /**
298
+ * amazon-chime-sdk-js 适配的rtc实现
299
+ */
300
+ class BrowserRTC4Chime extends CoreRTC {
301
+ constructor(options) {
302
+ super();
303
+ this.type = exports.RTCType.RealseeBrowserChimeRTC;
304
+ this.joined = false;
305
+ this.micro = false;
306
+ this.voiceId = '';
307
+ this.userId = '';
308
+ this.deviceChangeObserver = {};
309
+ this.audioVideoObserver = {};
310
+ this._getVoiceSign = () => {
311
+ throw new Error('方法 getVoiceSign 未实现');
312
+ };
313
+ this.$dom = document.createElement('div');
314
+ this.$audio = document.createElement('audio');
315
+ /**
316
+ * 对audio标签初始化
317
+ */
318
+ this._initDom = () => {
319
+ this.$audio.id = `rs-rtc-${uuid()}`;
320
+ this.$dom.id = `rs-rtc-${uuid()}`;
321
+ this.$dom.appendChild(this.$audio);
322
+ document.body.appendChild(this.$dom);
323
+ };
324
+ /**
325
+ * 初始化事件监听器
326
+ */
327
+ this.initObservers = () => {
328
+ // 输入输出设备变化的监听器
329
+ this.deviceChangeObserver = {
330
+ audioInputsChanged: (freshAudioInputDeviceList) => {
331
+ // An array of MediaDeviceInfo objects
332
+ freshAudioInputDeviceList === null || freshAudioInputDeviceList === void 0 ? void 0 : freshAudioInputDeviceList.forEach((mediaDeviceInfo) => {
333
+ this.logger.info(`Device ID: ${mediaDeviceInfo.deviceId} Microphone: ${mediaDeviceInfo.label}`);
334
+ });
335
+ },
336
+ audioOutputsChanged: (freshAudioOutputDeviceList) => {
337
+ this.logger.info(`Audio outputs updated: ${freshAudioOutputDeviceList}`);
338
+ },
339
+ videoInputsChanged: (freshVideoInputDeviceList) => {
340
+ this.logger.info(`Video inputs updated: ${freshVideoInputDeviceList}`);
341
+ },
342
+ audioInputMuteStateChanged: (device, muted) => {
343
+ this.logger.info(`Device ${device.toString()} ${muted ? 'is muted in hardware' : 'is not muted'}`);
344
+ },
345
+ };
346
+ // 流变化监听器
347
+ this.audioVideoObserver = {
348
+ audioVideoDidStart: () => {
349
+ this.logger.info('Started');
350
+ },
351
+ audioVideoDidStop: (sessionStatus) => {
352
+ // See the "Stopping a session" section for details.
353
+ this.logger.info(`Stopped with a session status code: ${sessionStatus.statusCode()}`);
354
+ },
355
+ audioVideoDidStartConnecting: (reconnecting) => {
356
+ if (reconnecting) {
357
+ // e.g. the WiFi connection is dropped.
358
+ this.logger.info('Attempting to reconnect');
359
+ }
360
+ },
361
+ };
362
+ };
363
+ /**
364
+ * 注册rtc事件
365
+ */
366
+ this._registerRtcEvent = () => {
367
+ var _a, _b, _c, _d, _e, _f;
368
+ 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) || '';
369
+ if (presentAttendeeId) {
370
+ // 处理音量变化
371
+ const roster = new Map();
372
+ const getUserVolumes = () => {
373
+ const result = [];
374
+ roster.forEach((v, k) => {
375
+ result.push({
376
+ userId: v.userId,
377
+ volume: v.muted || v.signalStrength === 0 || !Boolean(v.volume)
378
+ ? 0
379
+ : v.volume,
380
+ });
381
+ });
382
+ return result;
383
+ };
384
+ (_d = this.meetingSession) === null || _d === void 0 ? void 0 : _d.audioVideo.realtimeSubscribeToAttendeeIdPresence((presentAttendeeId, present, externalUserId) => {
385
+ var _a;
386
+ if (!present) {
387
+ roster.delete(presentAttendeeId);
388
+ this.emit('userVolumes', getUserVolumes());
389
+ return;
390
+ }
391
+ (_a = this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.realtimeSubscribeToVolumeIndicator(presentAttendeeId, (attendeeId, volume, muted, signalStrength) => {
392
+ const baseAttendeeId = new amazonChimeSdkJs.DefaultModality(attendeeId).base();
393
+ if (baseAttendeeId !== attendeeId) {
394
+ // Optional: Do not include the content attendee (attendee-id#content) in the roster.
395
+ // See the "Screen and content share" section for details.
396
+ return;
397
+ }
398
+ roster.set(attendeeId, {
399
+ userId: externalUserId || attendeeId,
400
+ volume,
401
+ muted,
402
+ signalStrength,
403
+ });
404
+ this.emit('userVolumes', getUserVolumes());
405
+ });
406
+ });
407
+ // 弱网
408
+ (_e = this.meetingSession) === null || _e === void 0 ? void 0 : _e.audioVideo.realtimeSubscribeToVolumeIndicator(presentAttendeeId, (attendeeId, volume, muted, signalStrength) => {
409
+ const baseAttendeeId = new amazonChimeSdkJs.DefaultModality(attendeeId).base();
410
+ if (baseAttendeeId === attendeeId) {
411
+ if (signalStrength !== null && signalStrength !== 1) {
412
+ this.emit('weakNetwork');
413
+ }
414
+ }
415
+ });
416
+ // 报错
417
+ (_f = this.meetingSession) === null || _f === void 0 ? void 0 : _f.audioVideo.realtimeSubscribeToFatalError((error) => this.emit('error', error));
418
+ }
419
+ };
420
+ // 挂载签名钩子
421
+ this._getVoiceSign = options.getVoiceSign;
422
+ this._initDom();
423
+ this.logger = new amazonChimeSdkJs.ConsoleLogger('WebRTCLogger', options.logLevel || amazonChimeSdkJs.LogLevel.OFF);
424
+ this.deviceController = new amazonChimeSdkJs.DefaultDeviceController(this.logger);
425
+ this.initObservers();
426
+ }
427
+ /**
428
+ * 加入语音会议
429
+ * @param options
430
+ * @returns
431
+ */
432
+ async join(options) {
433
+ return new Promise(async (success, fail) => {
434
+ var _a;
435
+ this.emit('joinWillStart');
436
+ try {
437
+ // 取签名
438
+ const { sdkAppId, userId, roomId, userSig } = await this._getVoiceSign({
439
+ ...options,
440
+ roomId: options.roomId || 0,
441
+ });
442
+ this.userId = userId;
443
+ const { attendence, vendor_wrapper, } = JSON.parse(decodeURIComponent(userSig));
444
+ // 初始化配置
445
+ const configuration = new amazonChimeSdkJs.MeetingSessionConfiguration({
446
+ Meeting: vendor_wrapper,
447
+ }, {
448
+ Attendee: {
449
+ ExternalUserId: attendence.external_user_id,
450
+ AttendeeId: attendence.attendee_id,
451
+ JoinToken: attendence.join_token,
452
+ },
453
+ });
454
+ // 初始化会议会话
455
+ this.meetingSession = new amazonChimeSdkJs.DefaultMeetingSession(configuration, this.logger, this.deviceController);
456
+ // 注册事件
457
+ this._registerRtcEvent();
458
+ // 绑定监听器
459
+ this.meetingSession.audioVideo.addDeviceChangeObserver(this.deviceChangeObserver);
460
+ this.meetingSession.audioVideo.addObserver(this.audioVideoObserver);
461
+ // 绑定播放器
462
+ this.meetingSession.audioVideo.bindAudioElement(this.$audio);
463
+ const observer = {
464
+ audioVideoDidStart: () => {
465
+ var _a;
466
+ (_a = this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.realtimeMuteLocalAudio();
467
+ this.joined = true;
468
+ this.emit('joined');
469
+ success(true);
470
+ },
471
+ audioVideoDidStop: () => {
472
+ this.joined = false;
473
+ success(false);
474
+ },
475
+ };
476
+ this.meetingSession.audioVideo.addObserver(observer);
477
+ // 选择语音输入设备
478
+ const audioInputDevices = await this.deviceController.listAudioInputDevices(true);
479
+ const defaultAudioInput = audioInputDevices.find((device) => device.deviceId === 'default');
480
+ const otherAudioInput = audioInputDevices.find((device) => device.deviceId !== '');
481
+ this.audioInput = defaultAudioInput || otherAudioInput;
482
+ await this.meetingSession.audioVideo.chooseVideoInputDevice(null);
483
+ await this.meetingSession.audioVideo.chooseAudioInputDevice(((_a = this.audioInput) === null || _a === void 0 ? void 0 : _a.deviceId) || 'default');
484
+ this.meetingSession.audioVideo.start();
485
+ }
486
+ catch (e) {
487
+ this.emit('error', e);
488
+ this.logger.error(e.message);
489
+ success(false);
490
+ }
491
+ });
492
+ }
493
+ quit() {
494
+ return new Promise((success, fail) => {
495
+ var _a, _b;
496
+ this.joined = false;
497
+ const observer = {
498
+ audioVideoDidStop: (sessionStatus) => {
499
+ const sessionStatusCode = sessionStatus.statusCode();
500
+ if (sessionStatusCode === amazonChimeSdkJs.MeetingSessionStatusCode.Left) {
501
+ /*
502
+ - You called meetingSession.audioVideo.stop().
503
+ - When closing a browser window or page, Chime SDK attempts to leave the session.
504
+ */
505
+ this.logger.info('You left the session');
506
+ success(true);
507
+ }
508
+ else {
509
+ this.logger.info(`Stopped with a session status code: ${sessionStatusCode}`);
510
+ success(true);
511
+ }
512
+ },
513
+ };
514
+ (_a = this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.addObserver(observer);
515
+ (_b = this.meetingSession) === null || _b === void 0 ? void 0 : _b.audioVideo.stop();
516
+ });
517
+ }
518
+ async detectMicro() {
519
+ return new Promise((resolve) => {
520
+ const rule = { audio: true, video: false };
521
+ try {
522
+ navigator.mediaDevices
523
+ .getUserMedia(rule)
524
+ .then(() => resolve(true))
525
+ .catch(() => resolve(false));
526
+ }
527
+ catch (e) {
528
+ this.logger.error(e.message);
529
+ resolve(false);
530
+ }
531
+ });
532
+ }
533
+ async toggleMicro(flag) {
534
+ var _a, _b, _c;
535
+ if (flag) {
536
+ (_a = this.meetingSession) === null || _a === void 0 ? void 0 : _a.audioVideo.realtimeUnmuteLocalAudio();
537
+ }
538
+ else {
539
+ (_b = this.meetingSession) === null || _b === void 0 ? void 0 : _b.audioVideo.realtimeMuteLocalAudio();
540
+ }
541
+ const muted = (_c = this.meetingSession) === null || _c === void 0 ? void 0 : _c.audioVideo.realtimeIsLocalAudioMuted();
542
+ if (muted !== undefined) {
543
+ return flag !== muted;
544
+ }
545
+ else {
546
+ return false;
547
+ }
548
+ }
549
+ shock() {
550
+ throw new Error('Method not implemented.');
551
+ }
552
+ }
553
+
554
+ /**
555
+ * rtc加入返回值code枚举
556
+ */
557
+ exports.RTCJoinedInfoCodeEnum = void 0;
558
+ (function (RTCJoinedInfoCodeEnum) {
559
+ /**
560
+ * 成功
561
+ */
562
+ RTCJoinedInfoCodeEnum[RTCJoinedInfoCodeEnum["Success"] = 0] = "Success";
563
+ /**
564
+ * 失败
565
+ */
566
+ RTCJoinedInfoCodeEnum[RTCJoinedInfoCodeEnum["Failure"] = 1] = "Failure";
567
+ /**
568
+ * 重复加入
569
+ */
570
+ RTCJoinedInfoCodeEnum[RTCJoinedInfoCodeEnum["ReJoin"] = 2] = "ReJoin";
571
+ /**
572
+ * 无麦克风权限
573
+ */
574
+ RTCJoinedInfoCodeEnum[RTCJoinedInfoCodeEnum["NoMicroPermission"] = 3] = "NoMicroPermission";
575
+ })(exports.RTCJoinedInfoCodeEnum || (exports.RTCJoinedInfoCodeEnum = {}));
576
+
577
+ class VRWebViewRTC extends CoreRTC {
578
+ constructor({ jsBridge, getVoiceSign }) {
579
+ super();
580
+ this.type = exports.RTCType.RealseeVRWebViewRTC;
581
+ this.joined = false;
582
+ this.micro = false;
583
+ this.voiceId = '';
584
+ this.options = { jsBridge, getVoiceSign };
585
+ this.jsBridge.callAndListen('live/userVolumes', (userVolumes) => {
586
+ this.emit('userVolumes', userVolumes);
587
+ });
588
+ this.jsBridge.callAndListen('live/weakNetwork', (weakNetwork) => {
589
+ if (weakNetwork)
590
+ this.emit('weakNetwork');
591
+ });
592
+ }
593
+ get jsBridge() {
594
+ return this.options.jsBridge;
595
+ }
596
+ async join(options) {
597
+ this.emit('joinWillStart');
598
+ const { sdkAppId, userId, userSig } = await this.options.getVoiceSign(options);
599
+ this.type = options.type;
600
+ const [res, error] = await this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${sdkAppId}&userID=${userId}&roomID=${Number(options.voiceId)}&userSig=${userSig}`);
601
+ if (!res) {
602
+ this.emit('error', error ? error : new Error('加入房间失败:未知异常。'));
603
+ this.joined = false;
604
+ }
605
+ else {
606
+ if (res.code === exports.RTCJoinedInfoCodeEnum.Success) {
607
+ this.emit('joined');
608
+ this.joined = true;
609
+ }
610
+ else {
611
+ this.emit('error', res);
612
+ this.joined = false;
613
+ }
614
+ }
615
+ return this.joined;
616
+ }
617
+ async quit() {
618
+ const [res, error] = await this.jsBridge.callAndBackfeed('live/quit');
619
+ if (res === null) {
620
+ this.emit('error', error ? error : new Error('退出房间失败:未知异常。'));
621
+ }
622
+ this.joined = false;
623
+ return !!res;
624
+ }
625
+ async detectMicro() {
626
+ const [res, error] = await this.jsBridge.detectMicro();
627
+ if (res === null) {
628
+ this.emit('error', error ? error : new Error('麦克风监测异常!'));
629
+ return false;
630
+ }
631
+ return res;
632
+ }
633
+ async toggleMicro(flag) {
634
+ const [res, error] = await this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${!!flag ? 1 : 0}`);
635
+ if (res === null) {
636
+ this.emit('error', error ? error : new Error('麦克风监测异常!'));
637
+ return false;
638
+ }
639
+ this.micro = res;
640
+ return res;
641
+ }
642
+ shock() {
643
+ this.jsBridge.shock(1);
644
+ }
645
+ }
646
+
647
+ /**
648
+ * WebSocket 通信指令
649
+ * - 下行:服务端推送数据
650
+ * - 上行:客户端上报数据
651
+ */
652
+ exports.Command = void 0;
653
+ (function (Command) {
654
+ /* 当前用户信息:下行 */
655
+ Command["SelfUserInfo"] = "SELF_USER_INFO";
656
+ /* 房间信息:下行 */
657
+ Command["RoomInfo"] = "ROOM_INFO";
658
+ /* RTC信息:下行 */
659
+ Command["RTCInfo"] = "RTC_INFO";
660
+ /* 用户列表:下行 */
661
+ Command["UserList"] = "USER_LIST";
662
+ /* 内置消息:下行、上行 */
663
+ Command["BuiltinMsg"] = "BUILTIN_MSG";
664
+ /* 自定义广播事件消息:下行、上行 */
665
+ Command["CustomEvent"] = "CUSTOM_EVENT";
666
+ /* 帧数据同步:下行、上行 */
667
+ Command["KeyframeSync"] = "KEYFRAME_SYNC";
668
+ /* 被踢出房间:下行 */
669
+ Command["UserKickOut"] = "USER_KICK_OUT";
670
+ })(exports.Command || (exports.Command = {}));
671
+ /**
672
+ * 内置事件类型。
673
+ */
674
+ exports.BuiltinEventType = void 0;
675
+ (function (BuiltinEventType) {
676
+ /**
677
+ * 变更用户状态。
678
+ */
679
+ BuiltinEventType["UserChange"] = "user_change";
680
+ /**
681
+ * 变更房间状态。
682
+ */
683
+ BuiltinEventType["RoomChange"] = "room_change";
684
+ })(exports.BuiltinEventType || (exports.BuiltinEventType = {}));
685
+ /**
686
+ * 内置事件行为类型。
687
+ */
688
+ exports.BuiltinActionType = void 0;
689
+ (function (BuiltinActionType) {
690
+ /**
691
+ * 修改麦克风状态。
692
+ */
693
+ BuiltinActionType["UserMicroStatus"] = "change_micro_status";
694
+ /**
695
+ * 同步当前用户状态:客户端麦克风状态已经修改成功,通知服务端
696
+ */
697
+ BuiltinActionType["UserMicroStatusSync"] = "sync_micro_status";
698
+ /**
699
+ * 调整某些用户的权限。
700
+ */
701
+ BuiltinActionType["UserPermission"] = "change_permission";
702
+ /**
703
+ * 用户状态发生改变。
704
+ */
705
+ BuiltinActionType["UserStatus"] = "change_status";
706
+ /**
707
+ * 更新用户信息。
708
+ */
709
+ BuiltinActionType["UserInfo"] = "change_info";
710
+ /**
711
+ * 关闭房间。
712
+ */
713
+ BuiltinActionType["RoomClose"] = "close";
714
+ })(exports.BuiltinActionType || (exports.BuiltinActionType = {}));
715
+ /**
716
+ * 麦克风状态。
717
+ */
718
+ exports.MicroStatus = void 0;
719
+ (function (MicroStatus) {
720
+ MicroStatus["OPEN"] = "OPEN";
721
+ MicroStatus["CLOSE"] = "CLOSE";
722
+ })(exports.MicroStatus || (exports.MicroStatus = {}));
723
+ /**
724
+ * 解析下后端数据格式。
725
+ * @param jsonTxt - JSON序列化后的文本。
726
+ * @returns false 标识解析失败;解析成功返回 {@link LiveMsg} 实例。
727
+ */
728
+ function parseLiveMsg(jsonTxt) {
729
+ try {
730
+ const msg = JSON.parse(jsonTxt);
731
+ const resMsg = {
732
+ code: msg.code,
733
+ message: msg.message,
734
+ command: msg.command,
735
+ roomCode: msg.room_code,
736
+ appID: msg.app_id,
737
+ requestId: msg.request_id,
738
+ frontRequestId: msg.front_request_id,
739
+ triggerUserID: msg.trigger_user_id,
740
+ data: msg.data || {},
741
+ };
742
+ const undefinedKeys = Object.keys(resMsg).filter((key) => resMsg[key] === undefined);
743
+ if (undefinedKeys.length > 0) {
744
+ console.warn(`推送数据格式异常:${undefinedKeys.join(" ")} 值不存在!`);
745
+ }
746
+ return resMsg;
747
+ }
748
+ catch (error) {
749
+ // notcare? 过滤掉所有不符合规范的数据
750
+ return false;
751
+ }
752
+ }
753
+
754
+ /**
755
+ * 用户当前状态枚举。
756
+ */
757
+ exports.UserStatus = void 0;
758
+ (function (UserStatus) {
759
+ /**
760
+ * 正常
761
+ */
762
+ UserStatus[UserStatus["Normal"] = 0] = "Normal";
763
+ /**
764
+ * 被移除
765
+ */
766
+ UserStatus[UserStatus["Removed"] = 1] = "Removed";
767
+ /**
768
+ * 被替换
769
+ */
770
+ UserStatus[UserStatus["Replaced"] = 2] = "Replaced";
771
+ })(exports.UserStatus || (exports.UserStatus = {}));
772
+ exports.MemUserStatus = void 0;
773
+ (function (MemUserStatus) {
774
+ MemUserStatus["WAIT_ENTER"] = "WAIT_ENTER";
775
+ MemUserStatus["ONLINE"] = "ONLINE";
776
+ MemUserStatus["LEAVE"] = "LEAVE";
777
+ MemUserStatus["KICK_OUT"] = "KICK_OUT";
778
+ MemUserStatus["BE_REPLACE"] = "BE_REPLACE";
779
+ MemUserStatus["EXCEPTION"] = "EXCEPTION";
780
+ })(exports.MemUserStatus || (exports.MemUserStatus = {}));
781
+
782
+ /**
783
+ * WebSocket 连接状态枚举
784
+ */
785
+ exports.WebSocketState = void 0;
786
+ (function (WebSocketState) {
787
+ /**
788
+ * 尚未初始化
789
+ */
790
+ WebSocketState[WebSocketState["NOTINITIALIZED"] = -1] = "NOTINITIALIZED";
791
+ /**
792
+ * 正在链接中
793
+ */
794
+ WebSocketState[WebSocketState["CONNECTING"] = 0] = "CONNECTING";
795
+ /**
796
+ * 已经链接并且可以通讯
797
+ */
798
+ WebSocketState[WebSocketState["OPEN"] = 1] = "OPEN";
799
+ /**
800
+ * 连接正在关闭
801
+ */
802
+ WebSocketState[WebSocketState["CLOSING"] = 2] = "CLOSING";
803
+ /**
804
+ * 连接已关闭或者没有链接成功
805
+ */
806
+ WebSocketState[WebSocketState["CLOSED"] = 3] = "CLOSED";
807
+ })(exports.WebSocketState || (exports.WebSocketState = {}));
808
+ exports.WebSocketErrorType = void 0;
809
+ (function (WebSocketErrorType) {
810
+ WebSocketErrorType["Error"] = "Error";
811
+ WebSocketErrorType["Close"] = "Close";
812
+ WebSocketErrorType["MicroAuth"] = "MicroAuth";
813
+ WebSocketErrorType["DuplicateConnect"] = "DuplicateConnect";
814
+ WebSocketErrorType["IllegalURL"] = "IllegalURL";
815
+ WebSocketErrorType["Unknown"] = "Unknown";
816
+ WebSocketErrorType["IllegalArgs"] = "IllegalArgs";
817
+ })(exports.WebSocketErrorType || (exports.WebSocketErrorType = {}));
818
+ /**
819
+ * WebSocket 异常关闭枚举:https://developer.mozilla.org/zh-CN/docs/Web/API/CloseEvent。
820
+ */
821
+ exports.WebSocketCloseError = void 0;
822
+ (function (WebSocketCloseError) {
823
+ /**
824
+ * 终端离开, 可能因为服务端错误, 也可能因为浏览器正从打开连接的页面跳转离开。
825
+ */
826
+ WebSocketCloseError["Err_1001"] = "CLOSE_GOING_AWAY";
827
+ /**
828
+ * 由于协议错误而中断连接。
829
+ */
830
+ WebSocketCloseError["Err_1002"] = "CLOSE_PROTOCOL_ERROR";
831
+ /**
832
+ * 由于接收到不允许的数据类型而断开连接 (如仅接收文本数据的终端接收到了二进制数据)。
833
+ */
834
+ WebSocketCloseError["Err_1003"] = "CLOSE_UNSUPPORTED";
835
+ /**
836
+ * 安全因素或WebSocket连接次数达到上限。
837
+ */
838
+ WebSocketCloseError["Err_1006"] = "CLOSE_ABNORMAL";
839
+ /**
840
+ * 由于收到了格式不符的数据而断开连接 (如文本消息中包含了非 UTF-8 数据)。
841
+ */
842
+ WebSocketCloseError["Err_1007"] = "Unsupported Data";
843
+ /**
844
+ * 由于收到不符合约定的数据而断开连接。
845
+ */
846
+ WebSocketCloseError["Err_1008"] = "Policy Violation";
847
+ /**
848
+ * 由于收到过大的数据帧而断开连接。
849
+ */
850
+ WebSocketCloseError["Err_1009"] = "CLOSE_TOO_LARGE";
851
+ /**
852
+ * 未知错误。
853
+ */
854
+ WebSocketCloseError["Err_unknown"] = "unknown";
855
+ })(exports.WebSocketCloseError || (exports.WebSocketCloseError = {}));
856
+ function parseWSClsErr(code) {
857
+ switch (code) {
858
+ case 1001: {
859
+ return exports.WebSocketCloseError.Err_1001;
860
+ }
861
+ case 1002: {
862
+ return exports.WebSocketCloseError.Err_1002;
863
+ }
864
+ case 1003: {
865
+ return exports.WebSocketCloseError.Err_1003;
866
+ }
867
+ case 1006: {
868
+ return exports.WebSocketCloseError.Err_1006;
869
+ }
870
+ case 1007: {
871
+ return exports.WebSocketCloseError.Err_1007;
872
+ }
873
+ case 1008: {
874
+ return exports.WebSocketCloseError.Err_1008;
875
+ }
876
+ case 1009: {
877
+ return exports.WebSocketCloseError.Err_1009;
878
+ }
879
+ }
880
+ return exports.WebSocketCloseError.Err_unknown;
881
+ }
882
+
883
+ function appendUri(uri, query) {
884
+ const hasQuery = uri.indexOf('?') !== -1;
885
+ const newQuery = Object.keys(query).reduce((accu, curr, idx) => `${accu}${(idx === 0 && !hasQuery) ? '?' : '&'}${curr}=${query[curr]}`, '');
886
+ return uri + newQuery;
887
+ }
888
+
889
+ /**
890
+ * 判断是否是真实的对象类型
891
+ * @param value
892
+ * @returns
893
+ */
894
+ function isTrulyObject(value) {
895
+ return Object.prototype.toString.call(value) === '[object Object]';
896
+ }
897
+ /**
898
+ * 判断基础类型是否相等
899
+ * @param value
900
+ * @param other
901
+ * @returns
902
+ */
903
+ function baseIsEqual(value, other) {
904
+ if (value === other)
905
+ return true;
906
+ if (typeof value !== typeof other)
907
+ return false;
908
+ if (Number.isNaN(value) && Number.isNaN(other))
909
+ return true;
910
+ return false;
911
+ }
912
+ /**
913
+ * 对象浅比较
914
+ * @param value
915
+ * @param other
916
+ * @returns
917
+ */
918
+ function objEqualShallow(value, other) {
919
+ const valueProps = Object.getOwnPropertyNames(value);
920
+ const otherProps = Object.getOwnPropertyNames(other);
921
+ if (valueProps.length !== otherProps.length)
922
+ return false;
923
+ for (let i = 0, len = valueProps.length; i < len; i++) {
924
+ const propName = valueProps[i];
925
+ if (!baseIsEqual(value[propName], other[propName]))
926
+ return false;
927
+ }
928
+ return true;
929
+ }
930
+ /**
931
+ * 数组浅比较
932
+ * @param value
933
+ * @param other
934
+ * @returns
935
+ */
936
+ function arrayEqualShallow(value, other) {
937
+ if (value.length !== other.length)
938
+ return false;
939
+ for (let i = 0, len = value.length; i < len; i++) {
940
+ if (!baseIsEqual(value[i], other[i]))
941
+ return false;
942
+ }
943
+ return true;
944
+ }
945
+ /**
946
+ * 变量浅比较
947
+ * @param value
948
+ * @param other
949
+ * @returns
950
+ */
951
+ function isShallowEqual(value, other) {
952
+ if (baseIsEqual(value, other))
953
+ return true;
954
+ if (isTrulyObject(value) && isTrulyObject(other))
955
+ return objEqualShallow(value, other);
956
+ if (Array.isArray(value) && Array.isArray(other))
957
+ return arrayEqualShallow(value, other);
958
+ return false;
959
+ }
960
+ /**
961
+ * 对象深比较
962
+ * @param value
963
+ * @param other
964
+ * @returns
965
+ */
966
+ function isDeepEqual(value, other) {
967
+ if (baseIsEqual(value, other))
968
+ return true;
969
+ if (isTrulyObject(value) && isTrulyObject(other))
970
+ return objEqualDeep(value, other);
971
+ if (Array.isArray(value) && Array.isArray(other))
972
+ return arrayEqualDeep(value, other);
973
+ return false;
974
+ }
975
+ /**
976
+ * 数组深比较
977
+ * @param value
978
+ * @param other
979
+ * @returns
980
+ */
981
+ function arrayEqualDeep(value, other) {
982
+ if (value.length !== other.length)
983
+ return false;
984
+ for (let i = 0, len = value.length; i < len; i++) {
985
+ if (!isDeepEqual(value[i], other[i]))
986
+ return false;
987
+ }
988
+ return true;
989
+ }
990
+ /**
991
+ * 对象深比较
992
+ * @param value
993
+ * @param other
994
+ * @returns
995
+ */
996
+ function objEqualDeep(value, other) {
997
+ const valueProps = Object.getOwnPropertyNames(value);
998
+ const otherProps = Object.getOwnPropertyNames(other);
999
+ if (valueProps.length !== otherProps.length)
1000
+ return false;
1001
+ for (let i = 0, len = valueProps.length; i < len; i++) {
1002
+ const propName = valueProps[i];
1003
+ if (!isDeepEqual(value[propName], other[propName]))
1004
+ return false;
1005
+ }
1006
+ return true;
1007
+ }
1008
+ /**
1009
+ * 对象比较。
1010
+ * @param value 第一个比较的值。
1011
+ * @param other 第二个比较的值。
1012
+ * @param options 可选参数,可选项:`deep` 是否深比较。
1013
+ * @returns {boolean} 是否相等。
1014
+ */
1015
+ function equal(value, other, opt) {
1016
+ if (!opt.deep)
1017
+ return isShallowEqual(value, other);
1018
+ return isDeepEqual(value, other);
1019
+ }
1020
+
1021
+ class LiveController {
1022
+ constructor(options) {
1023
+ this.readyState = exports.WebSocketState.NOTINITIALIZED;
1024
+ this.canSync = true;
1025
+ this.connecting = false;
1026
+ this.keyframes = {};
1027
+ /**
1028
+ * 检测 WebSocket.readyState 状态
1029
+ */
1030
+ this.checkReadyState = (live) => {
1031
+ do {
1032
+ if (!this.webSocket) {
1033
+ if (this.readyState !== exports.WebSocketState.NOTINITIALIZED) {
1034
+ this.readyState = exports.WebSocketState.NOTINITIALIZED;
1035
+ live.emit('ws.readyStateUpdate', this.readyState);
1036
+ }
1037
+ break;
1038
+ }
1039
+ const readyState = this.webSocket.readyState;
1040
+ if (readyState !== this.readyState) {
1041
+ this.readyState = readyState;
1042
+ live.emit('ws.readyStateUpdate', this.readyState);
1043
+ }
1044
+ } while (false);
1045
+ return this.readyState;
1046
+ };
1047
+ this.dispose = () => {
1048
+ this.disposeWebSocket();
1049
+ this.connecting = false;
1050
+ if (this.healthCheckId) {
1051
+ clearInterval(this.healthCheckId);
1052
+ this.healthCheckId = undefined;
1053
+ }
1054
+ };
1055
+ /**
1056
+ * 销毁WebSocket相关依赖。
1057
+ */
1058
+ this.disposeWebSocket = () => {
1059
+ if (!this.webSocket)
1060
+ return;
1061
+ if (this.onEvtOpnListener) {
1062
+ this.webSocket.removeEventListener('open', this.onEvtOpnListener);
1063
+ this.onEvtOpnListener = undefined;
1064
+ }
1065
+ if (this.onEvtMsgListener) {
1066
+ this.webSocket.removeEventListener('message', this.onEvtMsgListener);
1067
+ this.onEvtMsgListener = undefined;
1068
+ }
1069
+ if (this.onEvtErrListener) {
1070
+ this.webSocket.removeEventListener('error', this.onEvtErrListener);
1071
+ this.onEvtErrListener = undefined;
1072
+ }
1073
+ if (this.onEvtCLEListener) {
1074
+ this.webSocket.removeEventListener('close', this.onEvtCLEListener);
1075
+ this.onEvtCLEListener = undefined;
1076
+ }
1077
+ this.webSocket.close();
1078
+ this.webSocket = undefined;
1079
+ };
1080
+ this.options = Object.assign({ autoConnect: true, healthCheck: 3000 }, options);
1081
+ }
1082
+ /**
1083
+ * 解析数据
1084
+ * @param liveMsg
1085
+ * @param live
1086
+ */
1087
+ handleMessage(liveMsg, live) {
1088
+ var _a, _b, _c;
1089
+ const { command, data, frontRequestId, code, message } = liveMsg;
1090
+ if (code === 'SUCCESS') {
1091
+ switch (command) {
1092
+ /**
1093
+ * 自己的状态变化
1094
+ */
1095
+ case exports.Command.SelfUserInfo: {
1096
+ const selfInfo = data;
1097
+ if (equal(this.selfUserInfo, selfInfo, { deep: true }))
1098
+ return;
1099
+ this.selfUserInfo = selfInfo;
1100
+ live.emit('selfInfoUpdate', this.selfUserInfo, frontRequestId);
1101
+ break;
1102
+ }
1103
+ /**
1104
+ * 房间信息变化
1105
+ */
1106
+ case exports.Command.RoomInfo: {
1107
+ const roomInfo = data;
1108
+ this.roomInfo = Object.assign({}, roomInfo);
1109
+ live.emit('readyKeyframeSync', (roomInfo.last_frame || {}));
1110
+ break;
1111
+ }
1112
+ /**
1113
+ * 语音信息变化
1114
+ */
1115
+ case exports.Command.RTCInfo: {
1116
+ const { voice_id: voiceId, type } = data;
1117
+ /* 如果已经进入语音房间,则不重复进入 --> "RTCInfo" 指令可能会下发多次 */
1118
+ if (live.$RTC.joined) {
1119
+ break;
1120
+ }
1121
+ live.$RTC.join({
1122
+ voiceId,
1123
+ userId: ((_a = this.selfUserInfo) === null || _a === void 0 ? void 0 : _a.id) || '',
1124
+ roomId: (_b = this.roomInfo) === null || _b === void 0 ? void 0 : _b.info.room_code,
1125
+ type,
1126
+ });
1127
+ // 加入房间后 麦克风默认就开启了:需要发个指令。
1128
+ live.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
1129
+ status: exports.MicroStatus.OPEN,
1130
+ });
1131
+ break;
1132
+ }
1133
+ /**
1134
+ * 房间用户列表变化
1135
+ */
1136
+ case exports.Command.UserList: {
1137
+ const userList = data;
1138
+ this.userList = userList;
1139
+ live.emit('userListUpdate', this.userList, frontRequestId);
1140
+ break;
1141
+ }
1142
+ /**
1143
+ * 自定义事件广播
1144
+ */
1145
+ case exports.Command.CustomEvent: {
1146
+ const evtMsg = data;
1147
+ live.emit('broadcast', evtMsg, frontRequestId);
1148
+ break;
1149
+ }
1150
+ /**
1151
+ * 帧数据同步
1152
+ */
1153
+ case exports.Command.KeyframeSync: {
1154
+ const remoteKeyframes = data;
1155
+ // 此处做一层 diff,仅跟本地数据不一致的情况下才广播数据。
1156
+ const keyframes = Object.keys(remoteKeyframes).reduce((accu, curr) => {
1157
+ if (equal(remoteKeyframes[curr], this.keyframes[curr], { deep: true })) {
1158
+ return accu;
1159
+ }
1160
+ const params = [
1161
+ remoteKeyframes[curr],
1162
+ this.keyframes[curr],
1163
+ frontRequestId,
1164
+ ];
1165
+ const evtName = curr;
1166
+ live.keyframes.emit(evtName, ...params);
1167
+ this.keyframes[curr] = remoteKeyframes[curr];
1168
+ accu[curr] = remoteKeyframes[curr];
1169
+ return accu;
1170
+ }, {});
1171
+ live.emit('keyframes', keyframes, frontRequestId);
1172
+ break;
1173
+ }
1174
+ /**
1175
+ * 内置消息
1176
+ */
1177
+ case exports.Command.BuiltinMsg: {
1178
+ const builtinMsg = data;
1179
+ live.emit('builtinEvent', builtinMsg);
1180
+ if (builtinMsg.event_type === exports.BuiltinEventType.UserChange) {
1181
+ live.emit('userChange', builtinMsg);
1182
+ }
1183
+ if (builtinMsg.event_type === exports.BuiltinEventType.RoomChange) {
1184
+ live.emit('roomChange', builtinMsg);
1185
+ }
1186
+ /**
1187
+ * 下发指令自己操作麦克风
1188
+ */
1189
+ if (builtinMsg.event_type === exports.BuiltinEventType.UserChange &&
1190
+ builtinMsg.action === exports.BuiltinActionType.UserMicroStatus) {
1191
+ live.toggleMicro(builtinMsg.data.status === exports.MicroStatus.OPEN);
1192
+ }
1193
+ /**
1194
+ * 如果下发指令退出房间,则 关闭麦克风 及 销毁 WebSocket
1195
+ */
1196
+ if (builtinMsg.event_type === exports.BuiltinEventType.RoomChange &&
1197
+ builtinMsg.action === exports.BuiltinActionType.RoomClose) {
1198
+ (_c = this.options.rtc) === null || _c === void 0 ? void 0 : _c.quit();
1199
+ this.disposeWebSocket();
1200
+ }
1201
+ break;
1202
+ }
1203
+ /**
1204
+ * 被踢出房间
1205
+ */
1206
+ case exports.Command.UserKickOut: {
1207
+ live.emit('kickOut');
1208
+ break;
1209
+ }
1210
+ /**
1211
+ * 其它未知广播
1212
+ */
1213
+ default: {
1214
+ console.warn('unknown command: ', command);
1215
+ }
1216
+ }
1217
+ }
1218
+ else {
1219
+ live.emit('error', liveMsg);
1220
+ }
1221
+ }
1222
+ /**
1223
+ * 发送数据
1224
+ * @param data
1225
+ */
1226
+ sendMessage(data) {
1227
+ if (!this.webSocket)
1228
+ return console.warn('WebSocket has not yet been initialized!');
1229
+ if (!data)
1230
+ return console.warn('WebSocket messages is empty!');
1231
+ this.webSocket.send(JSON.stringify(data));
1232
+ }
1233
+ }
1234
+
1235
+ const unimplementedGetVoiceSign = (params) => Promise.reject('unimplemented method GetVoiceSign');
1236
+ /**
1237
+ * 创建 `live` 实例。
1238
+ */
1239
+ function createLive(options) {
1240
+ const liveController = new LiveController(options);
1241
+ const createLiveMsg = (command, data = {}, toUserIds) => {
1242
+ toUserIds = toUserIds
1243
+ ? Array.isArray(toUserIds)
1244
+ ? toUserIds
1245
+ : [toUserIds]
1246
+ : [];
1247
+ if (toUserIds)
1248
+ data['to_user_ids'] = toUserIds;
1249
+ return { command, front_request_id: uuid(), data };
1250
+ };
1251
+ class LiveTpl extends Subscribe {
1252
+ constructor() {
1253
+ var _a;
1254
+ super();
1255
+ this.keyframes = new Subscribe();
1256
+ // 没有传rtc实例时
1257
+ if (!options.rtc) {
1258
+ // 取指定的内部rtc类型
1259
+ if (options.rtcType) {
1260
+ if (!options.getVoiceSign) {
1261
+ throw new Error('GetVoiceSign method must be passed when using built-in RTC instances');
1262
+ }
1263
+ const getVoiceSign = (_a = options.getVoiceSign) !== null && _a !== void 0 ? _a : unimplementedGetVoiceSign;
1264
+ switch (options.rtcType) {
1265
+ case exports.RTCType.RealseeVRWebViewRTC: {
1266
+ // 内置的 VRWebViewRTC
1267
+ if (!options.jsBridge) {
1268
+ throw new Error('JsBridge instance must be passed when using built-in VRWebViewRTC instances');
1269
+ }
1270
+ liveController.options.rtc = new VRWebViewRTC({
1271
+ jsBridge: options.jsBridge,
1272
+ getVoiceSign,
1273
+ });
1274
+ break;
1275
+ }
1276
+ case exports.RTCType.RealseeBrowserChimeRTC: {
1277
+ // 内置的 RealseeBrowserChimeRTC
1278
+ liveController.options.rtc = new BrowserRTC4Chime({
1279
+ getVoiceSign,
1280
+ logLevel: options.__debug__ ? amazonChimeSdkJs.LogLevel.DEBUG : amazonChimeSdkJs.LogLevel.ERROR,
1281
+ });
1282
+ break;
1283
+ }
1284
+ case exports.RTCType.RealseeBrowserRTC: {
1285
+ // 内置的 RealseeBrowserRTC
1286
+ liveController.options.rtc = new BrowserRTC({
1287
+ getVoiceSign,
1288
+ });
1289
+ break;
1290
+ }
1291
+ default: {
1292
+ throw new Error('unknown built-in RTC type');
1293
+ }
1294
+ }
1295
+ }
1296
+ }
1297
+ if (!liveController.options.rtc) {
1298
+ console.warn('unused rtc');
1299
+ }
1300
+ // 默认自动连接
1301
+ if (liveController.options.url && liveController.options.getTicket) {
1302
+ this.connect();
1303
+ }
1304
+ // 健康检查:WHY --> 在某些WebView特殊场景下 WebSocket.readyState 发生变化时不会出发error\close等事件;
1305
+ // 因此,开启一个定时任务监测 WebSocket.readyState 状态的更新
1306
+ const healthCheck = ((healthCheck) => {
1307
+ if (!healthCheck)
1308
+ return 0;
1309
+ if (healthCheck === true)
1310
+ return 3000;
1311
+ const duration = Number(healthCheck);
1312
+ if (duration > 0)
1313
+ return duration;
1314
+ return 3000;
1315
+ })(liveController.options.healthCheck);
1316
+ if (healthCheck) {
1317
+ liveController.healthCheckId = setInterval(() => liveController.checkReadyState(this), healthCheck);
1318
+ }
1319
+ }
1320
+ get options() {
1321
+ return Object.freeze(Object.assign({}, liveController.options));
1322
+ }
1323
+ get readyState() {
1324
+ liveController.checkReadyState(this);
1325
+ return liveController.readyState;
1326
+ }
1327
+ get url() {
1328
+ var _a;
1329
+ return ((_a = liveController.webSocket) === null || _a === void 0 ? void 0 : _a.url) || '';
1330
+ }
1331
+ get selfInfo() {
1332
+ return liveController.selfUserInfo;
1333
+ }
1334
+ get userList() {
1335
+ return liveController.userList || [];
1336
+ }
1337
+ get snapshot() {
1338
+ return liveController.keyframes || {};
1339
+ }
1340
+ get $RTC() {
1341
+ return liveController.options.rtc;
1342
+ }
1343
+ async setSelfInfo(userInfo) {
1344
+ if (this.readyState !== exports.WebSocketState.OPEN) {
1345
+ return new Error('The connection is not open and ready to communicate.');
1346
+ }
1347
+ try {
1348
+ return await this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserInfo, userInfo);
1349
+ }
1350
+ catch (error) {
1351
+ return error;
1352
+ }
1353
+ }
1354
+ getFramesByKey(key) {
1355
+ return liveController.keyframes[key];
1356
+ }
1357
+ sendKeyframe(key, frame) {
1358
+ if (this.readyState !== exports.WebSocketState.OPEN) {
1359
+ return new Error('The connection is not open and ready to communicate.');
1360
+ }
1361
+ liveController.keyframes[key] = frame;
1362
+ const liveMsg = createLiveMsg(exports.Command.KeyframeSync, this.snapshot);
1363
+ liveController.sendMessage(liveMsg);
1364
+ return true;
1365
+ }
1366
+ broadcast(data, toUserIds, timeout) {
1367
+ if (this.readyState !== exports.WebSocketState.OPEN) {
1368
+ return new Error('The connection is not open and ready to communicate.');
1369
+ }
1370
+ return new Promise((resolve, reject) => {
1371
+ const customEvent = createLiveMsg(exports.Command.CustomEvent, data, toUserIds);
1372
+ const front_request_id = customEvent.front_request_id;
1373
+ liveController.sendMessage(customEvent);
1374
+ const timeoutId = timeout
1375
+ ? setTimeout(() => {
1376
+ reject(new Error('RESPONSE TIMEOUT'));
1377
+ this.off('broadcast', broadcast);
1378
+ }, timeout)
1379
+ : undefined;
1380
+ const broadcast = (data, frontRequestId) => {
1381
+ if (frontRequestId !== front_request_id)
1382
+ return;
1383
+ this.off('broadcast', broadcast);
1384
+ resolve(data);
1385
+ if (timeoutId)
1386
+ clearInterval(timeoutId);
1387
+ };
1388
+ this.on('broadcast', broadcast);
1389
+ });
1390
+ }
1391
+ async updateStatus(evtType, atnType, status, toUserIds) {
1392
+ // TODO 统一规则,不能联合类型
1393
+ if (this.readyState !== exports.WebSocketState.OPEN) {
1394
+ return false;
1395
+ }
1396
+ const data = Object.assign({ event_type: evtType, action: atnType }, { data: status });
1397
+ const liveMsg = createLiveMsg(exports.Command.BuiltinMsg, data, toUserIds);
1398
+ liveController.sendMessage(liveMsg);
1399
+ return true;
1400
+ }
1401
+ // 仅用于用户自己的麦克风控制
1402
+ async toggleMicro(microStatus) {
1403
+ var _a, _b;
1404
+ if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.control_own_micro))
1405
+ return false;
1406
+ await this.$RTC.toggleMicro(microStatus);
1407
+ return await this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
1408
+ status: microStatus ? exports.MicroStatus.OPEN : exports.MicroStatus.CLOSE,
1409
+ }, []);
1410
+ }
1411
+ async forbidMicro(microStatus, toUserIds) {
1412
+ var _a, _b;
1413
+ if (liveController.options.canForbidUserMicro &&
1414
+ !liveController.options.canForbidUserMicro(toUserIds)) {
1415
+ return false;
1416
+ }
1417
+ if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.control_other_micro)) {
1418
+ return false;
1419
+ }
1420
+ return await this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
1421
+ status: microStatus,
1422
+ }, toUserIds);
1423
+ }
1424
+ /**
1425
+ * @deprecated 暂不可用
1426
+ */
1427
+ async forbidSync(sync, toUserIds) {
1428
+ var _a, _b;
1429
+ if (liveController.options.canForbidUserSync &&
1430
+ !liveController.options.canForbidUserSync(toUserIds)) {
1431
+ return false;
1432
+ }
1433
+ if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.control_other_sync)) {
1434
+ return false;
1435
+ }
1436
+ return await this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserPermission, { sync_frame: sync }, toUserIds);
1437
+ }
1438
+ async kick(toUserIds) {
1439
+ var _a, _b;
1440
+ if (liveController.options.canForbidUserKick &&
1441
+ !liveController.options.canForbidUserKick(toUserIds)) {
1442
+ return false;
1443
+ }
1444
+ if (!((_b = (_a = this.selfInfo) === null || _a === void 0 ? void 0 : _a.permission) === null || _b === void 0 ? void 0 : _b.change_other_status)) {
1445
+ return false;
1446
+ }
1447
+ return await this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserStatus, {
1448
+ status: 'KICK_OUT',
1449
+ }, toUserIds);
1450
+ }
1451
+ async exit() {
1452
+ /** 退出强制关闭语音(?) */
1453
+ await this.$RTC.quit();
1454
+ return await this.updateStatus(exports.BuiltinEventType.RoomChange, exports.BuiltinActionType.RoomClose, {});
1455
+ }
1456
+ async connect(options = {}) {
1457
+ // 连接 WebSocket 前验证麦克风权限
1458
+ const microAuth = await this.$RTC.detectMicro();
1459
+ if (!microAuth) {
1460
+ const error = new Error('系统监测麦克风未授权~');
1461
+ this.emit('ws.error', { type: exports.WebSocketErrorType.MicroAuth, error });
1462
+ return error;
1463
+ }
1464
+ // WebSocket 正在连接中,规避重复连接
1465
+ if (liveController.connecting) {
1466
+ const error = new Error('WebSocket 正在连接中,请勿重复连接 ...');
1467
+ this.emit('ws.error', {
1468
+ type: exports.WebSocketErrorType.DuplicateConnect,
1469
+ error,
1470
+ });
1471
+ return error;
1472
+ }
1473
+ // 非强制连接场景下,如果已经完成 WebSocket 连接则不执行后续逻辑
1474
+ const { force } = options;
1475
+ if (!force) {
1476
+ if (this.readyState === exports.WebSocketState.CONNECTING ||
1477
+ this.readyState === exports.WebSocketState.OPEN) {
1478
+ return true;
1479
+ }
1480
+ }
1481
+ // WebSocket URL 逻辑
1482
+ if (options.url) {
1483
+ liveController.options.url = options.url;
1484
+ }
1485
+ if (options.getTicket) {
1486
+ liveController.options.getTicket = options.getTicket;
1487
+ }
1488
+ if (!liveController.options.url ||
1489
+ !liveController.options.url.startsWith('ws')) {
1490
+ const error = new Error(`WebSocket URL 未配置或格式不合法:"${liveController.options.url}"`);
1491
+ this.emit('ws.error', { type: exports.WebSocketErrorType.IllegalURL, error });
1492
+ return error;
1493
+ }
1494
+ if (!liveController.options.getTicket) {
1495
+ const error = new Error(`getTicket() 未配置!`);
1496
+ this.emit('ws.error', { type: exports.WebSocketErrorType.IllegalArgs, error });
1497
+ return error;
1498
+ }
1499
+ // 连接锁
1500
+ liveController.connecting = true;
1501
+ // 连接前销毁之前绑定的事件
1502
+ liveController.disposeWebSocket();
1503
+ this.emit('ws.beforeConnect');
1504
+ const url = force || options.url || !this.url
1505
+ ? appendUri(liveController.options.url, {
1506
+ ticket: await liveController.options.getTicket(),
1507
+ force: Number(!!force),
1508
+ })
1509
+ : this.url;
1510
+ liveController.webSocket = new WebSocket(url);
1511
+ liveController.onEvtOpnListener = () => {
1512
+ liveController.checkReadyState(this);
1513
+ this.emit('ws.afterConnect');
1514
+ };
1515
+ liveController.onEvtMsgListener = (evt) => {
1516
+ liveController.checkReadyState(this);
1517
+ try {
1518
+ const liveMsg = parseLiveMsg(evt.data);
1519
+ if (liveMsg === false)
1520
+ return;
1521
+ liveController.handleMessage(liveMsg, this);
1522
+ }
1523
+ catch (error) {
1524
+ // 未知错误
1525
+ this.emit('ws.error', {
1526
+ type: exports.WebSocketErrorType.Unknown,
1527
+ error,
1528
+ target: evt,
1529
+ });
1530
+ }
1531
+ };
1532
+ liveController.onEvtErrListener = (evt) => {
1533
+ live.emit('ws.error', { type: exports.WebSocketErrorType.Error, target: evt });
1534
+ liveController.checkReadyState(this);
1535
+ };
1536
+ liveController.onEvtCLEListener = (evt) => {
1537
+ liveController.checkReadyState(this);
1538
+ const code = Number(evt.code);
1539
+ if (code === 1000)
1540
+ return;
1541
+ // 异常退出不一定会触发'error'事件,根据 evt.code 一些类型的退出也算是 error 行为
1542
+ const errMsg = parseWSClsErr(code);
1543
+ live.emit('ws.error', {
1544
+ target: evt,
1545
+ type: exports.WebSocketErrorType.Close,
1546
+ closeError: errMsg,
1547
+ });
1548
+ };
1549
+ liveController.webSocket.addEventListener('open', liveController.onEvtOpnListener);
1550
+ liveController.webSocket.addEventListener('message', liveController.onEvtMsgListener);
1551
+ liveController.webSocket.addEventListener('error', liveController.onEvtErrListener);
1552
+ liveController.webSocket.addEventListener('close', liveController.onEvtCLEListener);
1553
+ return await new Promise((resolve, reject) => {
1554
+ const success = () => {
1555
+ resolve(true);
1556
+ liveController.connecting = false;
1557
+ this.off('ws.error', fail);
1558
+ };
1559
+ const fail = (error) => {
1560
+ reject(error.error
1561
+ ? error.error
1562
+ : new Error('WebSocket connection failed!'));
1563
+ liveController.connecting = false;
1564
+ this.off('ws.afterConnect', success);
1565
+ };
1566
+ this.once('ws.afterConnect', success);
1567
+ this.once('ws.error', fail);
1568
+ });
1569
+ }
1570
+ async revoke() {
1571
+ return true;
1572
+ }
1573
+ }
1574
+ const live = new LiveTpl();
1575
+ // 如果是调试环境则将内部状态暴露出来
1576
+ if (options.__debug__) {
1577
+ Object.assign(live, { __controller__: liveController });
1578
+ Object.assign(window, { $live: live });
1579
+ }
1580
+ return live;
1581
+ }
1582
+
1583
+ function createCommonjsModule(fn) {
1584
+ var module = { exports: {} };
1585
+ return fn(module, module.exports), module.exports;
1586
+ }
1587
+
1588
+ /**
1589
+ * @license React
1590
+ * react.production.min.js
1591
+ *
1592
+ * Copyright (c) Facebook, Inc. and its affiliates.
1593
+ *
1594
+ * This source code is licensed under the MIT license found in the
1595
+ * LICENSE file in the root directory of this source tree.
1596
+ */
1597
+ var l=Symbol.for("react.element"),n=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),q=Symbol.for("react.strict_mode"),r=Symbol.for("react.profiler"),t=Symbol.for("react.provider"),u=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),w=Symbol.for("react.suspense"),x=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),z=Symbol.iterator;function A(a){if(null===a||"object"!==typeof a)return null;a=z&&a[z]||a["@@iterator"];return "function"===typeof a?a:null}
1598
+ var B={isMounted:function(){return !1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},C=Object.assign,D={};function E(a,b,e){this.props=a;this.context=b;this.refs=D;this.updater=e||B;}E.prototype.isReactComponent={};
1599
+ E.prototype.setState=function(a,b){if("object"!==typeof a&&"function"!==typeof a&&null!=a)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,a,b,"setState");};E.prototype.forceUpdate=function(a){this.updater.enqueueForceUpdate(this,a,"forceUpdate");};function F(){}F.prototype=E.prototype;function G(a,b,e){this.props=a;this.context=b;this.refs=D;this.updater=e||B;}var H=G.prototype=new F;
1600
+ H.constructor=G;C(H,E.prototype);H.isPureReactComponent=!0;var I=Array.isArray,J=Object.prototype.hasOwnProperty,K={current:null},L={key:!0,ref:!0,__self:!0,__source:!0};
1601
+ function M(a,b,e){var d,c={},k=null,h=null;if(null!=b)for(d in void 0!==b.ref&&(h=b.ref),void 0!==b.key&&(k=""+b.key),b)J.call(b,d)&&!L.hasOwnProperty(d)&&(c[d]=b[d]);var g=arguments.length-2;if(1===g)c.children=e;else if(1<g){for(var f=Array(g),m=0;m<g;m++)f[m]=arguments[m+2];c.children=f;}if(a&&a.defaultProps)for(d in g=a.defaultProps,g)void 0===c[d]&&(c[d]=g[d]);return {$$typeof:l,type:a,key:k,ref:h,props:c,_owner:K.current}}
1602
+ function N(a,b){return {$$typeof:l,type:a.type,key:b,ref:a.ref,props:a.props,_owner:a._owner}}function O(a){return "object"===typeof a&&null!==a&&a.$$typeof===l}function escape(a){var b={"=":"=0",":":"=2"};return "$"+a.replace(/[=:]/g,function(a){return b[a]})}var P=/\/+/g;function Q(a,b){return "object"===typeof a&&null!==a&&null!=a.key?escape(""+a.key):b.toString(36)}
1603
+ function R(a,b,e,d,c){var k=typeof a;if("undefined"===k||"boolean"===k)a=null;var h=!1;if(null===a)h=!0;else switch(k){case "string":case "number":h=!0;break;case "object":switch(a.$$typeof){case l:case n:h=!0;}}if(h)return h=a,c=c(h),a=""===d?"."+Q(h,0):d,I(c)?(e="",null!=a&&(e=a.replace(P,"$&/")+"/"),R(c,b,e,"",function(a){return a})):null!=c&&(O(c)&&(c=N(c,e+(!c.key||h&&h.key===c.key?"":(""+c.key).replace(P,"$&/")+"/")+a)),b.push(c)),1;h=0;d=""===d?".":d+":";if(I(a))for(var g=0;g<a.length;g++){k=
1604
+ a[g];var f=d+Q(k,g);h+=R(k,b,e,f,c);}else if(f=A(a),"function"===typeof f)for(a=f.call(a),g=0;!(k=a.next()).done;)k=k.value,f=d+Q(k,g++),h+=R(k,b,e,f,c);else if("object"===k)throw b=String(a),Error("Objects are not valid as a React child (found: "+("[object Object]"===b?"object with keys {"+Object.keys(a).join(", ")+"}":b)+"). If you meant to render a collection of children, use an array instead.");return h}
1605
+ function S(a,b,e){if(null==a)return a;var d=[],c=0;R(a,d,"","",function(a){return b.call(e,a,c++)});return d}function T(a){if(-1===a._status){var b=a._result;b=b();b.then(function(b){if(0===a._status||-1===a._status)a._status=1,a._result=b;},function(b){if(0===a._status||-1===a._status)a._status=2,a._result=b;});-1===a._status&&(a._status=0,a._result=b);}if(1===a._status)return a._result.default;throw a._result;}
1606
+ var U={current:null},V={transition:null},W={ReactCurrentDispatcher:U,ReactCurrentBatchConfig:V,ReactCurrentOwner:K};var Children={map:S,forEach:function(a,b,e){S(a,function(){b.apply(this,arguments);},e);},count:function(a){var b=0;S(a,function(){b++;});return b},toArray:function(a){return S(a,function(a){return a})||[]},only:function(a){if(!O(a))throw Error("React.Children.only expected to receive a single React element child.");return a}};var Component=E;var Fragment=p;
1607
+ var Profiler=r;var PureComponent=G;var StrictMode=q;var Suspense=w;var __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=W;
1608
+ var cloneElement=function(a,b,e){if(null===a||void 0===a)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+a+".");var d=C({},a.props),c=a.key,k=a.ref,h=a._owner;if(null!=b){void 0!==b.ref&&(k=b.ref,h=K.current);void 0!==b.key&&(c=""+b.key);if(a.type&&a.type.defaultProps)var g=a.type.defaultProps;for(f in b)J.call(b,f)&&!L.hasOwnProperty(f)&&(d[f]=void 0===b[f]&&void 0!==g?g[f]:b[f]);}var f=arguments.length-2;if(1===f)d.children=e;else if(1<f){g=Array(f);
1609
+ for(var m=0;m<f;m++)g[m]=arguments[m+2];d.children=g;}return {$$typeof:l,type:a.type,key:c,ref:k,props:d,_owner:h}};var createContext=function(a){a={$$typeof:u,_currentValue:a,_currentValue2:a,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null};a.Provider={$$typeof:t,_context:a};return a.Consumer=a};var createElement=M;var createFactory=function(a){var b=M.bind(null,a);b.type=a;return b};var createRef=function(){return {current:null}};
1610
+ var forwardRef=function(a){return {$$typeof:v,render:a}};var isValidElement=O;var lazy=function(a){return {$$typeof:y,_payload:{_status:-1,_result:a},_init:T}};var memo=function(a,b){return {$$typeof:x,type:a,compare:void 0===b?null:b}};var startTransition=function(a){var b=V.transition;V.transition={};try{a();}finally{V.transition=b;}};var unstable_act=function(){throw Error("act(...) is not supported in production builds of React.");};
1611
+ var useCallback=function(a,b){return U.current.useCallback(a,b)};var useContext=function(a){return U.current.useContext(a)};var useDebugValue=function(){};var useDeferredValue=function(a){return U.current.useDeferredValue(a)};var useEffect=function(a,b){return U.current.useEffect(a,b)};var useId=function(){return U.current.useId()};var useImperativeHandle=function(a,b,e){return U.current.useImperativeHandle(a,b,e)};
1612
+ var useInsertionEffect=function(a,b){return U.current.useInsertionEffect(a,b)};var useLayoutEffect=function(a,b){return U.current.useLayoutEffect(a,b)};var useMemo=function(a,b){return U.current.useMemo(a,b)};var useReducer=function(a,b,e){return U.current.useReducer(a,b,e)};var useRef=function(a){return U.current.useRef(a)};var useState=function(a){return U.current.useState(a)};var useSyncExternalStore=function(a,b,e){return U.current.useSyncExternalStore(a,b,e)};
1613
+ var useTransition=function(){return U.current.useTransition()};var version="18.1.0";
1614
+
1615
+ var react_production_min = {
1616
+ Children: Children,
1617
+ Component: Component,
1618
+ Fragment: Fragment,
1619
+ Profiler: Profiler,
1620
+ PureComponent: PureComponent,
1621
+ StrictMode: StrictMode,
1622
+ Suspense: Suspense,
1623
+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
1624
+ cloneElement: cloneElement,
1625
+ createContext: createContext,
1626
+ createElement: createElement,
1627
+ createFactory: createFactory,
1628
+ createRef: createRef,
1629
+ forwardRef: forwardRef,
1630
+ isValidElement: isValidElement,
1631
+ lazy: lazy,
1632
+ memo: memo,
1633
+ startTransition: startTransition,
1634
+ unstable_act: unstable_act,
1635
+ useCallback: useCallback,
1636
+ useContext: useContext,
1637
+ useDebugValue: useDebugValue,
1638
+ useDeferredValue: useDeferredValue,
1639
+ useEffect: useEffect,
1640
+ useId: useId,
1641
+ useImperativeHandle: useImperativeHandle,
1642
+ useInsertionEffect: useInsertionEffect,
1643
+ useLayoutEffect: useLayoutEffect,
1644
+ useMemo: useMemo,
1645
+ useReducer: useReducer,
1646
+ useRef: useRef,
1647
+ useState: useState,
1648
+ useSyncExternalStore: useSyncExternalStore,
1649
+ useTransition: useTransition,
1650
+ version: version
1651
+ };
1652
+
1653
+ /**
1654
+ * @license React
1655
+ * react.development.js
1656
+ *
1657
+ * Copyright (c) Facebook, Inc. and its affiliates.
1658
+ *
1659
+ * This source code is licensed under the MIT license found in the
1660
+ * LICENSE file in the root directory of this source tree.
1661
+ */
1662
+
1663
+ var react_development = createCommonjsModule(function (module, exports) {
1664
+
1665
+ if (process.env.NODE_ENV !== "production") {
1666
+ (function() {
1667
+
1668
+ /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
1669
+ if (
1670
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
1671
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
1672
+ 'function'
1673
+ ) {
1674
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
1675
+ }
1676
+ var ReactVersion = '18.1.0';
1677
+
1678
+ // -----------------------------------------------------------------------------
1679
+
1680
+ var enableScopeAPI = false; // Experimental Create Event Handle API.
1681
+ var enableCacheElement = false;
1682
+ var enableTransitionTracing = false; // No known bugs, but needs performance testing
1683
+
1684
+ var enableLegacyHidden = false; // Enables unstable_avoidThisFallback feature in Fiber
1685
+ // stuff. Intended to enable React core members to more easily debug scheduling
1686
+ // issues in DEV builds.
1687
+
1688
+ var enableDebugTracing = false; // Track which Fiber(s) schedule render work.
1689
+
1690
+ // ATTENTION
1691
+
1692
+ var REACT_ELEMENT_TYPE = Symbol.for('react.element');
1693
+ var REACT_PORTAL_TYPE = Symbol.for('react.portal');
1694
+ var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
1695
+ var REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
1696
+ var REACT_PROFILER_TYPE = Symbol.for('react.profiler');
1697
+ var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
1698
+ var REACT_CONTEXT_TYPE = Symbol.for('react.context');
1699
+ var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
1700
+ var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
1701
+ var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
1702
+ var REACT_MEMO_TYPE = Symbol.for('react.memo');
1703
+ var REACT_LAZY_TYPE = Symbol.for('react.lazy');
1704
+ var REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
1705
+ var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
1706
+ var FAUX_ITERATOR_SYMBOL = '@@iterator';
1707
+ function getIteratorFn(maybeIterable) {
1708
+ if (maybeIterable === null || typeof maybeIterable !== 'object') {
1709
+ return null;
1710
+ }
1711
+
1712
+ var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
1713
+
1714
+ if (typeof maybeIterator === 'function') {
1715
+ return maybeIterator;
1716
+ }
1717
+
1718
+ return null;
1719
+ }
1720
+
1721
+ /**
1722
+ * Keeps track of the current dispatcher.
1723
+ */
1724
+ var ReactCurrentDispatcher = {
1725
+ /**
1726
+ * @internal
1727
+ * @type {ReactComponent}
1728
+ */
1729
+ current: null
1730
+ };
1731
+
1732
+ /**
1733
+ * Keeps track of the current batch's configuration such as how long an update
1734
+ * should suspend for if it needs to.
1735
+ */
1736
+ var ReactCurrentBatchConfig = {
1737
+ transition: null
1738
+ };
1739
+
1740
+ var ReactCurrentActQueue = {
1741
+ current: null,
1742
+ // Used to reproduce behavior of `batchedUpdates` in legacy mode.
1743
+ isBatchingLegacy: false,
1744
+ didScheduleLegacyUpdate: false
1745
+ };
1746
+
1747
+ /**
1748
+ * Keeps track of the current owner.
1749
+ *
1750
+ * The current owner is the component who should own any components that are
1751
+ * currently being constructed.
1752
+ */
1753
+ var ReactCurrentOwner = {
1754
+ /**
1755
+ * @internal
1756
+ * @type {ReactComponent}
1757
+ */
1758
+ current: null
1759
+ };
1760
+
1761
+ var ReactDebugCurrentFrame = {};
1762
+ var currentExtraStackFrame = null;
1763
+ function setExtraStackFrame(stack) {
1764
+ {
1765
+ currentExtraStackFrame = stack;
1766
+ }
1767
+ }
1768
+
1769
+ {
1770
+ ReactDebugCurrentFrame.setExtraStackFrame = function (stack) {
1771
+ {
1772
+ currentExtraStackFrame = stack;
1773
+ }
1774
+ }; // Stack implementation injected by the current renderer.
1775
+
1776
+
1777
+ ReactDebugCurrentFrame.getCurrentStack = null;
1778
+
1779
+ ReactDebugCurrentFrame.getStackAddendum = function () {
1780
+ var stack = ''; // Add an extra top frame while an element is being validated
1781
+
1782
+ if (currentExtraStackFrame) {
1783
+ stack += currentExtraStackFrame;
1784
+ } // Delegate to the injected renderer-specific implementation
1785
+
1786
+
1787
+ var impl = ReactDebugCurrentFrame.getCurrentStack;
1788
+
1789
+ if (impl) {
1790
+ stack += impl() || '';
1791
+ }
1792
+
1793
+ return stack;
1794
+ };
1795
+ }
1796
+
1797
+ var ReactSharedInternals = {
1798
+ ReactCurrentDispatcher: ReactCurrentDispatcher,
1799
+ ReactCurrentBatchConfig: ReactCurrentBatchConfig,
1800
+ ReactCurrentOwner: ReactCurrentOwner
1801
+ };
1802
+
1803
+ {
1804
+ ReactSharedInternals.ReactDebugCurrentFrame = ReactDebugCurrentFrame;
1805
+ ReactSharedInternals.ReactCurrentActQueue = ReactCurrentActQueue;
1806
+ }
1807
+
1808
+ // by calls to these methods by a Babel plugin.
1809
+ //
1810
+ // In PROD (or in packages without access to React internals),
1811
+ // they are left as they are instead.
1812
+
1813
+ function warn(format) {
1814
+ {
1815
+ {
1816
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1817
+ args[_key - 1] = arguments[_key];
1818
+ }
1819
+
1820
+ printWarning('warn', format, args);
1821
+ }
1822
+ }
1823
+ }
1824
+ function error(format) {
1825
+ {
1826
+ {
1827
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1828
+ args[_key2 - 1] = arguments[_key2];
1829
+ }
1830
+
1831
+ printWarning('error', format, args);
1832
+ }
1833
+ }
1834
+ }
1835
+
1836
+ function printWarning(level, format, args) {
1837
+ // When changing this logic, you might want to also
1838
+ // update consoleWithStackDev.www.js as well.
1839
+ {
1840
+ var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
1841
+ var stack = ReactDebugCurrentFrame.getStackAddendum();
1842
+
1843
+ if (stack !== '') {
1844
+ format += '%s';
1845
+ args = args.concat([stack]);
1846
+ } // eslint-disable-next-line react-internal/safe-string-coercion
1847
+
1848
+
1849
+ var argsWithFormat = args.map(function (item) {
1850
+ return String(item);
1851
+ }); // Careful: RN currently depends on this prefix
1852
+
1853
+ argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
1854
+ // breaks IE9: https://github.com/facebook/react/issues/13610
1855
+ // eslint-disable-next-line react-internal/no-production-logging
1856
+
1857
+ Function.prototype.apply.call(console[level], console, argsWithFormat);
1858
+ }
1859
+ }
1860
+
1861
+ var didWarnStateUpdateForUnmountedComponent = {};
1862
+
1863
+ function warnNoop(publicInstance, callerName) {
1864
+ {
1865
+ var _constructor = publicInstance.constructor;
1866
+ var componentName = _constructor && (_constructor.displayName || _constructor.name) || 'ReactClass';
1867
+ var warningKey = componentName + "." + callerName;
1868
+
1869
+ if (didWarnStateUpdateForUnmountedComponent[warningKey]) {
1870
+ return;
1871
+ }
1872
+
1873
+ error("Can't call %s on a component that is not yet mounted. " + 'This is a no-op, but it might indicate a bug in your application. ' + 'Instead, assign to `this.state` directly or define a `state = {};` ' + 'class property with the desired state in the %s component.', callerName, componentName);
1874
+
1875
+ didWarnStateUpdateForUnmountedComponent[warningKey] = true;
1876
+ }
1877
+ }
1878
+ /**
1879
+ * This is the abstract API for an update queue.
1880
+ */
1881
+
1882
+
1883
+ var ReactNoopUpdateQueue = {
1884
+ /**
1885
+ * Checks whether or not this composite component is mounted.
1886
+ * @param {ReactClass} publicInstance The instance we want to test.
1887
+ * @return {boolean} True if mounted, false otherwise.
1888
+ * @protected
1889
+ * @final
1890
+ */
1891
+ isMounted: function (publicInstance) {
1892
+ return false;
1893
+ },
1894
+
1895
+ /**
1896
+ * Forces an update. This should only be invoked when it is known with
1897
+ * certainty that we are **not** in a DOM transaction.
1898
+ *
1899
+ * You may want to call this when you know that some deeper aspect of the
1900
+ * component's state has changed but `setState` was not called.
1901
+ *
1902
+ * This will not invoke `shouldComponentUpdate`, but it will invoke
1903
+ * `componentWillUpdate` and `componentDidUpdate`.
1904
+ *
1905
+ * @param {ReactClass} publicInstance The instance that should rerender.
1906
+ * @param {?function} callback Called after component is updated.
1907
+ * @param {?string} callerName name of the calling function in the public API.
1908
+ * @internal
1909
+ */
1910
+ enqueueForceUpdate: function (publicInstance, callback, callerName) {
1911
+ warnNoop(publicInstance, 'forceUpdate');
1912
+ },
1913
+
1914
+ /**
1915
+ * Replaces all of the state. Always use this or `setState` to mutate state.
1916
+ * You should treat `this.state` as immutable.
1917
+ *
1918
+ * There is no guarantee that `this.state` will be immediately updated, so
1919
+ * accessing `this.state` after calling this method may return the old value.
1920
+ *
1921
+ * @param {ReactClass} publicInstance The instance that should rerender.
1922
+ * @param {object} completeState Next state.
1923
+ * @param {?function} callback Called after component is updated.
1924
+ * @param {?string} callerName name of the calling function in the public API.
1925
+ * @internal
1926
+ */
1927
+ enqueueReplaceState: function (publicInstance, completeState, callback, callerName) {
1928
+ warnNoop(publicInstance, 'replaceState');
1929
+ },
1930
+
1931
+ /**
1932
+ * Sets a subset of the state. This only exists because _pendingState is
1933
+ * internal. This provides a merging strategy that is not available to deep
1934
+ * properties which is confusing. TODO: Expose pendingState or don't use it
1935
+ * during the merge.
1936
+ *
1937
+ * @param {ReactClass} publicInstance The instance that should rerender.
1938
+ * @param {object} partialState Next partial state to be merged with state.
1939
+ * @param {?function} callback Called after component is updated.
1940
+ * @param {?string} Name of the calling function in the public API.
1941
+ * @internal
1942
+ */
1943
+ enqueueSetState: function (publicInstance, partialState, callback, callerName) {
1944
+ warnNoop(publicInstance, 'setState');
1945
+ }
1946
+ };
1947
+
1948
+ var assign = Object.assign;
1949
+
1950
+ var emptyObject = {};
1951
+
1952
+ {
1953
+ Object.freeze(emptyObject);
1954
+ }
1955
+ /**
1956
+ * Base class helpers for the updating state of a component.
1957
+ */
1958
+
1959
+
1960
+ function Component(props, context, updater) {
1961
+ this.props = props;
1962
+ this.context = context; // If a component has string refs, we will assign a different object later.
1963
+
1964
+ this.refs = emptyObject; // We initialize the default updater but the real one gets injected by the
1965
+ // renderer.
1966
+
1967
+ this.updater = updater || ReactNoopUpdateQueue;
1968
+ }
1969
+
1970
+ Component.prototype.isReactComponent = {};
1971
+ /**
1972
+ * Sets a subset of the state. Always use this to mutate
1973
+ * state. You should treat `this.state` as immutable.
1974
+ *
1975
+ * There is no guarantee that `this.state` will be immediately updated, so
1976
+ * accessing `this.state` after calling this method may return the old value.
1977
+ *
1978
+ * There is no guarantee that calls to `setState` will run synchronously,
1979
+ * as they may eventually be batched together. You can provide an optional
1980
+ * callback that will be executed when the call to setState is actually
1981
+ * completed.
1982
+ *
1983
+ * When a function is provided to setState, it will be called at some point in
1984
+ * the future (not synchronously). It will be called with the up to date
1985
+ * component arguments (state, props, context). These values can be different
1986
+ * from this.* because your function may be called after receiveProps but before
1987
+ * shouldComponentUpdate, and this new state, props, and context will not yet be
1988
+ * assigned to this.
1989
+ *
1990
+ * @param {object|function} partialState Next partial state or function to
1991
+ * produce next partial state to be merged with current state.
1992
+ * @param {?function} callback Called after state is updated.
1993
+ * @final
1994
+ * @protected
1995
+ */
1996
+
1997
+ Component.prototype.setState = function (partialState, callback) {
1998
+ if (typeof partialState !== 'object' && typeof partialState !== 'function' && partialState != null) {
1999
+ throw new Error('setState(...): takes an object of state variables to update or a ' + 'function which returns an object of state variables.');
2000
+ }
2001
+
2002
+ this.updater.enqueueSetState(this, partialState, callback, 'setState');
2003
+ };
2004
+ /**
2005
+ * Forces an update. This should only be invoked when it is known with
2006
+ * certainty that we are **not** in a DOM transaction.
2007
+ *
2008
+ * You may want to call this when you know that some deeper aspect of the
2009
+ * component's state has changed but `setState` was not called.
2010
+ *
2011
+ * This will not invoke `shouldComponentUpdate`, but it will invoke
2012
+ * `componentWillUpdate` and `componentDidUpdate`.
2013
+ *
2014
+ * @param {?function} callback Called after update is complete.
2015
+ * @final
2016
+ * @protected
2017
+ */
2018
+
2019
+
2020
+ Component.prototype.forceUpdate = function (callback) {
2021
+ this.updater.enqueueForceUpdate(this, callback, 'forceUpdate');
2022
+ };
2023
+ /**
2024
+ * Deprecated APIs. These APIs used to exist on classic React classes but since
2025
+ * we would like to deprecate them, we're not going to move them over to this
2026
+ * modern base class. Instead, we define a getter that warns if it's accessed.
2027
+ */
2028
+
2029
+
2030
+ {
2031
+ var deprecatedAPIs = {
2032
+ isMounted: ['isMounted', 'Instead, make sure to clean up subscriptions and pending requests in ' + 'componentWillUnmount to prevent memory leaks.'],
2033
+ replaceState: ['replaceState', 'Refactor your code to use setState instead (see ' + 'https://github.com/facebook/react/issues/3236).']
2034
+ };
2035
+
2036
+ var defineDeprecationWarning = function (methodName, info) {
2037
+ Object.defineProperty(Component.prototype, methodName, {
2038
+ get: function () {
2039
+ warn('%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]);
2040
+
2041
+ return undefined;
2042
+ }
2043
+ });
2044
+ };
2045
+
2046
+ for (var fnName in deprecatedAPIs) {
2047
+ if (deprecatedAPIs.hasOwnProperty(fnName)) {
2048
+ defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
2049
+ }
2050
+ }
2051
+ }
2052
+
2053
+ function ComponentDummy() {}
2054
+
2055
+ ComponentDummy.prototype = Component.prototype;
2056
+ /**
2057
+ * Convenience component with default shallow equality check for sCU.
2058
+ */
2059
+
2060
+ function PureComponent(props, context, updater) {
2061
+ this.props = props;
2062
+ this.context = context; // If a component has string refs, we will assign a different object later.
2063
+
2064
+ this.refs = emptyObject;
2065
+ this.updater = updater || ReactNoopUpdateQueue;
2066
+ }
2067
+
2068
+ var pureComponentPrototype = PureComponent.prototype = new ComponentDummy();
2069
+ pureComponentPrototype.constructor = PureComponent; // Avoid an extra prototype jump for these methods.
2070
+
2071
+ assign(pureComponentPrototype, Component.prototype);
2072
+ pureComponentPrototype.isPureReactComponent = true;
2073
+
2074
+ // an immutable object with a single mutable value
2075
+ function createRef() {
2076
+ var refObject = {
2077
+ current: null
2078
+ };
2079
+
2080
+ {
2081
+ Object.seal(refObject);
2082
+ }
2083
+
2084
+ return refObject;
2085
+ }
2086
+
2087
+ var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
2088
+
2089
+ function isArray(a) {
2090
+ return isArrayImpl(a);
2091
+ }
2092
+
2093
+ /*
2094
+ * The `'' + value` pattern (used in in perf-sensitive code) throws for Symbol
2095
+ * and Temporal.* types. See https://github.com/facebook/react/pull/22064.
2096
+ *
2097
+ * The functions in this module will throw an easier-to-understand,
2098
+ * easier-to-debug exception with a clear errors message message explaining the
2099
+ * problem. (Instead of a confusing exception thrown inside the implementation
2100
+ * of the `value` object).
2101
+ */
2102
+ // $FlowFixMe only called in DEV, so void return is not possible.
2103
+ function typeName(value) {
2104
+ {
2105
+ // toStringTag is needed for namespaced types like Temporal.Instant
2106
+ var hasToStringTag = typeof Symbol === 'function' && Symbol.toStringTag;
2107
+ var type = hasToStringTag && value[Symbol.toStringTag] || value.constructor.name || 'Object';
2108
+ return type;
2109
+ }
2110
+ } // $FlowFixMe only called in DEV, so void return is not possible.
2111
+
2112
+
2113
+ function willCoercionThrow(value) {
2114
+ {
2115
+ try {
2116
+ return false;
2117
+ } catch (e) {
2118
+ return true;
2119
+ }
2120
+ }
2121
+ }
2122
+
2123
+ function testStringCoercion(value) {
2124
+ // If you ended up here by following an exception call stack, here's what's
2125
+ // happened: you supplied an object or symbol value to React (as a prop, key,
2126
+ // DOM attribute, CSS property, string ref, etc.) and when React tried to
2127
+ // coerce it to a string using `'' + value`, an exception was thrown.
2128
+ //
2129
+ // The most common types that will cause this exception are `Symbol` instances
2130
+ // and Temporal objects like `Temporal.Instant`. But any object that has a
2131
+ // `valueOf` or `[Symbol.toPrimitive]` method that throws will also cause this
2132
+ // exception. (Library authors do this to prevent users from using built-in
2133
+ // numeric operators like `+` or comparison operators like `>=` because custom
2134
+ // methods are needed to perform accurate arithmetic or comparison.)
2135
+ //
2136
+ // To fix the problem, coerce this object or symbol value to a string before
2137
+ // passing it to React. The most reliable way is usually `String(value)`.
2138
+ //
2139
+ // To find which value is throwing, check the browser or debugger console.
2140
+ // Before this exception was thrown, there should be `console.error` output
2141
+ // that shows the type (Symbol, Temporal.PlainDate, etc.) that caused the
2142
+ // problem and how that type was used: key, atrribute, input value prop, etc.
2143
+ // In most cases, this console output also shows the component and its
2144
+ // ancestor components where the exception happened.
2145
+ //
2146
+ // eslint-disable-next-line react-internal/safe-string-coercion
2147
+ return '' + value;
2148
+ }
2149
+ function checkKeyStringCoercion(value) {
2150
+ {
2151
+ if (willCoercionThrow()) {
2152
+ error('The provided key is an unsupported type %s.' + ' This value must be coerced to a string before before using it here.', typeName(value));
2153
+
2154
+ return testStringCoercion(value); // throw (to help callers find troubleshooting comments)
2155
+ }
2156
+ }
2157
+ }
2158
+
2159
+ function getWrappedName(outerType, innerType, wrapperName) {
2160
+ var displayName = outerType.displayName;
2161
+
2162
+ if (displayName) {
2163
+ return displayName;
2164
+ }
2165
+
2166
+ var functionName = innerType.displayName || innerType.name || '';
2167
+ return functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName;
2168
+ } // Keep in sync with react-reconciler/getComponentNameFromFiber
2169
+
2170
+
2171
+ function getContextName(type) {
2172
+ return type.displayName || 'Context';
2173
+ } // Note that the reconciler package should generally prefer to use getComponentNameFromFiber() instead.
2174
+
2175
+
2176
+ function getComponentNameFromType(type) {
2177
+ if (type == null) {
2178
+ // Host root, text node or just invalid type.
2179
+ return null;
2180
+ }
2181
+
2182
+ {
2183
+ if (typeof type.tag === 'number') {
2184
+ error('Received an unexpected object in getComponentNameFromType(). ' + 'This is likely a bug in React. Please file an issue.');
2185
+ }
2186
+ }
2187
+
2188
+ if (typeof type === 'function') {
2189
+ return type.displayName || type.name || null;
2190
+ }
2191
+
2192
+ if (typeof type === 'string') {
2193
+ return type;
2194
+ }
2195
+
2196
+ switch (type) {
2197
+ case REACT_FRAGMENT_TYPE:
2198
+ return 'Fragment';
2199
+
2200
+ case REACT_PORTAL_TYPE:
2201
+ return 'Portal';
2202
+
2203
+ case REACT_PROFILER_TYPE:
2204
+ return 'Profiler';
2205
+
2206
+ case REACT_STRICT_MODE_TYPE:
2207
+ return 'StrictMode';
2208
+
2209
+ case REACT_SUSPENSE_TYPE:
2210
+ return 'Suspense';
2211
+
2212
+ case REACT_SUSPENSE_LIST_TYPE:
2213
+ return 'SuspenseList';
2214
+
2215
+ }
2216
+
2217
+ if (typeof type === 'object') {
2218
+ switch (type.$$typeof) {
2219
+ case REACT_CONTEXT_TYPE:
2220
+ var context = type;
2221
+ return getContextName(context) + '.Consumer';
2222
+
2223
+ case REACT_PROVIDER_TYPE:
2224
+ var provider = type;
2225
+ return getContextName(provider._context) + '.Provider';
2226
+
2227
+ case REACT_FORWARD_REF_TYPE:
2228
+ return getWrappedName(type, type.render, 'ForwardRef');
2229
+
2230
+ case REACT_MEMO_TYPE:
2231
+ var outerName = type.displayName || null;
2232
+
2233
+ if (outerName !== null) {
2234
+ return outerName;
2235
+ }
2236
+
2237
+ return getComponentNameFromType(type.type) || 'Memo';
2238
+
2239
+ case REACT_LAZY_TYPE:
2240
+ {
2241
+ var lazyComponent = type;
2242
+ var payload = lazyComponent._payload;
2243
+ var init = lazyComponent._init;
2244
+
2245
+ try {
2246
+ return getComponentNameFromType(init(payload));
2247
+ } catch (x) {
2248
+ return null;
2249
+ }
2250
+ }
2251
+
2252
+ // eslint-disable-next-line no-fallthrough
2253
+ }
2254
+ }
2255
+
2256
+ return null;
2257
+ }
2258
+
2259
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
2260
+
2261
+ var RESERVED_PROPS = {
2262
+ key: true,
2263
+ ref: true,
2264
+ __self: true,
2265
+ __source: true
2266
+ };
2267
+ var specialPropKeyWarningShown, specialPropRefWarningShown, didWarnAboutStringRefs;
2268
+
2269
+ {
2270
+ didWarnAboutStringRefs = {};
2271
+ }
2272
+
2273
+ function hasValidRef(config) {
2274
+ {
2275
+ if (hasOwnProperty.call(config, 'ref')) {
2276
+ var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
2277
+
2278
+ if (getter && getter.isReactWarning) {
2279
+ return false;
2280
+ }
2281
+ }
2282
+ }
2283
+
2284
+ return config.ref !== undefined;
2285
+ }
2286
+
2287
+ function hasValidKey(config) {
2288
+ {
2289
+ if (hasOwnProperty.call(config, 'key')) {
2290
+ var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
2291
+
2292
+ if (getter && getter.isReactWarning) {
2293
+ return false;
2294
+ }
2295
+ }
2296
+ }
2297
+
2298
+ return config.key !== undefined;
2299
+ }
2300
+
2301
+ function defineKeyPropWarningGetter(props, displayName) {
2302
+ var warnAboutAccessingKey = function () {
2303
+ {
2304
+ if (!specialPropKeyWarningShown) {
2305
+ specialPropKeyWarningShown = true;
2306
+
2307
+ error('%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
2308
+ }
2309
+ }
2310
+ };
2311
+
2312
+ warnAboutAccessingKey.isReactWarning = true;
2313
+ Object.defineProperty(props, 'key', {
2314
+ get: warnAboutAccessingKey,
2315
+ configurable: true
2316
+ });
2317
+ }
2318
+
2319
+ function defineRefPropWarningGetter(props, displayName) {
2320
+ var warnAboutAccessingRef = function () {
2321
+ {
2322
+ if (!specialPropRefWarningShown) {
2323
+ specialPropRefWarningShown = true;
2324
+
2325
+ error('%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
2326
+ }
2327
+ }
2328
+ };
2329
+
2330
+ warnAboutAccessingRef.isReactWarning = true;
2331
+ Object.defineProperty(props, 'ref', {
2332
+ get: warnAboutAccessingRef,
2333
+ configurable: true
2334
+ });
2335
+ }
2336
+
2337
+ function warnIfStringRefCannotBeAutoConverted(config) {
2338
+ {
2339
+ if (typeof config.ref === 'string' && ReactCurrentOwner.current && config.__self && ReactCurrentOwner.current.stateNode !== config.__self) {
2340
+ var componentName = getComponentNameFromType(ReactCurrentOwner.current.type);
2341
+
2342
+ if (!didWarnAboutStringRefs[componentName]) {
2343
+ error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-string-ref', componentName, config.ref);
2344
+
2345
+ didWarnAboutStringRefs[componentName] = true;
2346
+ }
2347
+ }
2348
+ }
2349
+ }
2350
+ /**
2351
+ * Factory method to create a new React element. This no longer adheres to
2352
+ * the class pattern, so do not use new to call it. Also, instanceof check
2353
+ * will not work. Instead test $$typeof field against Symbol.for('react.element') to check
2354
+ * if something is a React Element.
2355
+ *
2356
+ * @param {*} type
2357
+ * @param {*} props
2358
+ * @param {*} key
2359
+ * @param {string|object} ref
2360
+ * @param {*} owner
2361
+ * @param {*} self A *temporary* helper to detect places where `this` is
2362
+ * different from the `owner` when React.createElement is called, so that we
2363
+ * can warn. We want to get rid of owner and replace string `ref`s with arrow
2364
+ * functions, and as long as `this` and owner are the same, there will be no
2365
+ * change in behavior.
2366
+ * @param {*} source An annotation object (added by a transpiler or otherwise)
2367
+ * indicating filename, line number, and/or other information.
2368
+ * @internal
2369
+ */
2370
+
2371
+
2372
+ var ReactElement = function (type, key, ref, self, source, owner, props) {
2373
+ var element = {
2374
+ // This tag allows us to uniquely identify this as a React Element
2375
+ $$typeof: REACT_ELEMENT_TYPE,
2376
+ // Built-in properties that belong on the element
2377
+ type: type,
2378
+ key: key,
2379
+ ref: ref,
2380
+ props: props,
2381
+ // Record the component responsible for creating this element.
2382
+ _owner: owner
2383
+ };
2384
+
2385
+ {
2386
+ // The validation flag is currently mutative. We put it on
2387
+ // an external backing store so that we can freeze the whole object.
2388
+ // This can be replaced with a WeakMap once they are implemented in
2389
+ // commonly used development environments.
2390
+ element._store = {}; // To make comparing ReactElements easier for testing purposes, we make
2391
+ // the validation flag non-enumerable (where possible, which should
2392
+ // include every environment we run tests in), so the test framework
2393
+ // ignores it.
2394
+
2395
+ Object.defineProperty(element._store, 'validated', {
2396
+ configurable: false,
2397
+ enumerable: false,
2398
+ writable: true,
2399
+ value: false
2400
+ }); // self and source are DEV only properties.
2401
+
2402
+ Object.defineProperty(element, '_self', {
2403
+ configurable: false,
2404
+ enumerable: false,
2405
+ writable: false,
2406
+ value: self
2407
+ }); // Two elements created in two different places should be considered
2408
+ // equal for testing purposes and therefore we hide it from enumeration.
2409
+
2410
+ Object.defineProperty(element, '_source', {
2411
+ configurable: false,
2412
+ enumerable: false,
2413
+ writable: false,
2414
+ value: source
2415
+ });
2416
+
2417
+ if (Object.freeze) {
2418
+ Object.freeze(element.props);
2419
+ Object.freeze(element);
2420
+ }
2421
+ }
2422
+
2423
+ return element;
2424
+ };
2425
+ /**
2426
+ * Create and return a new ReactElement of the given type.
2427
+ * See https://reactjs.org/docs/react-api.html#createelement
2428
+ */
2429
+
2430
+ function createElement(type, config, children) {
2431
+ var propName; // Reserved names are extracted
2432
+
2433
+ var props = {};
2434
+ var key = null;
2435
+ var ref = null;
2436
+ var self = null;
2437
+ var source = null;
2438
+
2439
+ if (config != null) {
2440
+ if (hasValidRef(config)) {
2441
+ ref = config.ref;
2442
+
2443
+ {
2444
+ warnIfStringRefCannotBeAutoConverted(config);
2445
+ }
2446
+ }
2447
+
2448
+ if (hasValidKey(config)) {
2449
+ {
2450
+ checkKeyStringCoercion(config.key);
2451
+ }
2452
+
2453
+ key = '' + config.key;
2454
+ }
2455
+
2456
+ self = config.__self === undefined ? null : config.__self;
2457
+ source = config.__source === undefined ? null : config.__source; // Remaining properties are added to a new props object
2458
+
2459
+ for (propName in config) {
2460
+ if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
2461
+ props[propName] = config[propName];
2462
+ }
2463
+ }
2464
+ } // Children can be more than one argument, and those are transferred onto
2465
+ // the newly allocated props object.
2466
+
2467
+
2468
+ var childrenLength = arguments.length - 2;
2469
+
2470
+ if (childrenLength === 1) {
2471
+ props.children = children;
2472
+ } else if (childrenLength > 1) {
2473
+ var childArray = Array(childrenLength);
2474
+
2475
+ for (var i = 0; i < childrenLength; i++) {
2476
+ childArray[i] = arguments[i + 2];
2477
+ }
2478
+
2479
+ {
2480
+ if (Object.freeze) {
2481
+ Object.freeze(childArray);
2482
+ }
2483
+ }
2484
+
2485
+ props.children = childArray;
2486
+ } // Resolve default props
2487
+
2488
+
2489
+ if (type && type.defaultProps) {
2490
+ var defaultProps = type.defaultProps;
2491
+
2492
+ for (propName in defaultProps) {
2493
+ if (props[propName] === undefined) {
2494
+ props[propName] = defaultProps[propName];
2495
+ }
2496
+ }
2497
+ }
2498
+
2499
+ {
2500
+ if (key || ref) {
2501
+ var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
2502
+
2503
+ if (key) {
2504
+ defineKeyPropWarningGetter(props, displayName);
2505
+ }
2506
+
2507
+ if (ref) {
2508
+ defineRefPropWarningGetter(props, displayName);
2509
+ }
2510
+ }
2511
+ }
2512
+
2513
+ return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
2514
+ }
2515
+ function cloneAndReplaceKey(oldElement, newKey) {
2516
+ var newElement = ReactElement(oldElement.type, newKey, oldElement.ref, oldElement._self, oldElement._source, oldElement._owner, oldElement.props);
2517
+ return newElement;
2518
+ }
2519
+ /**
2520
+ * Clone and return a new ReactElement using element as the starting point.
2521
+ * See https://reactjs.org/docs/react-api.html#cloneelement
2522
+ */
2523
+
2524
+ function cloneElement(element, config, children) {
2525
+ if (element === null || element === undefined) {
2526
+ throw new Error("React.cloneElement(...): The argument must be a React element, but you passed " + element + ".");
2527
+ }
2528
+
2529
+ var propName; // Original props are copied
2530
+
2531
+ var props = assign({}, element.props); // Reserved names are extracted
2532
+
2533
+ var key = element.key;
2534
+ var ref = element.ref; // Self is preserved since the owner is preserved.
2535
+
2536
+ var self = element._self; // Source is preserved since cloneElement is unlikely to be targeted by a
2537
+ // transpiler, and the original source is probably a better indicator of the
2538
+ // true owner.
2539
+
2540
+ var source = element._source; // Owner will be preserved, unless ref is overridden
2541
+
2542
+ var owner = element._owner;
2543
+
2544
+ if (config != null) {
2545
+ if (hasValidRef(config)) {
2546
+ // Silently steal the ref from the parent.
2547
+ ref = config.ref;
2548
+ owner = ReactCurrentOwner.current;
2549
+ }
2550
+
2551
+ if (hasValidKey(config)) {
2552
+ {
2553
+ checkKeyStringCoercion(config.key);
2554
+ }
2555
+
2556
+ key = '' + config.key;
2557
+ } // Remaining properties override existing props
2558
+
2559
+
2560
+ var defaultProps;
2561
+
2562
+ if (element.type && element.type.defaultProps) {
2563
+ defaultProps = element.type.defaultProps;
2564
+ }
2565
+
2566
+ for (propName in config) {
2567
+ if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
2568
+ if (config[propName] === undefined && defaultProps !== undefined) {
2569
+ // Resolve default props
2570
+ props[propName] = defaultProps[propName];
2571
+ } else {
2572
+ props[propName] = config[propName];
2573
+ }
2574
+ }
2575
+ }
2576
+ } // Children can be more than one argument, and those are transferred onto
2577
+ // the newly allocated props object.
2578
+
2579
+
2580
+ var childrenLength = arguments.length - 2;
2581
+
2582
+ if (childrenLength === 1) {
2583
+ props.children = children;
2584
+ } else if (childrenLength > 1) {
2585
+ var childArray = Array(childrenLength);
2586
+
2587
+ for (var i = 0; i < childrenLength; i++) {
2588
+ childArray[i] = arguments[i + 2];
2589
+ }
2590
+
2591
+ props.children = childArray;
2592
+ }
2593
+
2594
+ return ReactElement(element.type, key, ref, self, source, owner, props);
2595
+ }
2596
+ /**
2597
+ * Verifies the object is a ReactElement.
2598
+ * See https://reactjs.org/docs/react-api.html#isvalidelement
2599
+ * @param {?object} object
2600
+ * @return {boolean} True if `object` is a ReactElement.
2601
+ * @final
2602
+ */
2603
+
2604
+ function isValidElement(object) {
2605
+ return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
2606
+ }
2607
+
2608
+ var SEPARATOR = '.';
2609
+ var SUBSEPARATOR = ':';
2610
+ /**
2611
+ * Escape and wrap key so it is safe to use as a reactid
2612
+ *
2613
+ * @param {string} key to be escaped.
2614
+ * @return {string} the escaped key.
2615
+ */
2616
+
2617
+ function escape(key) {
2618
+ var escapeRegex = /[=:]/g;
2619
+ var escaperLookup = {
2620
+ '=': '=0',
2621
+ ':': '=2'
2622
+ };
2623
+ var escapedString = key.replace(escapeRegex, function (match) {
2624
+ return escaperLookup[match];
2625
+ });
2626
+ return '$' + escapedString;
2627
+ }
2628
+ /**
2629
+ * TODO: Test that a single child and an array with one item have the same key
2630
+ * pattern.
2631
+ */
2632
+
2633
+
2634
+ var didWarnAboutMaps = false;
2635
+ var userProvidedKeyEscapeRegex = /\/+/g;
2636
+
2637
+ function escapeUserProvidedKey(text) {
2638
+ return text.replace(userProvidedKeyEscapeRegex, '$&/');
2639
+ }
2640
+ /**
2641
+ * Generate a key string that identifies a element within a set.
2642
+ *
2643
+ * @param {*} element A element that could contain a manual key.
2644
+ * @param {number} index Index that is used if a manual key is not provided.
2645
+ * @return {string}
2646
+ */
2647
+
2648
+
2649
+ function getElementKey(element, index) {
2650
+ // Do some typechecking here since we call this blindly. We want to ensure
2651
+ // that we don't block potential future ES APIs.
2652
+ if (typeof element === 'object' && element !== null && element.key != null) {
2653
+ // Explicit key
2654
+ {
2655
+ checkKeyStringCoercion(element.key);
2656
+ }
2657
+
2658
+ return escape('' + element.key);
2659
+ } // Implicit key determined by the index in the set
2660
+
2661
+
2662
+ return index.toString(36);
2663
+ }
2664
+
2665
+ function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
2666
+ var type = typeof children;
2667
+
2668
+ if (type === 'undefined' || type === 'boolean') {
2669
+ // All of the above are perceived as null.
2670
+ children = null;
2671
+ }
2672
+
2673
+ var invokeCallback = false;
2674
+
2675
+ if (children === null) {
2676
+ invokeCallback = true;
2677
+ } else {
2678
+ switch (type) {
2679
+ case 'string':
2680
+ case 'number':
2681
+ invokeCallback = true;
2682
+ break;
2683
+
2684
+ case 'object':
2685
+ switch (children.$$typeof) {
2686
+ case REACT_ELEMENT_TYPE:
2687
+ case REACT_PORTAL_TYPE:
2688
+ invokeCallback = true;
2689
+ }
2690
+
2691
+ }
2692
+ }
2693
+
2694
+ if (invokeCallback) {
2695
+ var _child = children;
2696
+ var mappedChild = callback(_child); // If it's the only child, treat the name as if it was wrapped in an array
2697
+ // so that it's consistent if the number of children grows:
2698
+
2699
+ var childKey = nameSoFar === '' ? SEPARATOR + getElementKey(_child, 0) : nameSoFar;
2700
+
2701
+ if (isArray(mappedChild)) {
2702
+ var escapedChildKey = '';
2703
+
2704
+ if (childKey != null) {
2705
+ escapedChildKey = escapeUserProvidedKey(childKey) + '/';
2706
+ }
2707
+
2708
+ mapIntoArray(mappedChild, array, escapedChildKey, '', function (c) {
2709
+ return c;
2710
+ });
2711
+ } else if (mappedChild != null) {
2712
+ if (isValidElement(mappedChild)) {
2713
+ {
2714
+ // The `if` statement here prevents auto-disabling of the safe
2715
+ // coercion ESLint rule, so we must manually disable it below.
2716
+ // $FlowFixMe Flow incorrectly thinks React.Portal doesn't have a key
2717
+ if (mappedChild.key && (!_child || _child.key !== mappedChild.key)) {
2718
+ checkKeyStringCoercion(mappedChild.key);
2719
+ }
2720
+ }
2721
+
2722
+ mappedChild = cloneAndReplaceKey(mappedChild, // Keep both the (mapped) and old keys if they differ, just as
2723
+ // traverseAllChildren used to do for objects as children
2724
+ escapedPrefix + ( // $FlowFixMe Flow incorrectly thinks React.Portal doesn't have a key
2725
+ mappedChild.key && (!_child || _child.key !== mappedChild.key) ? // $FlowFixMe Flow incorrectly thinks existing element's key can be a number
2726
+ // eslint-disable-next-line react-internal/safe-string-coercion
2727
+ escapeUserProvidedKey('' + mappedChild.key) + '/' : '') + childKey);
2728
+ }
2729
+
2730
+ array.push(mappedChild);
2731
+ }
2732
+
2733
+ return 1;
2734
+ }
2735
+
2736
+ var child;
2737
+ var nextName;
2738
+ var subtreeCount = 0; // Count of children found in the current subtree.
2739
+
2740
+ var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
2741
+
2742
+ if (isArray(children)) {
2743
+ for (var i = 0; i < children.length; i++) {
2744
+ child = children[i];
2745
+ nextName = nextNamePrefix + getElementKey(child, i);
2746
+ subtreeCount += mapIntoArray(child, array, escapedPrefix, nextName, callback);
2747
+ }
2748
+ } else {
2749
+ var iteratorFn = getIteratorFn(children);
2750
+
2751
+ if (typeof iteratorFn === 'function') {
2752
+ var iterableChildren = children;
2753
+
2754
+ {
2755
+ // Warn about using Maps as children
2756
+ if (iteratorFn === iterableChildren.entries) {
2757
+ if (!didWarnAboutMaps) {
2758
+ warn('Using Maps as children is not supported. ' + 'Use an array of keyed ReactElements instead.');
2759
+ }
2760
+
2761
+ didWarnAboutMaps = true;
2762
+ }
2763
+ }
2764
+
2765
+ var iterator = iteratorFn.call(iterableChildren);
2766
+ var step;
2767
+ var ii = 0;
2768
+
2769
+ while (!(step = iterator.next()).done) {
2770
+ child = step.value;
2771
+ nextName = nextNamePrefix + getElementKey(child, ii++);
2772
+ subtreeCount += mapIntoArray(child, array, escapedPrefix, nextName, callback);
2773
+ }
2774
+ } else if (type === 'object') {
2775
+ // eslint-disable-next-line react-internal/safe-string-coercion
2776
+ var childrenString = String(children);
2777
+ throw new Error("Objects are not valid as a React child (found: " + (childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString) + "). " + 'If you meant to render a collection of children, use an array ' + 'instead.');
2778
+ }
2779
+ }
2780
+
2781
+ return subtreeCount;
2782
+ }
2783
+
2784
+ /**
2785
+ * Maps children that are typically specified as `props.children`.
2786
+ *
2787
+ * See https://reactjs.org/docs/react-api.html#reactchildrenmap
2788
+ *
2789
+ * The provided mapFunction(child, index) will be called for each
2790
+ * leaf child.
2791
+ *
2792
+ * @param {?*} children Children tree container.
2793
+ * @param {function(*, int)} func The map function.
2794
+ * @param {*} context Context for mapFunction.
2795
+ * @return {object} Object containing the ordered map of results.
2796
+ */
2797
+ function mapChildren(children, func, context) {
2798
+ if (children == null) {
2799
+ return children;
2800
+ }
2801
+
2802
+ var result = [];
2803
+ var count = 0;
2804
+ mapIntoArray(children, result, '', '', function (child) {
2805
+ return func.call(context, child, count++);
2806
+ });
2807
+ return result;
2808
+ }
2809
+ /**
2810
+ * Count the number of children that are typically specified as
2811
+ * `props.children`.
2812
+ *
2813
+ * See https://reactjs.org/docs/react-api.html#reactchildrencount
2814
+ *
2815
+ * @param {?*} children Children tree container.
2816
+ * @return {number} The number of children.
2817
+ */
2818
+
2819
+
2820
+ function countChildren(children) {
2821
+ var n = 0;
2822
+ mapChildren(children, function () {
2823
+ n++; // Don't return anything
2824
+ });
2825
+ return n;
2826
+ }
2827
+
2828
+ /**
2829
+ * Iterates through children that are typically specified as `props.children`.
2830
+ *
2831
+ * See https://reactjs.org/docs/react-api.html#reactchildrenforeach
2832
+ *
2833
+ * The provided forEachFunc(child, index) will be called for each
2834
+ * leaf child.
2835
+ *
2836
+ * @param {?*} children Children tree container.
2837
+ * @param {function(*, int)} forEachFunc
2838
+ * @param {*} forEachContext Context for forEachContext.
2839
+ */
2840
+ function forEachChildren(children, forEachFunc, forEachContext) {
2841
+ mapChildren(children, function () {
2842
+ forEachFunc.apply(this, arguments); // Don't return anything.
2843
+ }, forEachContext);
2844
+ }
2845
+ /**
2846
+ * Flatten a children object (typically specified as `props.children`) and
2847
+ * return an array with appropriately re-keyed children.
2848
+ *
2849
+ * See https://reactjs.org/docs/react-api.html#reactchildrentoarray
2850
+ */
2851
+
2852
+
2853
+ function toArray(children) {
2854
+ return mapChildren(children, function (child) {
2855
+ return child;
2856
+ }) || [];
2857
+ }
2858
+ /**
2859
+ * Returns the first child in a collection of children and verifies that there
2860
+ * is only one child in the collection.
2861
+ *
2862
+ * See https://reactjs.org/docs/react-api.html#reactchildrenonly
2863
+ *
2864
+ * The current implementation of this function assumes that a single child gets
2865
+ * passed without a wrapper, but the purpose of this helper function is to
2866
+ * abstract away the particular structure of children.
2867
+ *
2868
+ * @param {?object} children Child collection structure.
2869
+ * @return {ReactElement} The first and only `ReactElement` contained in the
2870
+ * structure.
2871
+ */
2872
+
2873
+
2874
+ function onlyChild(children) {
2875
+ if (!isValidElement(children)) {
2876
+ throw new Error('React.Children.only expected to receive a single React element child.');
2877
+ }
2878
+
2879
+ return children;
2880
+ }
2881
+
2882
+ function createContext(defaultValue) {
2883
+ // TODO: Second argument used to be an optional `calculateChangedBits`
2884
+ // function. Warn to reserve for future use?
2885
+ var context = {
2886
+ $$typeof: REACT_CONTEXT_TYPE,
2887
+ // As a workaround to support multiple concurrent renderers, we categorize
2888
+ // some renderers as primary and others as secondary. We only expect
2889
+ // there to be two concurrent renderers at most: React Native (primary) and
2890
+ // Fabric (secondary); React DOM (primary) and React ART (secondary).
2891
+ // Secondary renderers store their context values on separate fields.
2892
+ _currentValue: defaultValue,
2893
+ _currentValue2: defaultValue,
2894
+ // Used to track how many concurrent renderers this context currently
2895
+ // supports within in a single renderer. Such as parallel server rendering.
2896
+ _threadCount: 0,
2897
+ // These are circular
2898
+ Provider: null,
2899
+ Consumer: null,
2900
+ // Add these to use same hidden class in VM as ServerContext
2901
+ _defaultValue: null,
2902
+ _globalName: null
2903
+ };
2904
+ context.Provider = {
2905
+ $$typeof: REACT_PROVIDER_TYPE,
2906
+ _context: context
2907
+ };
2908
+ var hasWarnedAboutUsingNestedContextConsumers = false;
2909
+ var hasWarnedAboutUsingConsumerProvider = false;
2910
+ var hasWarnedAboutDisplayNameOnConsumer = false;
2911
+
2912
+ {
2913
+ // A separate object, but proxies back to the original context object for
2914
+ // backwards compatibility. It has a different $$typeof, so we can properly
2915
+ // warn for the incorrect usage of Context as a Consumer.
2916
+ var Consumer = {
2917
+ $$typeof: REACT_CONTEXT_TYPE,
2918
+ _context: context
2919
+ }; // $FlowFixMe: Flow complains about not setting a value, which is intentional here
2920
+
2921
+ Object.defineProperties(Consumer, {
2922
+ Provider: {
2923
+ get: function () {
2924
+ if (!hasWarnedAboutUsingConsumerProvider) {
2925
+ hasWarnedAboutUsingConsumerProvider = true;
2926
+
2927
+ error('Rendering <Context.Consumer.Provider> is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Provider> instead?');
2928
+ }
2929
+
2930
+ return context.Provider;
2931
+ },
2932
+ set: function (_Provider) {
2933
+ context.Provider = _Provider;
2934
+ }
2935
+ },
2936
+ _currentValue: {
2937
+ get: function () {
2938
+ return context._currentValue;
2939
+ },
2940
+ set: function (_currentValue) {
2941
+ context._currentValue = _currentValue;
2942
+ }
2943
+ },
2944
+ _currentValue2: {
2945
+ get: function () {
2946
+ return context._currentValue2;
2947
+ },
2948
+ set: function (_currentValue2) {
2949
+ context._currentValue2 = _currentValue2;
2950
+ }
2951
+ },
2952
+ _threadCount: {
2953
+ get: function () {
2954
+ return context._threadCount;
2955
+ },
2956
+ set: function (_threadCount) {
2957
+ context._threadCount = _threadCount;
2958
+ }
2959
+ },
2960
+ Consumer: {
2961
+ get: function () {
2962
+ if (!hasWarnedAboutUsingNestedContextConsumers) {
2963
+ hasWarnedAboutUsingNestedContextConsumers = true;
2964
+
2965
+ error('Rendering <Context.Consumer.Consumer> is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?');
2966
+ }
2967
+
2968
+ return context.Consumer;
2969
+ }
2970
+ },
2971
+ displayName: {
2972
+ get: function () {
2973
+ return context.displayName;
2974
+ },
2975
+ set: function (displayName) {
2976
+ if (!hasWarnedAboutDisplayNameOnConsumer) {
2977
+ warn('Setting `displayName` on Context.Consumer has no effect. ' + "You should set it directly on the context with Context.displayName = '%s'.", displayName);
2978
+
2979
+ hasWarnedAboutDisplayNameOnConsumer = true;
2980
+ }
2981
+ }
2982
+ }
2983
+ }); // $FlowFixMe: Flow complains about missing properties because it doesn't understand defineProperty
2984
+
2985
+ context.Consumer = Consumer;
2986
+ }
2987
+
2988
+ {
2989
+ context._currentRenderer = null;
2990
+ context._currentRenderer2 = null;
2991
+ }
2992
+
2993
+ return context;
2994
+ }
2995
+
2996
+ var Uninitialized = -1;
2997
+ var Pending = 0;
2998
+ var Resolved = 1;
2999
+ var Rejected = 2;
3000
+
3001
+ function lazyInitializer(payload) {
3002
+ if (payload._status === Uninitialized) {
3003
+ var ctor = payload._result;
3004
+ var thenable = ctor(); // Transition to the next state.
3005
+ // This might throw either because it's missing or throws. If so, we treat it
3006
+ // as still uninitialized and try again next time. Which is the same as what
3007
+ // happens if the ctor or any wrappers processing the ctor throws. This might
3008
+ // end up fixing it if the resolution was a concurrency bug.
3009
+
3010
+ thenable.then(function (moduleObject) {
3011
+ if (payload._status === Pending || payload._status === Uninitialized) {
3012
+ // Transition to the next state.
3013
+ var resolved = payload;
3014
+ resolved._status = Resolved;
3015
+ resolved._result = moduleObject;
3016
+ }
3017
+ }, function (error) {
3018
+ if (payload._status === Pending || payload._status === Uninitialized) {
3019
+ // Transition to the next state.
3020
+ var rejected = payload;
3021
+ rejected._status = Rejected;
3022
+ rejected._result = error;
3023
+ }
3024
+ });
3025
+
3026
+ if (payload._status === Uninitialized) {
3027
+ // In case, we're still uninitialized, then we're waiting for the thenable
3028
+ // to resolve. Set it as pending in the meantime.
3029
+ var pending = payload;
3030
+ pending._status = Pending;
3031
+ pending._result = thenable;
3032
+ }
3033
+ }
3034
+
3035
+ if (payload._status === Resolved) {
3036
+ var moduleObject = payload._result;
3037
+
3038
+ {
3039
+ if (moduleObject === undefined) {
3040
+ error('lazy: Expected the result of a dynamic imp' + 'ort() call. ' + 'Instead received: %s\n\nYour code should look like: \n ' + // Break up imports to avoid accidentally parsing them as dependencies.
3041
+ 'const MyComponent = lazy(() => imp' + "ort('./MyComponent'))\n\n" + 'Did you accidentally put curly braces around the import?', moduleObject);
3042
+ }
3043
+ }
3044
+
3045
+ {
3046
+ if (!('default' in moduleObject)) {
3047
+ error('lazy: Expected the result of a dynamic imp' + 'ort() call. ' + 'Instead received: %s\n\nYour code should look like: \n ' + // Break up imports to avoid accidentally parsing them as dependencies.
3048
+ 'const MyComponent = lazy(() => imp' + "ort('./MyComponent'))", moduleObject);
3049
+ }
3050
+ }
3051
+
3052
+ return moduleObject.default;
3053
+ } else {
3054
+ throw payload._result;
3055
+ }
3056
+ }
3057
+
3058
+ function lazy(ctor) {
3059
+ var payload = {
3060
+ // We use these fields to store the result.
3061
+ _status: Uninitialized,
3062
+ _result: ctor
3063
+ };
3064
+ var lazyType = {
3065
+ $$typeof: REACT_LAZY_TYPE,
3066
+ _payload: payload,
3067
+ _init: lazyInitializer
3068
+ };
3069
+
3070
+ {
3071
+ // In production, this would just set it on the object.
3072
+ var defaultProps;
3073
+ var propTypes; // $FlowFixMe
3074
+
3075
+ Object.defineProperties(lazyType, {
3076
+ defaultProps: {
3077
+ configurable: true,
3078
+ get: function () {
3079
+ return defaultProps;
3080
+ },
3081
+ set: function (newDefaultProps) {
3082
+ error('React.lazy(...): It is not supported to assign `defaultProps` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
3083
+
3084
+ defaultProps = newDefaultProps; // Match production behavior more closely:
3085
+ // $FlowFixMe
3086
+
3087
+ Object.defineProperty(lazyType, 'defaultProps', {
3088
+ enumerable: true
3089
+ });
3090
+ }
3091
+ },
3092
+ propTypes: {
3093
+ configurable: true,
3094
+ get: function () {
3095
+ return propTypes;
3096
+ },
3097
+ set: function (newPropTypes) {
3098
+ error('React.lazy(...): It is not supported to assign `propTypes` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
3099
+
3100
+ propTypes = newPropTypes; // Match production behavior more closely:
3101
+ // $FlowFixMe
3102
+
3103
+ Object.defineProperty(lazyType, 'propTypes', {
3104
+ enumerable: true
3105
+ });
3106
+ }
3107
+ }
3108
+ });
3109
+ }
3110
+
3111
+ return lazyType;
3112
+ }
3113
+
3114
+ function forwardRef(render) {
3115
+ {
3116
+ if (render != null && render.$$typeof === REACT_MEMO_TYPE) {
3117
+ error('forwardRef requires a render function but received a `memo` ' + 'component. Instead of forwardRef(memo(...)), use ' + 'memo(forwardRef(...)).');
3118
+ } else if (typeof render !== 'function') {
3119
+ error('forwardRef requires a render function but was given %s.', render === null ? 'null' : typeof render);
3120
+ } else {
3121
+ if (render.length !== 0 && render.length !== 2) {
3122
+ error('forwardRef render functions accept exactly two parameters: props and ref. %s', render.length === 1 ? 'Did you forget to use the ref parameter?' : 'Any additional parameter will be undefined.');
3123
+ }
3124
+ }
3125
+
3126
+ if (render != null) {
3127
+ if (render.defaultProps != null || render.propTypes != null) {
3128
+ error('forwardRef render functions do not support propTypes or defaultProps. ' + 'Did you accidentally pass a React component?');
3129
+ }
3130
+ }
3131
+ }
3132
+
3133
+ var elementType = {
3134
+ $$typeof: REACT_FORWARD_REF_TYPE,
3135
+ render: render
3136
+ };
3137
+
3138
+ {
3139
+ var ownName;
3140
+ Object.defineProperty(elementType, 'displayName', {
3141
+ enumerable: false,
3142
+ configurable: true,
3143
+ get: function () {
3144
+ return ownName;
3145
+ },
3146
+ set: function (name) {
3147
+ ownName = name; // The inner component shouldn't inherit this display name in most cases,
3148
+ // because the component may be used elsewhere.
3149
+ // But it's nice for anonymous functions to inherit the name,
3150
+ // so that our component-stack generation logic will display their frames.
3151
+ // An anonymous function generally suggests a pattern like:
3152
+ // React.forwardRef((props, ref) => {...});
3153
+ // This kind of inner function is not used elsewhere so the side effect is okay.
3154
+
3155
+ if (!render.name && !render.displayName) {
3156
+ render.displayName = name;
3157
+ }
3158
+ }
3159
+ });
3160
+ }
3161
+
3162
+ return elementType;
3163
+ }
3164
+
3165
+ var REACT_MODULE_REFERENCE;
3166
+
3167
+ {
3168
+ REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
3169
+ }
3170
+
3171
+ function isValidElementType(type) {
3172
+ if (typeof type === 'string' || typeof type === 'function') {
3173
+ return true;
3174
+ } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
3175
+
3176
+
3177
+ if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || enableDebugTracing || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || enableLegacyHidden || type === REACT_OFFSCREEN_TYPE || enableScopeAPI || enableCacheElement || enableTransitionTracing ) {
3178
+ return true;
3179
+ }
3180
+
3181
+ if (typeof type === 'object' && type !== null) {
3182
+ if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || // This needs to include all possible module reference object
3183
+ // types supported by any Flight configuration anywhere since
3184
+ // we don't know which Flight build this will end up being used
3185
+ // with.
3186
+ type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
3187
+ return true;
3188
+ }
3189
+ }
3190
+
3191
+ return false;
3192
+ }
3193
+
3194
+ function memo(type, compare) {
3195
+ {
3196
+ if (!isValidElementType(type)) {
3197
+ error('memo: The first argument must be a component. Instead ' + 'received: %s', type === null ? 'null' : typeof type);
3198
+ }
3199
+ }
3200
+
3201
+ var elementType = {
3202
+ $$typeof: REACT_MEMO_TYPE,
3203
+ type: type,
3204
+ compare: compare === undefined ? null : compare
3205
+ };
3206
+
3207
+ {
3208
+ var ownName;
3209
+ Object.defineProperty(elementType, 'displayName', {
3210
+ enumerable: false,
3211
+ configurable: true,
3212
+ get: function () {
3213
+ return ownName;
3214
+ },
3215
+ set: function (name) {
3216
+ ownName = name; // The inner component shouldn't inherit this display name in most cases,
3217
+ // because the component may be used elsewhere.
3218
+ // But it's nice for anonymous functions to inherit the name,
3219
+ // so that our component-stack generation logic will display their frames.
3220
+ // An anonymous function generally suggests a pattern like:
3221
+ // React.memo((props) => {...});
3222
+ // This kind of inner function is not used elsewhere so the side effect is okay.
3223
+
3224
+ if (!type.name && !type.displayName) {
3225
+ type.displayName = name;
3226
+ }
3227
+ }
3228
+ });
3229
+ }
3230
+
3231
+ return elementType;
3232
+ }
3233
+
3234
+ function resolveDispatcher() {
3235
+ var dispatcher = ReactCurrentDispatcher.current;
3236
+
3237
+ {
3238
+ if (dispatcher === null) {
3239
+ error('Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for' + ' one of the following reasons:\n' + '1. You might have mismatching versions of React and the renderer (such as React DOM)\n' + '2. You might be breaking the Rules of Hooks\n' + '3. You might have more than one copy of React in the same app\n' + 'See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.');
3240
+ }
3241
+ } // Will result in a null access error if accessed outside render phase. We
3242
+ // intentionally don't throw our own error because this is in a hot path.
3243
+ // Also helps ensure this is inlined.
3244
+
3245
+
3246
+ return dispatcher;
3247
+ }
3248
+ function useContext(Context) {
3249
+ var dispatcher = resolveDispatcher();
3250
+
3251
+ {
3252
+ // TODO: add a more generic warning for invalid values.
3253
+ if (Context._context !== undefined) {
3254
+ var realContext = Context._context; // Don't deduplicate because this legitimately causes bugs
3255
+ // and nobody should be using this in existing code.
3256
+
3257
+ if (realContext.Consumer === Context) {
3258
+ error('Calling useContext(Context.Consumer) is not supported, may cause bugs, and will be ' + 'removed in a future major release. Did you mean to call useContext(Context) instead?');
3259
+ } else if (realContext.Provider === Context) {
3260
+ error('Calling useContext(Context.Provider) is not supported. ' + 'Did you mean to call useContext(Context) instead?');
3261
+ }
3262
+ }
3263
+ }
3264
+
3265
+ return dispatcher.useContext(Context);
3266
+ }
3267
+ function useState(initialState) {
3268
+ var dispatcher = resolveDispatcher();
3269
+ return dispatcher.useState(initialState);
3270
+ }
3271
+ function useReducer(reducer, initialArg, init) {
3272
+ var dispatcher = resolveDispatcher();
3273
+ return dispatcher.useReducer(reducer, initialArg, init);
3274
+ }
3275
+ function useRef(initialValue) {
3276
+ var dispatcher = resolveDispatcher();
3277
+ return dispatcher.useRef(initialValue);
3278
+ }
3279
+ function useEffect(create, deps) {
3280
+ var dispatcher = resolveDispatcher();
3281
+ return dispatcher.useEffect(create, deps);
3282
+ }
3283
+ function useInsertionEffect(create, deps) {
3284
+ var dispatcher = resolveDispatcher();
3285
+ return dispatcher.useInsertionEffect(create, deps);
3286
+ }
3287
+ function useLayoutEffect(create, deps) {
3288
+ var dispatcher = resolveDispatcher();
3289
+ return dispatcher.useLayoutEffect(create, deps);
3290
+ }
3291
+ function useCallback(callback, deps) {
3292
+ var dispatcher = resolveDispatcher();
3293
+ return dispatcher.useCallback(callback, deps);
3294
+ }
3295
+ function useMemo(create, deps) {
3296
+ var dispatcher = resolveDispatcher();
3297
+ return dispatcher.useMemo(create, deps);
3298
+ }
3299
+ function useImperativeHandle(ref, create, deps) {
3300
+ var dispatcher = resolveDispatcher();
3301
+ return dispatcher.useImperativeHandle(ref, create, deps);
3302
+ }
3303
+ function useDebugValue(value, formatterFn) {
3304
+ {
3305
+ var dispatcher = resolveDispatcher();
3306
+ return dispatcher.useDebugValue(value, formatterFn);
3307
+ }
3308
+ }
3309
+ function useTransition() {
3310
+ var dispatcher = resolveDispatcher();
3311
+ return dispatcher.useTransition();
3312
+ }
3313
+ function useDeferredValue(value) {
3314
+ var dispatcher = resolveDispatcher();
3315
+ return dispatcher.useDeferredValue(value);
3316
+ }
3317
+ function useId() {
3318
+ var dispatcher = resolveDispatcher();
3319
+ return dispatcher.useId();
3320
+ }
3321
+ function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
3322
+ var dispatcher = resolveDispatcher();
3323
+ return dispatcher.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
3324
+ }
3325
+
3326
+ // Helpers to patch console.logs to avoid logging during side-effect free
3327
+ // replaying on render function. This currently only patches the object
3328
+ // lazily which won't cover if the log function was extracted eagerly.
3329
+ // We could also eagerly patch the method.
3330
+ var disabledDepth = 0;
3331
+ var prevLog;
3332
+ var prevInfo;
3333
+ var prevWarn;
3334
+ var prevError;
3335
+ var prevGroup;
3336
+ var prevGroupCollapsed;
3337
+ var prevGroupEnd;
3338
+
3339
+ function disabledLog() {}
3340
+
3341
+ disabledLog.__reactDisabledLog = true;
3342
+ function disableLogs() {
3343
+ {
3344
+ if (disabledDepth === 0) {
3345
+ /* eslint-disable react-internal/no-production-logging */
3346
+ prevLog = console.log;
3347
+ prevInfo = console.info;
3348
+ prevWarn = console.warn;
3349
+ prevError = console.error;
3350
+ prevGroup = console.group;
3351
+ prevGroupCollapsed = console.groupCollapsed;
3352
+ prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099
3353
+
3354
+ var props = {
3355
+ configurable: true,
3356
+ enumerable: true,
3357
+ value: disabledLog,
3358
+ writable: true
3359
+ }; // $FlowFixMe Flow thinks console is immutable.
3360
+
3361
+ Object.defineProperties(console, {
3362
+ info: props,
3363
+ log: props,
3364
+ warn: props,
3365
+ error: props,
3366
+ group: props,
3367
+ groupCollapsed: props,
3368
+ groupEnd: props
3369
+ });
3370
+ /* eslint-enable react-internal/no-production-logging */
3371
+ }
3372
+
3373
+ disabledDepth++;
3374
+ }
3375
+ }
3376
+ function reenableLogs() {
3377
+ {
3378
+ disabledDepth--;
3379
+
3380
+ if (disabledDepth === 0) {
3381
+ /* eslint-disable react-internal/no-production-logging */
3382
+ var props = {
3383
+ configurable: true,
3384
+ enumerable: true,
3385
+ writable: true
3386
+ }; // $FlowFixMe Flow thinks console is immutable.
3387
+
3388
+ Object.defineProperties(console, {
3389
+ log: assign({}, props, {
3390
+ value: prevLog
3391
+ }),
3392
+ info: assign({}, props, {
3393
+ value: prevInfo
3394
+ }),
3395
+ warn: assign({}, props, {
3396
+ value: prevWarn
3397
+ }),
3398
+ error: assign({}, props, {
3399
+ value: prevError
3400
+ }),
3401
+ group: assign({}, props, {
3402
+ value: prevGroup
3403
+ }),
3404
+ groupCollapsed: assign({}, props, {
3405
+ value: prevGroupCollapsed
3406
+ }),
3407
+ groupEnd: assign({}, props, {
3408
+ value: prevGroupEnd
3409
+ })
3410
+ });
3411
+ /* eslint-enable react-internal/no-production-logging */
3412
+ }
3413
+
3414
+ if (disabledDepth < 0) {
3415
+ error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.');
3416
+ }
3417
+ }
3418
+ }
3419
+
3420
+ var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher;
3421
+ var prefix;
3422
+ function describeBuiltInComponentFrame(name, source, ownerFn) {
3423
+ {
3424
+ if (prefix === undefined) {
3425
+ // Extract the VM specific prefix used by each line.
3426
+ try {
3427
+ throw Error();
3428
+ } catch (x) {
3429
+ var match = x.stack.trim().match(/\n( *(at )?)/);
3430
+ prefix = match && match[1] || '';
3431
+ }
3432
+ } // We use the prefix to ensure our stacks line up with native stack frames.
3433
+
3434
+
3435
+ return '\n' + prefix + name;
3436
+ }
3437
+ }
3438
+ var reentry = false;
3439
+ var componentFrameCache;
3440
+
3441
+ {
3442
+ var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
3443
+ componentFrameCache = new PossiblyWeakMap();
3444
+ }
3445
+
3446
+ function describeNativeComponentFrame(fn, construct) {
3447
+ // If something asked for a stack inside a fake render, it should get ignored.
3448
+ if ( !fn || reentry) {
3449
+ return '';
3450
+ }
3451
+
3452
+ {
3453
+ var frame = componentFrameCache.get(fn);
3454
+
3455
+ if (frame !== undefined) {
3456
+ return frame;
3457
+ }
3458
+ }
3459
+
3460
+ var control;
3461
+ reentry = true;
3462
+ var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined.
3463
+
3464
+ Error.prepareStackTrace = undefined;
3465
+ var previousDispatcher;
3466
+
3467
+ {
3468
+ previousDispatcher = ReactCurrentDispatcher$1.current; // Set the dispatcher in DEV because this might be call in the render function
3469
+ // for warnings.
3470
+
3471
+ ReactCurrentDispatcher$1.current = null;
3472
+ disableLogs();
3473
+ }
3474
+
3475
+ try {
3476
+ // This should throw.
3477
+ if (construct) {
3478
+ // Something should be setting the props in the constructor.
3479
+ var Fake = function () {
3480
+ throw Error();
3481
+ }; // $FlowFixMe
3482
+
3483
+
3484
+ Object.defineProperty(Fake.prototype, 'props', {
3485
+ set: function () {
3486
+ // We use a throwing setter instead of frozen or non-writable props
3487
+ // because that won't throw in a non-strict mode function.
3488
+ throw Error();
3489
+ }
3490
+ });
3491
+
3492
+ if (typeof Reflect === 'object' && Reflect.construct) {
3493
+ // We construct a different control for this case to include any extra
3494
+ // frames added by the construct call.
3495
+ try {
3496
+ Reflect.construct(Fake, []);
3497
+ } catch (x) {
3498
+ control = x;
3499
+ }
3500
+
3501
+ Reflect.construct(fn, [], Fake);
3502
+ } else {
3503
+ try {
3504
+ Fake.call();
3505
+ } catch (x) {
3506
+ control = x;
3507
+ }
3508
+
3509
+ fn.call(Fake.prototype);
3510
+ }
3511
+ } else {
3512
+ try {
3513
+ throw Error();
3514
+ } catch (x) {
3515
+ control = x;
3516
+ }
3517
+
3518
+ fn();
3519
+ }
3520
+ } catch (sample) {
3521
+ // This is inlined manually because closure doesn't do it for us.
3522
+ if (sample && control && typeof sample.stack === 'string') {
3523
+ // This extracts the first frame from the sample that isn't also in the control.
3524
+ // Skipping one frame that we assume is the frame that calls the two.
3525
+ var sampleLines = sample.stack.split('\n');
3526
+ var controlLines = control.stack.split('\n');
3527
+ var s = sampleLines.length - 1;
3528
+ var c = controlLines.length - 1;
3529
+
3530
+ while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) {
3531
+ // We expect at least one stack frame to be shared.
3532
+ // Typically this will be the root most one. However, stack frames may be
3533
+ // cut off due to maximum stack limits. In this case, one maybe cut off
3534
+ // earlier than the other. We assume that the sample is longer or the same
3535
+ // and there for cut off earlier. So we should find the root most frame in
3536
+ // the sample somewhere in the control.
3537
+ c--;
3538
+ }
3539
+
3540
+ for (; s >= 1 && c >= 0; s--, c--) {
3541
+ // Next we find the first one that isn't the same which should be the
3542
+ // frame that called our sample function and the control.
3543
+ if (sampleLines[s] !== controlLines[c]) {
3544
+ // In V8, the first line is describing the message but other VMs don't.
3545
+ // If we're about to return the first line, and the control is also on the same
3546
+ // line, that's a pretty good indicator that our sample threw at same line as
3547
+ // the control. I.e. before we entered the sample frame. So we ignore this result.
3548
+ // This can happen if you passed a class to function component, or non-function.
3549
+ if (s !== 1 || c !== 1) {
3550
+ do {
3551
+ s--;
3552
+ c--; // We may still have similar intermediate frames from the construct call.
3553
+ // The next one that isn't the same should be our match though.
3554
+
3555
+ if (c < 0 || sampleLines[s] !== controlLines[c]) {
3556
+ // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
3557
+ var _frame = '\n' + sampleLines[s].replace(' at new ', ' at '); // If our component frame is labeled "<anonymous>"
3558
+ // but we have a user-provided "displayName"
3559
+ // splice it in to make the stack more readable.
3560
+
3561
+
3562
+ if (fn.displayName && _frame.includes('<anonymous>')) {
3563
+ _frame = _frame.replace('<anonymous>', fn.displayName);
3564
+ }
3565
+
3566
+ {
3567
+ if (typeof fn === 'function') {
3568
+ componentFrameCache.set(fn, _frame);
3569
+ }
3570
+ } // Return the line we found.
3571
+
3572
+
3573
+ return _frame;
3574
+ }
3575
+ } while (s >= 1 && c >= 0);
3576
+ }
3577
+
3578
+ break;
3579
+ }
3580
+ }
3581
+ }
3582
+ } finally {
3583
+ reentry = false;
3584
+
3585
+ {
3586
+ ReactCurrentDispatcher$1.current = previousDispatcher;
3587
+ reenableLogs();
3588
+ }
3589
+
3590
+ Error.prepareStackTrace = previousPrepareStackTrace;
3591
+ } // Fallback to just using the name if we couldn't make it throw.
3592
+
3593
+
3594
+ var name = fn ? fn.displayName || fn.name : '';
3595
+ var syntheticFrame = name ? describeBuiltInComponentFrame(name) : '';
3596
+
3597
+ {
3598
+ if (typeof fn === 'function') {
3599
+ componentFrameCache.set(fn, syntheticFrame);
3600
+ }
3601
+ }
3602
+
3603
+ return syntheticFrame;
3604
+ }
3605
+ function describeFunctionComponentFrame(fn, source, ownerFn) {
3606
+ {
3607
+ return describeNativeComponentFrame(fn, false);
3608
+ }
3609
+ }
3610
+
3611
+ function shouldConstruct(Component) {
3612
+ var prototype = Component.prototype;
3613
+ return !!(prototype && prototype.isReactComponent);
3614
+ }
3615
+
3616
+ function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) {
3617
+
3618
+ if (type == null) {
3619
+ return '';
3620
+ }
3621
+
3622
+ if (typeof type === 'function') {
3623
+ {
3624
+ return describeNativeComponentFrame(type, shouldConstruct(type));
3625
+ }
3626
+ }
3627
+
3628
+ if (typeof type === 'string') {
3629
+ return describeBuiltInComponentFrame(type);
3630
+ }
3631
+
3632
+ switch (type) {
3633
+ case REACT_SUSPENSE_TYPE:
3634
+ return describeBuiltInComponentFrame('Suspense');
3635
+
3636
+ case REACT_SUSPENSE_LIST_TYPE:
3637
+ return describeBuiltInComponentFrame('SuspenseList');
3638
+ }
3639
+
3640
+ if (typeof type === 'object') {
3641
+ switch (type.$$typeof) {
3642
+ case REACT_FORWARD_REF_TYPE:
3643
+ return describeFunctionComponentFrame(type.render);
3644
+
3645
+ case REACT_MEMO_TYPE:
3646
+ // Memo may contain any component type so we recursively resolve it.
3647
+ return describeUnknownElementTypeFrameInDEV(type.type);
3648
+
3649
+ case REACT_LAZY_TYPE:
3650
+ {
3651
+ var lazyComponent = type;
3652
+ var payload = lazyComponent._payload;
3653
+ var init = lazyComponent._init;
3654
+
3655
+ try {
3656
+ // Lazy may contain any component type so we recursively resolve it.
3657
+ return describeUnknownElementTypeFrameInDEV(init(payload));
3658
+ } catch (x) {}
3659
+ }
3660
+ }
3661
+ }
3662
+
3663
+ return '';
3664
+ }
3665
+
3666
+ var loggedTypeFailures = {};
3667
+ var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
3668
+
3669
+ function setCurrentlyValidatingElement(element) {
3670
+ {
3671
+ if (element) {
3672
+ var stack = describeUnknownElementTypeFrameInDEV(element.type);
3673
+ ReactDebugCurrentFrame$1.setExtraStackFrame(stack);
3674
+ } else {
3675
+ ReactDebugCurrentFrame$1.setExtraStackFrame(null);
3676
+ }
3677
+ }
3678
+ }
3679
+
3680
+ function checkPropTypes(typeSpecs, values, location, componentName, element) {
3681
+ {
3682
+ // $FlowFixMe This is okay but Flow doesn't know it.
3683
+ var has = Function.call.bind(hasOwnProperty);
3684
+
3685
+ for (var typeSpecName in typeSpecs) {
3686
+ if (has(typeSpecs, typeSpecName)) {
3687
+ var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
3688
+ // fail the render phase where it didn't fail before. So we log it.
3689
+ // After these have been cleaned up, we'll let them throw.
3690
+
3691
+ try {
3692
+ // This is intentionally an invariant that gets caught. It's the same
3693
+ // behavior as without this statement except with a better message.
3694
+ if (typeof typeSpecs[typeSpecName] !== 'function') {
3695
+ // eslint-disable-next-line react-internal/prod-error-codes
3696
+ var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.');
3697
+ err.name = 'Invariant Violation';
3698
+ throw err;
3699
+ }
3700
+
3701
+ error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED');
3702
+ } catch (ex) {
3703
+ error$1 = ex;
3704
+ }
3705
+
3706
+ if (error$1 && !(error$1 instanceof Error)) {
3707
+ setCurrentlyValidatingElement(element);
3708
+
3709
+ error('%s: type specification of %s' + ' `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error$1);
3710
+
3711
+ setCurrentlyValidatingElement(null);
3712
+ }
3713
+
3714
+ if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) {
3715
+ // Only monitor this failure once because there tends to be a lot of the
3716
+ // same error.
3717
+ loggedTypeFailures[error$1.message] = true;
3718
+ setCurrentlyValidatingElement(element);
3719
+
3720
+ error('Failed %s type: %s', location, error$1.message);
3721
+
3722
+ setCurrentlyValidatingElement(null);
3723
+ }
3724
+ }
3725
+ }
3726
+ }
3727
+ }
3728
+
3729
+ function setCurrentlyValidatingElement$1(element) {
3730
+ {
3731
+ if (element) {
3732
+ var stack = describeUnknownElementTypeFrameInDEV(element.type);
3733
+ setExtraStackFrame(stack);
3734
+ } else {
3735
+ setExtraStackFrame(null);
3736
+ }
3737
+ }
3738
+ }
3739
+
3740
+ var propTypesMisspellWarningShown;
3741
+
3742
+ {
3743
+ propTypesMisspellWarningShown = false;
3744
+ }
3745
+
3746
+ function getDeclarationErrorAddendum() {
3747
+ if (ReactCurrentOwner.current) {
3748
+ var name = getComponentNameFromType(ReactCurrentOwner.current.type);
3749
+
3750
+ if (name) {
3751
+ return '\n\nCheck the render method of `' + name + '`.';
3752
+ }
3753
+ }
3754
+
3755
+ return '';
3756
+ }
3757
+
3758
+ function getSourceInfoErrorAddendum(source) {
3759
+ if (source !== undefined) {
3760
+ var fileName = source.fileName.replace(/^.*[\\\/]/, '');
3761
+ var lineNumber = source.lineNumber;
3762
+ return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
3763
+ }
3764
+
3765
+ return '';
3766
+ }
3767
+
3768
+ function getSourceInfoErrorAddendumForProps(elementProps) {
3769
+ if (elementProps !== null && elementProps !== undefined) {
3770
+ return getSourceInfoErrorAddendum(elementProps.__source);
3771
+ }
3772
+
3773
+ return '';
3774
+ }
3775
+ /**
3776
+ * Warn if there's no key explicitly set on dynamic arrays of children or
3777
+ * object keys are not valid. This allows us to keep track of children between
3778
+ * updates.
3779
+ */
3780
+
3781
+
3782
+ var ownerHasKeyUseWarning = {};
3783
+
3784
+ function getCurrentComponentErrorInfo(parentType) {
3785
+ var info = getDeclarationErrorAddendum();
3786
+
3787
+ if (!info) {
3788
+ var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
3789
+
3790
+ if (parentName) {
3791
+ info = "\n\nCheck the top-level render call using <" + parentName + ">.";
3792
+ }
3793
+ }
3794
+
3795
+ return info;
3796
+ }
3797
+ /**
3798
+ * Warn if the element doesn't have an explicit key assigned to it.
3799
+ * This element is in an array. The array could grow and shrink or be
3800
+ * reordered. All children that haven't already been validated are required to
3801
+ * have a "key" property assigned to it. Error statuses are cached so a warning
3802
+ * will only be shown once.
3803
+ *
3804
+ * @internal
3805
+ * @param {ReactElement} element Element that requires a key.
3806
+ * @param {*} parentType element's parent's type.
3807
+ */
3808
+
3809
+
3810
+ function validateExplicitKey(element, parentType) {
3811
+ if (!element._store || element._store.validated || element.key != null) {
3812
+ return;
3813
+ }
3814
+
3815
+ element._store.validated = true;
3816
+ var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
3817
+
3818
+ if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
3819
+ return;
3820
+ }
3821
+
3822
+ ownerHasKeyUseWarning[currentComponentErrorInfo] = true; // Usually the current owner is the offender, but if it accepts children as a
3823
+ // property, it may be the creator of the child that's responsible for
3824
+ // assigning it a key.
3825
+
3826
+ var childOwner = '';
3827
+
3828
+ if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
3829
+ // Give the component that originally created this child.
3830
+ childOwner = " It was passed a child from " + getComponentNameFromType(element._owner.type) + ".";
3831
+ }
3832
+
3833
+ {
3834
+ setCurrentlyValidatingElement$1(element);
3835
+
3836
+ error('Each child in a list should have a unique "key" prop.' + '%s%s See https://reactjs.org/link/warning-keys for more information.', currentComponentErrorInfo, childOwner);
3837
+
3838
+ setCurrentlyValidatingElement$1(null);
3839
+ }
3840
+ }
3841
+ /**
3842
+ * Ensure that every element either is passed in a static location, in an
3843
+ * array with an explicit keys property defined, or in an object literal
3844
+ * with valid key property.
3845
+ *
3846
+ * @internal
3847
+ * @param {ReactNode} node Statically passed child of any type.
3848
+ * @param {*} parentType node's parent's type.
3849
+ */
3850
+
3851
+
3852
+ function validateChildKeys(node, parentType) {
3853
+ if (typeof node !== 'object') {
3854
+ return;
3855
+ }
3856
+
3857
+ if (isArray(node)) {
3858
+ for (var i = 0; i < node.length; i++) {
3859
+ var child = node[i];
3860
+
3861
+ if (isValidElement(child)) {
3862
+ validateExplicitKey(child, parentType);
3863
+ }
3864
+ }
3865
+ } else if (isValidElement(node)) {
3866
+ // This element was passed in a valid location.
3867
+ if (node._store) {
3868
+ node._store.validated = true;
3869
+ }
3870
+ } else if (node) {
3871
+ var iteratorFn = getIteratorFn(node);
3872
+
3873
+ if (typeof iteratorFn === 'function') {
3874
+ // Entry iterators used to provide implicit keys,
3875
+ // but now we print a separate warning for them later.
3876
+ if (iteratorFn !== node.entries) {
3877
+ var iterator = iteratorFn.call(node);
3878
+ var step;
3879
+
3880
+ while (!(step = iterator.next()).done) {
3881
+ if (isValidElement(step.value)) {
3882
+ validateExplicitKey(step.value, parentType);
3883
+ }
3884
+ }
3885
+ }
3886
+ }
3887
+ }
3888
+ }
3889
+ /**
3890
+ * Given an element, validate that its props follow the propTypes definition,
3891
+ * provided by the type.
3892
+ *
3893
+ * @param {ReactElement} element
3894
+ */
3895
+
3896
+
3897
+ function validatePropTypes(element) {
3898
+ {
3899
+ var type = element.type;
3900
+
3901
+ if (type === null || type === undefined || typeof type === 'string') {
3902
+ return;
3903
+ }
3904
+
3905
+ var propTypes;
3906
+
3907
+ if (typeof type === 'function') {
3908
+ propTypes = type.propTypes;
3909
+ } else if (typeof type === 'object' && (type.$$typeof === REACT_FORWARD_REF_TYPE || // Note: Memo only checks outer props here.
3910
+ // Inner props are checked in the reconciler.
3911
+ type.$$typeof === REACT_MEMO_TYPE)) {
3912
+ propTypes = type.propTypes;
3913
+ } else {
3914
+ return;
3915
+ }
3916
+
3917
+ if (propTypes) {
3918
+ // Intentionally inside to avoid triggering lazy initializers:
3919
+ var name = getComponentNameFromType(type);
3920
+ checkPropTypes(propTypes, element.props, 'prop', name, element);
3921
+ } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
3922
+ propTypesMisspellWarningShown = true; // Intentionally inside to avoid triggering lazy initializers:
3923
+
3924
+ var _name = getComponentNameFromType(type);
3925
+
3926
+ error('Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', _name || 'Unknown');
3927
+ }
3928
+
3929
+ if (typeof type.getDefaultProps === 'function' && !type.getDefaultProps.isReactClassApproved) {
3930
+ error('getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.');
3931
+ }
3932
+ }
3933
+ }
3934
+ /**
3935
+ * Given a fragment, validate that it can only be provided with fragment props
3936
+ * @param {ReactElement} fragment
3937
+ */
3938
+
3939
+
3940
+ function validateFragmentProps(fragment) {
3941
+ {
3942
+ var keys = Object.keys(fragment.props);
3943
+
3944
+ for (var i = 0; i < keys.length; i++) {
3945
+ var key = keys[i];
3946
+
3947
+ if (key !== 'children' && key !== 'key') {
3948
+ setCurrentlyValidatingElement$1(fragment);
3949
+
3950
+ error('Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.', key);
3951
+
3952
+ setCurrentlyValidatingElement$1(null);
3953
+ break;
3954
+ }
3955
+ }
3956
+
3957
+ if (fragment.ref !== null) {
3958
+ setCurrentlyValidatingElement$1(fragment);
3959
+
3960
+ error('Invalid attribute `ref` supplied to `React.Fragment`.');
3961
+
3962
+ setCurrentlyValidatingElement$1(null);
3963
+ }
3964
+ }
3965
+ }
3966
+ function createElementWithValidation(type, props, children) {
3967
+ var validType = isValidElementType(type); // We warn in this case but don't throw. We expect the element creation to
3968
+ // succeed and there will likely be errors in render.
3969
+
3970
+ if (!validType) {
3971
+ var info = '';
3972
+
3973
+ if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
3974
+ info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and named imports.";
3975
+ }
3976
+
3977
+ var sourceInfo = getSourceInfoErrorAddendumForProps(props);
3978
+
3979
+ if (sourceInfo) {
3980
+ info += sourceInfo;
3981
+ } else {
3982
+ info += getDeclarationErrorAddendum();
3983
+ }
3984
+
3985
+ var typeString;
3986
+
3987
+ if (type === null) {
3988
+ typeString = 'null';
3989
+ } else if (isArray(type)) {
3990
+ typeString = 'array';
3991
+ } else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
3992
+ typeString = "<" + (getComponentNameFromType(type.type) || 'Unknown') + " />";
3993
+ info = ' Did you accidentally export a JSX literal instead of a component?';
3994
+ } else {
3995
+ typeString = typeof type;
3996
+ }
3997
+
3998
+ {
3999
+ error('React.createElement: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', typeString, info);
4000
+ }
4001
+ }
4002
+
4003
+ var element = createElement.apply(this, arguments); // The result can be nullish if a mock or a custom function is used.
4004
+ // TODO: Drop this when these are no longer allowed as the type argument.
4005
+
4006
+ if (element == null) {
4007
+ return element;
4008
+ } // Skip key warning if the type isn't valid since our key validation logic
4009
+ // doesn't expect a non-string/function type and can throw confusing errors.
4010
+ // We don't want exception behavior to differ between dev and prod.
4011
+ // (Rendering will throw with a helpful message and as soon as the type is
4012
+ // fixed, the key warnings will appear.)
4013
+
4014
+
4015
+ if (validType) {
4016
+ for (var i = 2; i < arguments.length; i++) {
4017
+ validateChildKeys(arguments[i], type);
4018
+ }
4019
+ }
4020
+
4021
+ if (type === REACT_FRAGMENT_TYPE) {
4022
+ validateFragmentProps(element);
4023
+ } else {
4024
+ validatePropTypes(element);
4025
+ }
4026
+
4027
+ return element;
4028
+ }
4029
+ var didWarnAboutDeprecatedCreateFactory = false;
4030
+ function createFactoryWithValidation(type) {
4031
+ var validatedFactory = createElementWithValidation.bind(null, type);
4032
+ validatedFactory.type = type;
4033
+
4034
+ {
4035
+ if (!didWarnAboutDeprecatedCreateFactory) {
4036
+ didWarnAboutDeprecatedCreateFactory = true;
4037
+
4038
+ warn('React.createFactory() is deprecated and will be removed in ' + 'a future major release. Consider using JSX ' + 'or use React.createElement() directly instead.');
4039
+ } // Legacy hook: remove it
4040
+
4041
+
4042
+ Object.defineProperty(validatedFactory, 'type', {
4043
+ enumerable: false,
4044
+ get: function () {
4045
+ warn('Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.');
4046
+
4047
+ Object.defineProperty(this, 'type', {
4048
+ value: type
4049
+ });
4050
+ return type;
4051
+ }
4052
+ });
4053
+ }
4054
+
4055
+ return validatedFactory;
4056
+ }
4057
+ function cloneElementWithValidation(element, props, children) {
4058
+ var newElement = cloneElement.apply(this, arguments);
4059
+
4060
+ for (var i = 2; i < arguments.length; i++) {
4061
+ validateChildKeys(arguments[i], newElement.type);
4062
+ }
4063
+
4064
+ validatePropTypes(newElement);
4065
+ return newElement;
4066
+ }
4067
+
4068
+ function startTransition(scope, options) {
4069
+ var prevTransition = ReactCurrentBatchConfig.transition;
4070
+ ReactCurrentBatchConfig.transition = {};
4071
+ var currentTransition = ReactCurrentBatchConfig.transition;
4072
+
4073
+ {
4074
+ ReactCurrentBatchConfig.transition._updatedFibers = new Set();
4075
+ }
4076
+
4077
+ try {
4078
+ scope();
4079
+ } finally {
4080
+ ReactCurrentBatchConfig.transition = prevTransition;
4081
+
4082
+ {
4083
+ if (prevTransition === null && currentTransition._updatedFibers) {
4084
+ var updatedFibersCount = currentTransition._updatedFibers.size;
4085
+
4086
+ if (updatedFibersCount > 10) {
4087
+ warn('Detected a large number of updates inside startTransition. ' + 'If this is due to a subscription please re-write it to use React provided hooks. ' + 'Otherwise concurrent mode guarantees are off the table.');
4088
+ }
4089
+
4090
+ currentTransition._updatedFibers.clear();
4091
+ }
4092
+ }
4093
+ }
4094
+ }
4095
+
4096
+ var didWarnAboutMessageChannel = false;
4097
+ var enqueueTaskImpl = null;
4098
+ function enqueueTask(task) {
4099
+ if (enqueueTaskImpl === null) {
4100
+ try {
4101
+ // read require off the module object to get around the bundlers.
4102
+ // we don't want them to detect a require and bundle a Node polyfill.
4103
+ var requireString = ('require' + Math.random()).slice(0, 7);
4104
+ var nodeRequire = module && module[requireString]; // assuming we're in node, let's try to get node's
4105
+ // version of setImmediate, bypassing fake timers if any.
4106
+
4107
+ enqueueTaskImpl = nodeRequire.call(module, 'timers').setImmediate;
4108
+ } catch (_err) {
4109
+ // we're in a browser
4110
+ // we can't use regular timers because they may still be faked
4111
+ // so we try MessageChannel+postMessage instead
4112
+ enqueueTaskImpl = function (callback) {
4113
+ {
4114
+ if (didWarnAboutMessageChannel === false) {
4115
+ didWarnAboutMessageChannel = true;
4116
+
4117
+ if (typeof MessageChannel === 'undefined') {
4118
+ error('This browser does not have a MessageChannel implementation, ' + 'so enqueuing tasks via await act(async () => ...) will fail. ' + 'Please file an issue at https://github.com/facebook/react/issues ' + 'if you encounter this warning.');
4119
+ }
4120
+ }
4121
+ }
4122
+
4123
+ var channel = new MessageChannel();
4124
+ channel.port1.onmessage = callback;
4125
+ channel.port2.postMessage(undefined);
4126
+ };
4127
+ }
4128
+ }
4129
+
4130
+ return enqueueTaskImpl(task);
4131
+ }
4132
+
4133
+ var actScopeDepth = 0;
4134
+ var didWarnNoAwaitAct = false;
4135
+ function act(callback) {
4136
+ {
4137
+ // `act` calls can be nested, so we track the depth. This represents the
4138
+ // number of `act` scopes on the stack.
4139
+ var prevActScopeDepth = actScopeDepth;
4140
+ actScopeDepth++;
4141
+
4142
+ if (ReactCurrentActQueue.current === null) {
4143
+ // This is the outermost `act` scope. Initialize the queue. The reconciler
4144
+ // will detect the queue and use it instead of Scheduler.
4145
+ ReactCurrentActQueue.current = [];
4146
+ }
4147
+
4148
+ var prevIsBatchingLegacy = ReactCurrentActQueue.isBatchingLegacy;
4149
+ var result;
4150
+
4151
+ try {
4152
+ // Used to reproduce behavior of `batchedUpdates` in legacy mode. Only
4153
+ // set to `true` while the given callback is executed, not for updates
4154
+ // triggered during an async event, because this is how the legacy
4155
+ // implementation of `act` behaved.
4156
+ ReactCurrentActQueue.isBatchingLegacy = true;
4157
+ result = callback(); // Replicate behavior of original `act` implementation in legacy mode,
4158
+ // which flushed updates immediately after the scope function exits, even
4159
+ // if it's an async function.
4160
+
4161
+ if (!prevIsBatchingLegacy && ReactCurrentActQueue.didScheduleLegacyUpdate) {
4162
+ var queue = ReactCurrentActQueue.current;
4163
+
4164
+ if (queue !== null) {
4165
+ ReactCurrentActQueue.didScheduleLegacyUpdate = false;
4166
+ flushActQueue(queue);
4167
+ }
4168
+ }
4169
+ } catch (error) {
4170
+ popActScope(prevActScopeDepth);
4171
+ throw error;
4172
+ } finally {
4173
+ ReactCurrentActQueue.isBatchingLegacy = prevIsBatchingLegacy;
4174
+ }
4175
+
4176
+ if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
4177
+ var thenableResult = result; // The callback is an async function (i.e. returned a promise). Wait
4178
+ // for it to resolve before exiting the current scope.
4179
+
4180
+ var wasAwaited = false;
4181
+ var thenable = {
4182
+ then: function (resolve, reject) {
4183
+ wasAwaited = true;
4184
+ thenableResult.then(function (returnValue) {
4185
+ popActScope(prevActScopeDepth);
4186
+
4187
+ if (actScopeDepth === 0) {
4188
+ // We've exited the outermost act scope. Recursively flush the
4189
+ // queue until there's no remaining work.
4190
+ recursivelyFlushAsyncActWork(returnValue, resolve, reject);
4191
+ } else {
4192
+ resolve(returnValue);
4193
+ }
4194
+ }, function (error) {
4195
+ // The callback threw an error.
4196
+ popActScope(prevActScopeDepth);
4197
+ reject(error);
4198
+ });
4199
+ }
4200
+ };
4201
+
4202
+ {
4203
+ if (!didWarnNoAwaitAct && typeof Promise !== 'undefined') {
4204
+ // eslint-disable-next-line no-undef
4205
+ Promise.resolve().then(function () {}).then(function () {
4206
+ if (!wasAwaited) {
4207
+ didWarnNoAwaitAct = true;
4208
+
4209
+ error('You called act(async () => ...) without await. ' + 'This could lead to unexpected testing behaviour, ' + 'interleaving multiple act calls and mixing their ' + 'scopes. ' + 'You should - await act(async () => ...);');
4210
+ }
4211
+ });
4212
+ }
4213
+ }
4214
+
4215
+ return thenable;
4216
+ } else {
4217
+ var returnValue = result; // The callback is not an async function. Exit the current scope
4218
+ // immediately, without awaiting.
4219
+
4220
+ popActScope(prevActScopeDepth);
4221
+
4222
+ if (actScopeDepth === 0) {
4223
+ // Exiting the outermost act scope. Flush the queue.
4224
+ var _queue = ReactCurrentActQueue.current;
4225
+
4226
+ if (_queue !== null) {
4227
+ flushActQueue(_queue);
4228
+ ReactCurrentActQueue.current = null;
4229
+ } // Return a thenable. If the user awaits it, we'll flush again in
4230
+ // case additional work was scheduled by a microtask.
4231
+
4232
+
4233
+ var _thenable = {
4234
+ then: function (resolve, reject) {
4235
+ // Confirm we haven't re-entered another `act` scope, in case
4236
+ // the user does something weird like await the thenable
4237
+ // multiple times.
4238
+ if (ReactCurrentActQueue.current === null) {
4239
+ // Recursively flush the queue until there's no remaining work.
4240
+ ReactCurrentActQueue.current = [];
4241
+ recursivelyFlushAsyncActWork(returnValue, resolve, reject);
4242
+ } else {
4243
+ resolve(returnValue);
4244
+ }
4245
+ }
4246
+ };
4247
+ return _thenable;
4248
+ } else {
4249
+ // Since we're inside a nested `act` scope, the returned thenable
4250
+ // immediately resolves. The outer scope will flush the queue.
4251
+ var _thenable2 = {
4252
+ then: function (resolve, reject) {
4253
+ resolve(returnValue);
4254
+ }
4255
+ };
4256
+ return _thenable2;
4257
+ }
4258
+ }
4259
+ }
4260
+ }
4261
+
4262
+ function popActScope(prevActScopeDepth) {
4263
+ {
4264
+ if (prevActScopeDepth !== actScopeDepth - 1) {
4265
+ error('You seem to have overlapping act() calls, this is not supported. ' + 'Be sure to await previous act() calls before making a new one. ');
4266
+ }
4267
+
4268
+ actScopeDepth = prevActScopeDepth;
4269
+ }
4270
+ }
4271
+
4272
+ function recursivelyFlushAsyncActWork(returnValue, resolve, reject) {
4273
+ {
4274
+ var queue = ReactCurrentActQueue.current;
4275
+
4276
+ if (queue !== null) {
4277
+ try {
4278
+ flushActQueue(queue);
4279
+ enqueueTask(function () {
4280
+ if (queue.length === 0) {
4281
+ // No additional work was scheduled. Finish.
4282
+ ReactCurrentActQueue.current = null;
4283
+ resolve(returnValue);
4284
+ } else {
4285
+ // Keep flushing work until there's none left.
4286
+ recursivelyFlushAsyncActWork(returnValue, resolve, reject);
4287
+ }
4288
+ });
4289
+ } catch (error) {
4290
+ reject(error);
4291
+ }
4292
+ } else {
4293
+ resolve(returnValue);
4294
+ }
4295
+ }
4296
+ }
4297
+
4298
+ var isFlushing = false;
4299
+
4300
+ function flushActQueue(queue) {
4301
+ {
4302
+ if (!isFlushing) {
4303
+ // Prevent re-entrance.
4304
+ isFlushing = true;
4305
+ var i = 0;
4306
+
4307
+ try {
4308
+ for (; i < queue.length; i++) {
4309
+ var callback = queue[i];
4310
+
4311
+ do {
4312
+ callback = callback(true);
4313
+ } while (callback !== null);
4314
+ }
4315
+
4316
+ queue.length = 0;
4317
+ } catch (error) {
4318
+ // If something throws, leave the remaining callbacks on the queue.
4319
+ queue = queue.slice(i + 1);
4320
+ throw error;
4321
+ } finally {
4322
+ isFlushing = false;
4323
+ }
4324
+ }
4325
+ }
4326
+ }
4327
+
4328
+ var createElement$1 = createElementWithValidation ;
4329
+ var cloneElement$1 = cloneElementWithValidation ;
4330
+ var createFactory = createFactoryWithValidation ;
4331
+ var Children = {
4332
+ map: mapChildren,
4333
+ forEach: forEachChildren,
4334
+ count: countChildren,
4335
+ toArray: toArray,
4336
+ only: onlyChild
4337
+ };
4338
+
4339
+ exports.Children = Children;
4340
+ exports.Component = Component;
4341
+ exports.Fragment = REACT_FRAGMENT_TYPE;
4342
+ exports.Profiler = REACT_PROFILER_TYPE;
4343
+ exports.PureComponent = PureComponent;
4344
+ exports.StrictMode = REACT_STRICT_MODE_TYPE;
4345
+ exports.Suspense = REACT_SUSPENSE_TYPE;
4346
+ exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = ReactSharedInternals;
4347
+ exports.cloneElement = cloneElement$1;
4348
+ exports.createContext = createContext;
4349
+ exports.createElement = createElement$1;
4350
+ exports.createFactory = createFactory;
4351
+ exports.createRef = createRef;
4352
+ exports.forwardRef = forwardRef;
4353
+ exports.isValidElement = isValidElement;
4354
+ exports.lazy = lazy;
4355
+ exports.memo = memo;
4356
+ exports.startTransition = startTransition;
4357
+ exports.unstable_act = act;
4358
+ exports.useCallback = useCallback;
4359
+ exports.useContext = useContext;
4360
+ exports.useDebugValue = useDebugValue;
4361
+ exports.useDeferredValue = useDeferredValue;
4362
+ exports.useEffect = useEffect;
4363
+ exports.useId = useId;
4364
+ exports.useImperativeHandle = useImperativeHandle;
4365
+ exports.useInsertionEffect = useInsertionEffect;
4366
+ exports.useLayoutEffect = useLayoutEffect;
4367
+ exports.useMemo = useMemo;
4368
+ exports.useReducer = useReducer;
4369
+ exports.useRef = useRef;
4370
+ exports.useState = useState;
4371
+ exports.useSyncExternalStore = useSyncExternalStore;
4372
+ exports.useTransition = useTransition;
4373
+ exports.version = ReactVersion;
4374
+ /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
4375
+ if (
4376
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
4377
+ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
4378
+ 'function'
4379
+ ) {
4380
+ __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
4381
+ }
4382
+
4383
+ })();
4384
+ }
4385
+ });
4386
+
4387
+ var require$$0 = react_production_min;
4388
+
4389
+ var require$$1 = react_development;
4390
+
4391
+ var react = createCommonjsModule(function (module) {
4392
+
4393
+ if (process.env.NODE_ENV === 'production') {
4394
+ module.exports = require$$0;
4395
+ } else {
4396
+ module.exports = require$$1;
4397
+ }
4398
+ });
4399
+
4400
+ var React = react;
4401
+
4402
+ /**
4403
+ * 创建 {@link LiveReact} 实例,并提供 `React` 技术栈相关工具链。
4404
+ */
4405
+ function createLiveReact(options) {
4406
+ const LiveContext = React.createContext(null);
4407
+ const live = createLive(options);
4408
+ function LiveProvider(props) {
4409
+ return (React.createElement(LiveContext.Provider, { value: props.live || live }, props.children));
4410
+ }
4411
+ function useLiveInstance() {
4412
+ const context = React.useContext(LiveContext);
4413
+ if (!context)
4414
+ throw new Error('LiveProvider never found.');
4415
+ return context;
4416
+ }
4417
+ /**
4418
+ * @deprecated
4419
+ * @returns
4420
+ */
4421
+ function unsafe__useLiveInstance() {
4422
+ return useLiveInstance();
4423
+ }
4424
+ function useRTCInstance() {
4425
+ const live = useLiveInstance();
4426
+ return live.$RTC;
4427
+ }
4428
+ /**
4429
+ * @deprecated
4430
+ * @returns
4431
+ */
4432
+ function unsafe__useRTCInstance() {
4433
+ return useRTCInstance();
4434
+ }
4435
+ function useConnect() {
4436
+ const live = useLiveInstance();
4437
+ return async (options) => await live.connect(options);
4438
+ }
4439
+ function useCurrentWebSocketUrl() {
4440
+ const live = useLiveInstance();
4441
+ const [state, setState] = React.useState(undefined);
4442
+ React.useEffect(() => {
4443
+ const onWSBeforeConnect = () => setState(live.url);
4444
+ live.on('ws.beforeConnect', onWSBeforeConnect);
4445
+ return () => live.off('ws.beforeConnect', onWSBeforeConnect);
4446
+ }, [live]);
4447
+ return state;
4448
+ }
4449
+ function useKeyframeUpdateCallback(name, callback, deps = []) {
4450
+ const live = useLiveInstance();
4451
+ const dependencyList = [live, name, ...deps];
4452
+ const dispose = () => live.keyframes.off(name, callback);
4453
+ React.useEffect(() => {
4454
+ live.keyframes.on(name, callback);
4455
+ return dispose;
4456
+ }, dependencyList);
4457
+ return dispose;
4458
+ }
4459
+ function useLiveAction() {
4460
+ const live = useLiveInstance();
4461
+ const toggleMicro = React.useCallback((microStatus) => live.toggleMicro(microStatus), [live]);
4462
+ const broadcast = React.useCallback((data, toUserIds, timeout = 0) => live.broadcast(data, toUserIds, timeout), [live]);
4463
+ const exit = React.useCallback(() => live.exit(), [live]);
4464
+ const kick = React.useCallback((toUserIds) => live.kick(toUserIds), [live]);
4465
+ const forbidMicro = React.useCallback((micro, toUserIds) => live.forbidMicro(micro, toUserIds), [live]);
4466
+ // const forbidSync = React.useCallback(
4467
+ // (sync: boolean, toUserIds?: string | string[] | undefined) =>
4468
+ // live.forbidSync(sync, toUserIds),
4469
+ // [live],
4470
+ // );
4471
+ const getFramesByKey = React.useCallback((key) => live.getFramesByKey(key), [live]);
4472
+ const sendKeyframe = React.useCallback((key, frame) => live.sendKeyframe(key, frame), [live]);
4473
+ const setSelfInfo = React.useCallback((userInfo) => live.setSelfInfo(userInfo), [live]);
4474
+ const updateStatus = React.useCallback((evtType, atnType, status, toUserIds) => live.updateStatus(evtType, atnType, status, toUserIds), [live]);
4475
+ return {
4476
+ broadcast,
4477
+ exit,
4478
+ kick,
4479
+ toggleMicro,
4480
+ forbidMicro,
4481
+ // forbidSync,
4482
+ sendKeyframe,
4483
+ getFramesByKey,
4484
+ setSelfInfo,
4485
+ updateStatus,
4486
+ };
4487
+ }
4488
+ function useKeyframe(key) {
4489
+ const live = useLiveInstance();
4490
+ const [state, updateState] = React.useState(live.getFramesByKey(key));
4491
+ React.useEffect(() => {
4492
+ const onUpdate = (nextKeyframes) => updateState(nextKeyframes);
4493
+ const evtName = key;
4494
+ const callback = onUpdate;
4495
+ live.keyframes.on(evtName, callback);
4496
+ return () => live.keyframes.off(evtName, callback);
4497
+ }, [live]);
4498
+ const setState = React.useCallback((frame) => live.sendKeyframe(key, frame), [live]);
4499
+ return [state, setState];
4500
+ }
4501
+ function useLiveEventCallback(name, callback, deps = []) {
4502
+ const live = useLiveInstance();
4503
+ const dispose = () => live.off(name, callback);
4504
+ const dependencyList = [live, name, ...deps];
4505
+ React.useEffect(() => {
4506
+ live.on(name, callback);
4507
+ return dispose;
4508
+ }, dependencyList);
4509
+ return dispose;
4510
+ }
4511
+ /**
4512
+ * @deprecated
4513
+ * @returns
4514
+ */
4515
+ function useReadyState() {
4516
+ const live = useLiveInstance();
4517
+ const [state, updateState] = React.useState(live.readyState);
4518
+ React.useEffect(() => {
4519
+ const readyStateUpdate = (readyState) => updateState(readyState);
4520
+ live.on('ws.readyStateUpdate', readyStateUpdate);
4521
+ return () => live.off('ws.readyStateUpdate', readyStateUpdate);
4522
+ }, [live]);
4523
+ return state;
4524
+ }
4525
+ function useRTCAction() {
4526
+ const live = useLiveInstance();
4527
+ const join = React.useCallback((options) => live.$RTC.join(options), [live]);
4528
+ const quit = React.useCallback(() => live.$RTC.quit(), [live]);
4529
+ const shock = React.useCallback(() => { var _a, _b; return (_b = (_a = live.$RTC).shock) === null || _b === void 0 ? void 0 : _b.call(_a); }, [live]);
4530
+ const toggleMicro = React.useCallback((flag) => live.$RTC.toggleMicro(flag), [live]);
4531
+ const detectMicro = React.useCallback(() => live.$RTC.detectMicro(), [live]);
4532
+ return {
4533
+ join,
4534
+ quit,
4535
+ shock,
4536
+ toggleMicro,
4537
+ detectMicro,
4538
+ };
4539
+ }
4540
+ function useRTCEventCallback(name, callback, deps = []) {
4541
+ const live = useLiveInstance();
4542
+ const dispose = () => live.$RTC.off(name, callback);
4543
+ const dependencyList = [live, name, ...deps];
4544
+ React.useEffect(() => {
4545
+ live.$RTC.on(name, callback);
4546
+ return dispose;
4547
+ }, dependencyList);
4548
+ return dispose;
4549
+ }
4550
+ function useSelfInfo() {
4551
+ const live = useLiveInstance();
4552
+ const [state, updateState] = React.useState(live.selfInfo || {});
4553
+ const selfInfoUpdate = (userInfo) => updateState(userInfo);
4554
+ React.useEffect(() => {
4555
+ live.on('selfInfoUpdate', selfInfoUpdate);
4556
+ return () => live.off('selfInfoUpdate', selfInfoUpdate);
4557
+ }, [live]);
4558
+ const setState = React.useCallback(async (userInfo) => {
4559
+ return await live.setSelfInfo(userInfo);
4560
+ }, [live]);
4561
+ return [state, setState];
4562
+ }
4563
+ function useSnapshot() {
4564
+ const live = useLiveInstance();
4565
+ const [state, setState] = React.useState(live.snapshot);
4566
+ React.useEffect(() => {
4567
+ const onKeyframes = (keyframes) => setState(keyframes);
4568
+ live.on('keyframes', onKeyframes);
4569
+ return () => live.off('keyframes', onKeyframes);
4570
+ });
4571
+ return state;
4572
+ }
4573
+ function useUserList() {
4574
+ const live = useLiveInstance();
4575
+ const [state, updateState] = React.useState(live.userList);
4576
+ const userListUpdate = (userList) => updateState(userList);
4577
+ React.useEffect(() => {
4578
+ live.on('userListUpdate', userListUpdate);
4579
+ return () => live.off('userListUpdate', userListUpdate);
4580
+ }, [live]);
4581
+ return state;
4582
+ }
4583
+ /**
4584
+ *
4585
+ * @param name
4586
+ * @param callback
4587
+ * @param deps
4588
+ * @returns
4589
+ * @deprecated
4590
+ */
4591
+ function useWebSocketEventCallback(name, callback, deps = []) {
4592
+ const live = useLiveInstance();
4593
+ const dispose = () => live.off(name, callback);
4594
+ const dependencyList = [live, name, ...deps];
4595
+ React.useEffect(() => {
4596
+ live.on(name, callback);
4597
+ return dispose;
4598
+ }, dependencyList);
4599
+ return dispose;
4600
+ }
4601
+ return {
4602
+ live,
4603
+ LiveProvider,
4604
+ unsafe__useLiveInstance,
4605
+ unsafe__useRTCInstance,
4606
+ useCurrentWebSocketUrl,
4607
+ useConnect,
4608
+ useKeyframe,
4609
+ useKeyframeUpdateCallback,
4610
+ useLiveAction,
4611
+ useLiveEventCallback,
4612
+ useReadyState,
4613
+ useRTCAction,
4614
+ useRTCEventCallback,
4615
+ useSelfInfo,
4616
+ useSnapshot,
4617
+ useUserList,
4618
+ useWebSocketEventCallback,
4619
+ };
4620
+ }
4621
+
4622
+ exports.BrowserRTC = BrowserRTC;
4623
+ exports.BrowserRTC4Chime = BrowserRTC4Chime;
4624
+ exports.CoreRTC = CoreRTC;
4625
+ exports.VRWebViewRTC = VRWebViewRTC;
4626
+ exports.createLive = createLive;
4627
+ exports.createLiveReact = createLiveReact;
4628
+ exports.parseLiveMsg = parseLiveMsg;
4629
+ exports.parseWSClsErr = parseWSClsErr;
4630
+ //# sourceMappingURL=realsee-live.cjs.development.js.map