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

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.
@@ -5,4 +5,4 @@ import { Live } from './live';
5
5
  * @param opts
6
6
  * @returns
7
7
  */
8
- export declare const createLive: <KeyframesSnapshot>(opts: LiveOptions) => Live<KeyframesSnapshot>;
8
+ export declare const createLive: <KeyframesSnapshot extends Record<string, any>>(opts: LiveOptions) => Live<KeyframesSnapshot>;
@@ -2,25 +2,25 @@ import React from 'react';
2
2
  import { BuiltinActionType, BuiltinEventType, KeyframeTypes, LiveConnectOptions, LiveEventType, LiveOptions, MicroStatus, RTCEventType, RTCType, UserInfo } from '../typings';
3
3
  import { LiveState } from '../typings/live/LiveState';
4
4
  import { Live } from './live';
5
- export declare type LiveProviderPropTypes<KeyframesSnapshot> = {
5
+ export declare type LiveProviderPropTypes<KeyframesSnapshot extends Record<string, any>> = {
6
6
  children?: React.ReactNode;
7
7
  live?: Live<KeyframesSnapshot>;
8
8
  };
9
9
  /**
10
10
  * 创建 {@link LiveReact} 实例,并提供 `React` 技术栈相关工具链。
11
11
  */
12
- export declare function createLiveReact<KeyframesSnapshot>(options: LiveOptions): {
12
+ export declare function createLiveReact<KeyframesSnapshot extends Record<string, any>>(options: LiveOptions): {
13
13
  live: Live<KeyframesSnapshot>;
14
14
  jsBridge: import("@realsee/jsbridge-x").JSBridgeProtocol;
15
15
  LiveProvider: (props: LiveProviderPropTypes<KeyframesSnapshot>) => JSX.Element;
16
16
  unsafe__useLiveInstance: () => Live<KeyframesSnapshot>;
17
17
  unsafe__useRTCInstance: () => import("../typings").RTCProtocol;
18
- useConnect: (options: LiveConnectOptions) => Promise<boolean | Error>;
18
+ useConnect: () => (options: LiveConnectOptions) => Promise<boolean | Error>;
19
19
  useKeyframe: <K extends keyof KeyframesSnapshot>(key: K) => [frame: KeyframesSnapshot[K] | undefined, setFrame: (frame: KeyframesSnapshot[K]) => boolean | Error];
20
20
  useKeyframeUpdateCallback: <KeyOfKeyframe extends keyof KeyframeTypes<KeyframesSnapshot>>(key: KeyOfKeyframe, callback: (...args: Parameters<KeyframeTypes<KeyframesSnapshot>[KeyOfKeyframe]>) => ReturnType<KeyframeTypes<KeyframesSnapshot>[KeyOfKeyframe]>, deps?: React.DependencyList) => () => void;
21
21
  useLiveAction: () => {
22
22
  connect: (options: LiveConnectOptions) => Promise<boolean | Error>;
23
- broadcast: (data: Record<string, any>, toUserIds: string | string[], timeout?: any) => Promise<unknown>;
23
+ broadcast: (data: Record<string, any>, toUserIds: string | string[], timeout?: number) => Promise<unknown>;
24
24
  exit: () => Promise<boolean>;
25
25
  kick: (toUserIds: string | string[]) => Promise<boolean>;
26
26
  toggleMicro: (microStatus: boolean) => Promise<boolean>;
@@ -145,7 +145,7 @@ export declare class Live<KeyframesSnapshot extends Record<string, any>> extends
145
145
  * @param timeout
146
146
  * @returns
147
147
  */
148
- broadcast<Request, Response>(request: Request, toUserIds: string | string[], timeout: number): Promise<Response> | Error | false;
148
+ broadcast<Request extends Record<string, any>, Response>(request: Request, toUserIds: string | string[], timeout: number): Promise<Response> | Error | false;
149
149
  toggleMicro: (microStatus: boolean) => Promise<boolean>;
150
150
  /**
151
151
  * 控制别人的麦
@@ -204,6 +204,7 @@ class BrowserRTC extends CoreRTC {
204
204
  this._getVoiceSign = () => {
205
205
  throw new Error('方法 getVoiceSign 未实现');
206
206
  };
207
+ this.checkRequirement = () => TRTC__default["default"].checkSystemRequirements();
207
208
  this.$dom = document.createElement('div');
208
209
  this._trtc = {
209
210
  client: null,
@@ -318,9 +319,10 @@ class BrowserRTC extends CoreRTC {
318
319
  var _a, _b, _c, _d;
319
320
  (_a = this._trtc.client) === null || _a === void 0 ? void 0 : _a.on('stream-added', this._handleStreamAdded);
320
321
  (_b = this._trtc.client) === null || _b === void 0 ? void 0 : _b.on('stream-subscribed', this._handleStreamSubscribed);
321
- (_c = this._trtc.client) === null || _c === void 0 ? void 0 : _c.on('audio-volume', (event) => this.emit('userVolumes', [
322
- { userId: event.userId, audioVolume: event.audioVolume },
323
- ]));
322
+ (_c = this._trtc.client) === null || _c === void 0 ? void 0 : _c.on('audio-volume', (event) => this.emit('userVolumes', event.result.map(({ userId, audioVolume }) => ({
323
+ userId,
324
+ audioVolume,
325
+ }))));
324
326
  (_d = this._trtc.client) === null || _d === void 0 ? void 0 : _d.on('error', (event) => this.emit('error', event));
325
327
  }
326
328
  }
@@ -1715,7 +1717,7 @@ class Live extends Subscribe {
1715
1717
  this._handleMessage = (liveMsg) => __awaiter(this, void 0, void 0, function* () {
1716
1718
  var _b, _c, _d, _e, _f, _g;
1717
1719
  if (typeof liveMsg === 'object') {
1718
- const { command, data, frontRequestId, code, message } = liveMsg;
1720
+ const { command, data = {}, frontRequestId, code, message } = liveMsg;
1719
1721
  if (code === 'SUCCESS') {
1720
1722
  switch (command) {
1721
1723
  /**
@@ -1885,8 +1887,8 @@ class Live extends Subscribe {
1885
1887
  }
1886
1888
  const { force = false } = options;
1887
1889
  // 检测一下麦克风权限,hack
1888
- if (this._options.rtc && this._options.jsBridge) {
1889
- const res = yield this._options.jsBridge.detectMicro();
1890
+ if (this._options.rtc) {
1891
+ const res = yield this._options.rtc.detectMicro();
1890
1892
  if (!res) {
1891
1893
  return new Error('Failed to obtain microphone authorization');
1892
1894
  }
@@ -2265,21 +2267,21 @@ function createLiveReact(options) {
2265
2267
  * @deprecated
2266
2268
  * @returns
2267
2269
  */
2268
- const unsafe__useLiveInstance = React.useCallback(() => useLiveInstance(), [useLiveInstance]);
2270
+ const unsafe__useLiveInstance = () => live;
2269
2271
  /**
2270
2272
  * 使用rtc实例
2271
2273
  */
2272
- const useRTCInstance = React.useCallback(() => useLiveInstance().$RTC, [useLiveInstance]);
2274
+ const useRTCInstance = () => live.$RTC;
2273
2275
  /**
2274
2276
  * 不建议这样使用
2275
2277
  * @deprecated
2276
2278
  * @returns
2277
2279
  */
2278
- const unsafe__useRTCInstance = React.useCallback(() => useRTCInstance(), [useRTCInstance]);
2280
+ const unsafe__useRTCInstance = () => useRTCInstance();
2279
2281
  /**
2280
2282
  * 带看连接操作
2281
2283
  */
2282
- const useConnect = React.useCallback((options) => __awaiter(this, void 0, void 0, function* () { return yield useLiveInstance().connect(options); }), []);
2284
+ const useConnect = () => (options) => __awaiter(this, void 0, void 0, function* () { return yield live.connect(options); });
2283
2285
  /**
2284
2286
  *
2285
2287
  * @param name
@@ -2303,17 +2305,17 @@ function createLiveReact(options) {
2303
2305
  */
2304
2306
  function useLiveAction() {
2305
2307
  const live = useLiveInstance();
2306
- const connect = React__default["default"].useCallback((options) => __awaiter(this, void 0, void 0, function* () { return yield live.connect(options); }), [live]);
2307
- const toggleMicro = React__default["default"].useCallback((microStatus) => live.toggleMicro(microStatus), [live]);
2308
- const broadcast = React__default["default"].useCallback((data, toUserIds, timeout = 0) => __awaiter(this, void 0, void 0, function* () { return yield live.broadcast(data, toUserIds, timeout); }), [live]);
2309
- const exit = React__default["default"].useCallback(() => __awaiter(this, void 0, void 0, function* () { return yield live.exit(); }), [live]);
2310
- const kick = React__default["default"].useCallback((toUserIds) => __awaiter(this, void 0, void 0, function* () { return yield live.kick(toUserIds); }), [live]);
2311
- const forbidMicro = React__default["default"].useCallback((micro, toUserIds = []) => __awaiter(this, void 0, void 0, function* () { return yield live.forbidMicro(micro, toUserIds); }), [live]);
2312
- const forbidSync = React__default["default"].useCallback((sync, toUserIds = []) => live.forbidSync(sync, toUserIds), [live]);
2313
- const getFramesByKey = React__default["default"].useCallback((key) => live.getFramesByKey(key), [live]);
2314
- const sendKeyframe = React__default["default"].useCallback((key, frame) => live.sendKeyframe(key, frame), [live]);
2315
- const setSelfInfo = React__default["default"].useCallback((userInfo) => live.setSelfInfo(userInfo), [live]);
2316
- const updateStatus = React__default["default"].useCallback((evtType, atnType, status, toUserIds) => live.updateStatus(evtType, atnType, status, toUserIds), [live]);
2308
+ const connect = (options) => __awaiter(this, void 0, void 0, function* () { return yield live.connect(options); });
2309
+ const toggleMicro = (microStatus) => live.toggleMicro(microStatus);
2310
+ const broadcast = (data, toUserIds, timeout = 0) => __awaiter(this, void 0, void 0, function* () { return yield live.broadcast(data, toUserIds, timeout); });
2311
+ const exit = () => __awaiter(this, void 0, void 0, function* () { return yield live.exit(); });
2312
+ const kick = (toUserIds) => __awaiter(this, void 0, void 0, function* () { return yield live.kick(toUserIds); });
2313
+ const forbidMicro = (micro, toUserIds = []) => __awaiter(this, void 0, void 0, function* () { return yield live.forbidMicro(micro, toUserIds); });
2314
+ const forbidSync = (sync, toUserIds = []) => live.forbidSync(sync, toUserIds);
2315
+ const getFramesByKey = (key) => live.getFramesByKey(key);
2316
+ const sendKeyframe = (key, frame) => live.sendKeyframe(key, frame);
2317
+ const setSelfInfo = (userInfo) => live.setSelfInfo(userInfo);
2318
+ const updateStatus = (evtType, atnType, status, toUserIds) => live.updateStatus(evtType, atnType, status, toUserIds);
2317
2319
  return {
2318
2320
  connect,
2319
2321
  broadcast,
@@ -2367,11 +2369,11 @@ function createLiveReact(options) {
2367
2369
  }
2368
2370
  function useRTCAction() {
2369
2371
  const live = useLiveInstance();
2370
- const join = React__default["default"].useCallback((options) => live.$RTC.join(options), [live]);
2371
- const quit = React__default["default"].useCallback(() => live.$RTC.quit(), [live]);
2372
- const shock = React__default["default"].useCallback(() => { var _a, _b; return (_b = (_a = live.$RTC).shock) === null || _b === void 0 ? void 0 : _b.call(_a); }, [live]);
2373
- const toggleMicro = React__default["default"].useCallback((flag) => live.$RTC.toggleMicro(flag), [live]);
2374
- const detectMicro = React__default["default"].useCallback(() => live.$RTC.detectMicro(), [live]);
2372
+ const join = (options) => live.$RTC.join(options);
2373
+ const quit = () => live.$RTC.quit();
2374
+ const shock = () => { var _a, _b; return (_b = (_a = live.$RTC).shock) === null || _b === void 0 ? void 0 : _b.call(_a); };
2375
+ const toggleMicro = (flag) => live.$RTC.toggleMicro(flag);
2376
+ const detectMicro = () => live.$RTC.detectMicro();
2375
2377
  return {
2376
2378
  join,
2377
2379
  quit,