@realsee/live 0.4.0-beta.6 → 0.5.0-alpha.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.
@@ -1,43 +1,80 @@
1
- import { Live } from '../typings/live/Live';
2
- import { LiveMsg } from '../typings/live/LiveMsg';
3
- import { LiveOptions } from '../typings/live/LiveOptions';
4
- import { RoomInfo } from '../typings/live/RoomInfo';
5
- import { UserInfo } from '../typings/live/UserInfo';
6
- import { WebSocketState } from '../typings/live/WebSocket';
7
- export declare class LiveController<Snapshot extends Record<string, any>> {
8
- readyState: WebSocketState;
9
- options: LiveOptions;
10
- healthCheckId?: number;
11
- canSync: boolean;
12
- webSocket?: WebSocket;
13
- connecting: boolean;
14
- selfUserInfo?: UserInfo;
15
- userList?: UserInfo[];
16
- roomInfo?: RoomInfo;
17
- keyframes: Partial<Snapshot>;
18
- constructor(options: LiveOptions);
19
- /**
20
- * 检测 WebSocket.readyState 状态
21
- */
22
- checkReadyState: (live: Live<Snapshot>) => WebSocketState;
23
- onEvtOpnListener?: (evt: Event) => void;
24
- onEvtMsgListener?: (evt: MessageEvent) => void;
25
- onEvtErrListener?: (evt: Event) => void;
26
- onEvtCLEListener?: (evt: CloseEvent) => void;
27
- dispose: () => boolean;
28
- /**
29
- * 销毁WebSocket相关依赖。
30
- */
31
- disposeWebSocket: () => true | undefined;
32
- /**
33
- * 解析数据
34
- * @param liveMsg
35
- * @param live
36
- */
37
- handleMessage(liveMsg: LiveMsg, live: Live<Snapshot>): void;
1
+ import { LiveMsg } from '../typings';
2
+ import { LiveState } from '../typings/live/LiveState';
3
+ import { Subscribe } from '../utils/subscribe';
4
+ export declare type LiveControllerEventMap = {
5
+ stateChange: (state: LiveState, prevState: LiveState) => void;
6
+ message: (message: LiveMsg) => void;
7
+ };
8
+ export declare class LiveController extends Subscribe<LiveControllerEventMap> {
9
+ /**
10
+ * ws代理器
11
+ */
12
+ private _ws;
13
+ /**
14
+ * 带看连接状态
15
+ */
16
+ private _state;
17
+ set state(state: LiveState);
18
+ get state(): LiveState;
19
+ constructor();
20
+ /**
21
+ * 添加事件监听
22
+ */
23
+ private _addWebSocketEventListeners;
24
+ /**
25
+ * 移除事件监听
26
+ */
27
+ private _removeWebSocketEventListeners;
28
+ /**
29
+ * 处理房间关闭事件
30
+ * @param event
31
+ */
32
+ private _handleCloseEvent;
33
+ /**
34
+ * 连接中
35
+ * @param event
36
+ */
37
+ private _handleConnectingEvent;
38
+ /**
39
+ * 连接发送异常
40
+ * @param event
41
+ */
42
+ private _handleErrorEvent;
43
+ /**
44
+ * 接收到消息
45
+ * @param event
46
+ */
47
+ private _handleMessageEvent;
48
+ /**
49
+ * 连接建立成功
50
+ * @param event
51
+ */
52
+ private _handleOpenEvent;
53
+ /**
54
+ * 处理超时
55
+ * @param event
56
+ */
57
+ private _handleTimeoutEvent;
58
+ /**
59
+ * 释放资源,释放之后需要重新实例化
60
+ * @returns
61
+ */
62
+ dispose: () => Promise<boolean>;
63
+ /**
64
+ * 开启房间链接
65
+ * @param url 房间链接
66
+ * @returns
67
+ */
68
+ open: (url: string) => void;
69
+ /**
70
+ * 关闭房间
71
+ * @param code
72
+ * @param reason
73
+ */
74
+ close: (code?: string | number | undefined, reason?: string | undefined) => Promise<boolean>;
38
75
  /**
39
76
  * 发送数据
40
77
  * @param data
41
78
  */
42
- sendMessage(data: Record<string, any>): void;
79
+ sendMessage(data?: any): void | undefined;
43
80
  }
@@ -1,6 +1,8 @@
1
- import { Live } from '../typings/live/Live';
2
1
  import { LiveOptions } from '../typings/live/LiveOptions';
2
+ import { Live } from './live';
3
3
  /**
4
- * 创建 `live` 实例。
4
+ * 创建`Live`实例
5
+ * @param opts
6
+ * @returns
5
7
  */
6
- export declare function createLive<Snapshot>(options: LiveOptions): Live<Snapshot>;
8
+ export declare const createLive: <KeyframesSnapshot>(opts: LiveOptions) => Live<KeyframesSnapshot>;
@@ -1,6 +1,52 @@
1
- import { LiveOptions } from '../typings/live/LiveOptions';
2
- import { LiveReact } from '../typings/react';
1
+ import React from 'react';
2
+ import { BuiltinActionType, BuiltinEventType, KeyframeTypes, LiveConnectOptions, LiveEventType, LiveOptions, MicroStatus, RTCEventType, RTCType, UserInfo } from '../typings';
3
+ import { LiveState } from '../typings/live/LiveState';
4
+ import { Live } from './live';
5
+ export declare type LiveProviderPropTypes<KeyframesSnapshot> = {
6
+ children?: React.ReactNode;
7
+ live?: Live<KeyframesSnapshot>;
8
+ };
3
9
  /**
4
10
  * 创建 {@link LiveReact} 实例,并提供 `React` 技术栈相关工具链。
5
11
  */
6
- export declare function createLiveReact<Snapshot>(options: LiveOptions): LiveReact<Snapshot>;
12
+ export declare function createLiveReact<KeyframesSnapshot>(options: LiveOptions): {
13
+ live: Live<KeyframesSnapshot>;
14
+ jsBridge: import("@realsee/jsbridge-x").JSBridgeProtocol;
15
+ LiveProvider: (props: LiveProviderPropTypes<KeyframesSnapshot>) => JSX.Element;
16
+ unsafe__useLiveInstance: () => Live<KeyframesSnapshot>;
17
+ unsafe__useRTCInstance: () => import("../typings").RTCProtocol;
18
+ useConnect: (options: LiveConnectOptions) => Promise<boolean | Error>;
19
+ useKeyframe: <K extends keyof KeyframesSnapshot>(key: K) => [frame: KeyframesSnapshot[K] | undefined, setFrame: (frame: KeyframesSnapshot[K]) => boolean | Error];
20
+ useKeyframeUpdateCallback: <KeyOfKeyframe extends keyof KeyframeTypes<KeyframesSnapshot>>(key: KeyOfKeyframe, callback: (...args: Parameters<KeyframeTypes<KeyframesSnapshot>[KeyOfKeyframe]>) => ReturnType<KeyframeTypes<KeyframesSnapshot>[KeyOfKeyframe]>, deps?: React.DependencyList) => () => void;
21
+ useLiveAction: () => {
22
+ connect: (options: LiveConnectOptions) => Promise<boolean | Error>;
23
+ broadcast: (data: Record<string, any>, toUserIds: string | string[], timeout?: any) => Promise<unknown>;
24
+ exit: () => Promise<boolean>;
25
+ kick: (toUserIds: string | string[]) => Promise<boolean>;
26
+ toggleMicro: (microStatus: boolean) => Promise<boolean>;
27
+ forbidMicro: (micro: MicroStatus, toUserIds?: string | string[]) => Promise<boolean>;
28
+ forbidSync: (sync: boolean, toUserIds?: string | string[]) => Promise<boolean>;
29
+ sendKeyframe: (key: keyof KeyframesSnapshot, frame: KeyframesSnapshot[keyof KeyframesSnapshot]) => boolean | Error;
30
+ getFramesByKey: (key: keyof KeyframesSnapshot) => Partial<KeyframesSnapshot>[keyof KeyframesSnapshot] | undefined;
31
+ setSelfInfo: (userInfo: Partial<UserInfo>) => Promise<boolean>;
32
+ updateStatus: (evtType: BuiltinEventType, atnType: BuiltinActionType, status: Record<string, any>, toUserIds?: string | string[]) => Promise<boolean>;
33
+ };
34
+ useLiveEventCallback: <K_1 extends keyof LiveEventType<KeyframesSnapshot>>(name: K_1, callback: (...args: Parameters<LiveEventType<KeyframesSnapshot>[K_1]>) => ReturnType<LiveEventType<KeyframesSnapshot>[K_1]>, deps?: React.DependencyList) => () => void;
35
+ useLiveState: () => LiveState;
36
+ useRTCAction: () => {
37
+ join: (options: {
38
+ voiceId: string;
39
+ userId: string;
40
+ roomId: string;
41
+ type: RTCType;
42
+ }) => Promise<boolean>;
43
+ quit: () => Promise<boolean>;
44
+ shock: () => void | undefined;
45
+ toggleMicro: (flag?: boolean | undefined) => Promise<boolean>;
46
+ detectMicro: () => Promise<boolean>;
47
+ };
48
+ useRTCEventCallback: <K_2 extends keyof RTCEventType>(name: K_2, callback: (...args: Parameters<RTCEventType[K_2]>) => ReturnType<RTCEventType[K_2]>, deps?: React.DependencyList) => () => void;
49
+ useSelfInfo: () => [Partial<UserInfo>, (userInfo: Partial<UserInfo>) => Promise<boolean | Error>];
50
+ useKeyframesSnapshot: () => Partial<KeyframesSnapshot>;
51
+ useUserList: () => UserInfo[];
52
+ };
@@ -0,0 +1,162 @@
1
+ import { JSBridgeProtocol } from '@realsee/jsbridge-x';
2
+ import { RTCProtocol } from '../rtc';
3
+ import { EventType, KeyframeTypes, LiveOptions, RoomInfo, UserInfo, BuiltinEventType, BuiltinActionType, MicroStatus, LiveConnectOptions } from '../typings';
4
+ import { LiveState } from '../typings/live/LiveState';
5
+ import { Subscribe } from '../utils/subscribe';
6
+ export declare type LiveBuiltInData<KeyframesSnapshot> = {
7
+ selfInfo?: UserInfo;
8
+ userList?: UserInfo[];
9
+ roomInfo?: RoomInfo;
10
+ keyframes: Partial<KeyframesSnapshot>;
11
+ };
12
+ export declare const _clearLiveInstanceIfNeed: () => void;
13
+ export declare class Live<KeyframesSnapshot extends Record<string, any>> extends Subscribe<EventType<KeyframesSnapshot>> {
14
+ /**
15
+ * 带看的配置
16
+ */
17
+ private _options;
18
+ get options(): LiveOptions;
19
+ /**
20
+ * 带看状态
21
+ */
22
+ get state(): LiveState;
23
+ /**
24
+ * 兼容老逻辑
25
+ * @deprecated 请直接读取 state 属性字段,未来将移除该属性
26
+ */
27
+ get readyState(): LiveState;
28
+ /**
29
+ * 获取当前WebSocket连接的URL。(注意:这个是WebSocket连接的完整连接,附带一些query参数)。
30
+ * @deprecated 带看不需要关注底层ws的相关信息,未来将移除
31
+ */
32
+ get url(): string | undefined;
33
+ /**
34
+ * 获取当前live使用的RTC实例
35
+ */
36
+ get $RTC(): RTCProtocol;
37
+ /**
38
+ * 获取当前live使用的jsBridge实例
39
+ */
40
+ get jsBridge(): JSBridgeProtocol;
41
+ /**
42
+ * 帧数据监听
43
+ */
44
+ keyframes: Subscribe<KeyframeTypes<KeyframesSnapshot>>;
45
+ /**
46
+ * 内置的一些数据
47
+ */
48
+ private _buildInData;
49
+ /**
50
+ * 当前帧数据快照
51
+ */
52
+ get snapshot(): Partial<KeyframesSnapshot>;
53
+ /**
54
+ * 根据键值取帧数据
55
+ * @param key 帧数据的键值
56
+ * @returns
57
+ */
58
+ getFramesByKey: <Key extends keyof KeyframesSnapshot>(key: Key) => Partial<KeyframesSnapshot>[Key] | undefined;
59
+ /**
60
+ * 发送帧数据(需要能够被序列化)
61
+ * @param key 帧数据键值
62
+ * @param frame 帧数据本体
63
+ * @returns
64
+ */
65
+ sendKeyframe: <Key extends keyof KeyframesSnapshot>(key: Key, frame: KeyframesSnapshot[Key]) => boolean | Error;
66
+ /**
67
+ * 当前用户信息
68
+ */
69
+ get selfInfo(): UserInfo | undefined;
70
+ /**
71
+ * 当前用户列表
72
+ */
73
+ get userList(): UserInfo[];
74
+ /**
75
+ * 当前带看房间信息
76
+ */
77
+ get roomInfo(): RoomInfo | undefined;
78
+ /**
79
+ * 带看控制器
80
+ */
81
+ private _controller;
82
+ constructor(opts: LiveOptions);
83
+ /**
84
+ * 添加带看控制的事件监听
85
+ */
86
+ private _addLiveControllerEventListeners;
87
+ /**
88
+ * 移除带看控制的事件监听
89
+ */
90
+ private _removeLiveControllerEventListeners;
91
+ /**
92
+ * 带看状态变化
93
+ * @param state
94
+ * @returns
95
+ */
96
+ private _handleStateChange;
97
+ private _handleMessage;
98
+ /**
99
+ * 清理带看缓存的数据
100
+ */
101
+ private _clearLiveData;
102
+ /**
103
+ * 连接带看
104
+ * @param options
105
+ * @returns
106
+ */
107
+ connect: (options?: LiveConnectOptions) => Promise<boolean | Error>;
108
+ /**
109
+ * 退出带看
110
+ * @returns
111
+ */
112
+ exit: () => Promise<boolean>;
113
+ /**
114
+ * 销毁带看
115
+ * @returns
116
+ */
117
+ dispose: () => Promise<boolean>;
118
+ /**
119
+ * 修改状态
120
+ * @param evtType
121
+ * @param atnType
122
+ * @param status
123
+ * @param toUserIds
124
+ * @returns
125
+ */
126
+ updateStatus(evtType: BuiltinEventType, atnType: BuiltinActionType, status: Record<string, any>, toUserIds?: string | string[]): Promise<boolean>;
127
+ /**
128
+ * 设置自己的用户信息
129
+ * @param userInfo
130
+ * @returns
131
+ */
132
+ setSelfInfo: (userInfo: Partial<UserInfo>) => Promise<boolean>;
133
+ /**
134
+ * 自定义广播
135
+ * @param request 广播请求的数据
136
+ * @param toUserIds
137
+ * @param timeout
138
+ * @returns
139
+ */
140
+ broadcast<Request, Response>(request: Request, toUserIds: string | string[], timeout: number): Promise<Response> | Error | false;
141
+ toggleMicro: (microStatus: boolean) => Promise<boolean>;
142
+ /**
143
+ * 控制别人的麦
144
+ * @param microStatus
145
+ * @param toUserIds
146
+ * @returns
147
+ */
148
+ forbidMicro: (microStatus: MicroStatus, toUserIds: string | string[]) => Promise<boolean>;
149
+ /**
150
+ * 控制别人的同步全量帧数据权限
151
+ * @param sync
152
+ * @param toUserIds
153
+ * @returns
154
+ */
155
+ forbidSync: (sync: boolean, toUserIds: string | string[]) => Promise<boolean>;
156
+ /**
157
+ * 把用户踢出带看
158
+ * @param toUserIds
159
+ * @returns
160
+ */
161
+ kick: (toUserIds: string | string[]) => Promise<boolean>;
162
+ }