@polyv/socket 2.1.0-rc-20251023.1 → 2.2.0-rc-20251113.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.
- package/index.cjs.js +12 -6
- package/index.es.d.ts +196 -75
- package/index.es.js +10052 -5369
- package/index.umd.js +12 -6
- package/package.json +3 -2
package/index.es.d.ts
CHANGED
|
@@ -10,10 +10,25 @@ import { SM2Key } from '@polyv/request-plugin-sm2';
|
|
|
10
10
|
|
|
11
11
|
export { AuthorizeAppSignRequestOptions }
|
|
12
12
|
|
|
13
|
+
declare interface ChannelInfo {
|
|
14
|
+
/**
|
|
15
|
+
* 频道号
|
|
16
|
+
*/
|
|
17
|
+
channelId: string;
|
|
18
|
+
/**
|
|
19
|
+
* 场次号
|
|
20
|
+
*/
|
|
21
|
+
sessionId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* 保利威账号 id
|
|
24
|
+
*/
|
|
25
|
+
accountId?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
13
28
|
/**
|
|
14
29
|
* 频道信息
|
|
15
30
|
*/
|
|
16
|
-
export declare interface
|
|
31
|
+
export declare interface ChannelInfoOptions {
|
|
17
32
|
/**
|
|
18
33
|
* 频道号
|
|
19
34
|
*/
|
|
@@ -28,6 +43,27 @@ export declare interface ChannelInfo {
|
|
|
28
43
|
accountId?: string;
|
|
29
44
|
}
|
|
30
45
|
|
|
46
|
+
declare class ChannelModule extends SocketModuleBase {
|
|
47
|
+
/**
|
|
48
|
+
* 频道号
|
|
49
|
+
*/
|
|
50
|
+
private __channelId;
|
|
51
|
+
/**
|
|
52
|
+
* 场次号
|
|
53
|
+
*/
|
|
54
|
+
private __sessionId?;
|
|
55
|
+
/**
|
|
56
|
+
* 保利威账号 id
|
|
57
|
+
*/
|
|
58
|
+
private __accountId?;
|
|
59
|
+
constructor(plvSocket: PolyvSocket);
|
|
60
|
+
getChannelInfo(): Promise<ChannelInfo>;
|
|
61
|
+
/**
|
|
62
|
+
* 更新场次信息
|
|
63
|
+
*/
|
|
64
|
+
updateSession(options: UpdateSessionOptions): void;
|
|
65
|
+
}
|
|
66
|
+
|
|
31
67
|
/**
|
|
32
68
|
* 频道令牌数据
|
|
33
69
|
*/
|
|
@@ -91,6 +127,77 @@ export declare enum ConnectFailReason {
|
|
|
91
127
|
SocketConnectTimeout = "SocketConnectTimeout"
|
|
92
128
|
}
|
|
93
129
|
|
|
130
|
+
declare class ConnectModule extends SocketModuleBase {
|
|
131
|
+
customSocket?: SocketInstance;
|
|
132
|
+
/**
|
|
133
|
+
* 事件存储
|
|
134
|
+
*/
|
|
135
|
+
private __eventStore;
|
|
136
|
+
/**
|
|
137
|
+
* Socket 连接实例
|
|
138
|
+
*/
|
|
139
|
+
private __socket?;
|
|
140
|
+
constructor(plvSocket: PolyvSocket);
|
|
141
|
+
setup(options: SocketSetupOptions): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* 获取连接令牌
|
|
144
|
+
*/
|
|
145
|
+
getToken(): Promise<string | undefined>;
|
|
146
|
+
getSocket(check?: true): SocketInstance;
|
|
147
|
+
getSocket(check: false): SocketInstance | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* 初始化 Socket
|
|
150
|
+
*/
|
|
151
|
+
private __initSocket;
|
|
152
|
+
/**
|
|
153
|
+
* 连接 Socket
|
|
154
|
+
*/
|
|
155
|
+
private __connectSocket;
|
|
156
|
+
/**
|
|
157
|
+
* 登录聊天室 socket
|
|
158
|
+
*/
|
|
159
|
+
private __loginSocket;
|
|
160
|
+
/**
|
|
161
|
+
* 监听 socket 连接事件
|
|
162
|
+
*/
|
|
163
|
+
private __bindConnectEvent;
|
|
164
|
+
/**
|
|
165
|
+
* 发送 socket 数据
|
|
166
|
+
* @param socketData socket 数据
|
|
167
|
+
* @param socketType socket 类型,默认:message
|
|
168
|
+
*/
|
|
169
|
+
emitSocket<D = unknown>(socketData: unknown, socketType?: SocketEventType, options?: EmitSocketOptions): Promise<D>;
|
|
170
|
+
/**
|
|
171
|
+
* 添加 socket 事件监听
|
|
172
|
+
* @param appName 应用名称
|
|
173
|
+
* @param handlers 消息事件处理对象
|
|
174
|
+
* @param socketType socket 事件类型
|
|
175
|
+
*/
|
|
176
|
+
addSocketHandles(appName: EventAppName, handlers: SocketEventStoreHandlers | EventHandler, socketType?: SocketEventType): void;
|
|
177
|
+
/**
|
|
178
|
+
* 清除 socket 事件监听
|
|
179
|
+
* @param appName 应用名称
|
|
180
|
+
*/
|
|
181
|
+
clearSocketHandles(appName: EventAppName): void;
|
|
182
|
+
/**
|
|
183
|
+
* 断开 Socket 连接
|
|
184
|
+
*/
|
|
185
|
+
disconnect(): Promise<void>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export declare interface EmitSocketOptions {
|
|
189
|
+
/**
|
|
190
|
+
* 是否直接回调参数
|
|
191
|
+
* @default false
|
|
192
|
+
*/
|
|
193
|
+
directCallback?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* 是否检查 code 返回
|
|
196
|
+
* @default true
|
|
197
|
+
*/
|
|
198
|
+
checkCode?: boolean;
|
|
199
|
+
}
|
|
200
|
+
|
|
94
201
|
/** 应用名 */
|
|
95
202
|
export declare type EventAppName = string;
|
|
96
203
|
|
|
@@ -100,6 +207,8 @@ export declare type EventHandler = (msg: any) => unknown;
|
|
|
100
207
|
/** 事件 key */
|
|
101
208
|
export declare type EventKey = string;
|
|
102
209
|
|
|
210
|
+
export declare const GlobalVariable = "PolyvSocket";
|
|
211
|
+
|
|
103
212
|
export declare type MaybePromiseFn<R> = () => Promise<R> | R;
|
|
104
213
|
|
|
105
214
|
declare class PolyvApiRequest extends PolyvRequest<PolyvApiRequestOptions> {
|
|
@@ -114,10 +223,12 @@ declare class PolyvApiRequest extends PolyvRequest<PolyvApiRequestOptions> {
|
|
|
114
223
|
declare interface PolyvApiRequestOptions extends RequestOptions {
|
|
115
224
|
}
|
|
116
225
|
|
|
117
|
-
export declare class PolyvSocket
|
|
226
|
+
export declare class PolyvSocket {
|
|
118
227
|
ConnectFailReason: typeof ConnectFailReason;
|
|
119
228
|
SocketUserType: typeof SocketUserType;
|
|
120
229
|
PolyvSocketEvent: typeof PolyvSocketEvent;
|
|
230
|
+
eventEmitter: EventEmitter<PolyvSocketEventRelations, PolyvSocketEvent>;
|
|
231
|
+
config: PolyvSocketConfig;
|
|
121
232
|
/**
|
|
122
233
|
* 聊天室 api 请求器
|
|
123
234
|
*/
|
|
@@ -126,88 +237,29 @@ export declare class PolyvSocket extends PolyvSocketBase {
|
|
|
126
237
|
* 保利威 api 请求器
|
|
127
238
|
*/
|
|
128
239
|
polyvApi: PolyvApiRequest;
|
|
129
|
-
constructor(config: PolyvSocketConfig);
|
|
130
|
-
/**
|
|
131
|
-
* 设置 Socket 连接
|
|
132
|
-
*/
|
|
133
|
-
setup(): Promise<void>;
|
|
134
|
-
protected _afterConnect(): void;
|
|
135
|
-
/**
|
|
136
|
-
* 登录聊天室 socket
|
|
137
|
-
*/
|
|
138
|
-
loginSocket(): Promise<void>;
|
|
139
240
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* 用户模块提供 Api 用于判断用户身份是否为内置的特殊用户身份,如讲师、管理员、助教等。
|
|
143
|
-
* @param userType 用户身份
|
|
144
|
-
* @param actor 用户头衔
|
|
145
|
-
* @returns 是否特殊身份
|
|
241
|
+
* 连接模块
|
|
146
242
|
*/
|
|
147
|
-
|
|
243
|
+
connect: ConnectModule;
|
|
148
244
|
/**
|
|
149
|
-
*
|
|
150
|
-
* @param userId 用户 id
|
|
245
|
+
* 频道模块
|
|
151
246
|
*/
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Polyv Socket 基类
|
|
157
|
-
*/
|
|
158
|
-
declare class PolyvSocketBase {
|
|
159
|
-
config: PolyvSocketConfig;
|
|
160
|
-
eventEmitter: EventEmitter<PolyvSocketEventRelations, PolyvSocketEvent>;
|
|
247
|
+
channel: ChannelModule;
|
|
161
248
|
/**
|
|
162
|
-
*
|
|
163
|
-
*/
|
|
164
|
-
private __eventStore;
|
|
165
|
-
/**
|
|
166
|
-
* Socket 连接实例
|
|
249
|
+
* 埋点
|
|
167
250
|
*/
|
|
168
|
-
|
|
251
|
+
rtas: RtasModule;
|
|
169
252
|
constructor(config: PolyvSocketConfig);
|
|
170
253
|
/**
|
|
171
|
-
*
|
|
172
|
-
*/
|
|
173
|
-
protected _afterConnect(): void;
|
|
174
|
-
/**
|
|
175
|
-
* 获取连接令牌
|
|
176
|
-
*/
|
|
177
|
-
getToken(): Promise<string | undefined>;
|
|
178
|
-
/**
|
|
179
|
-
* 获取频道信息
|
|
180
|
-
*/
|
|
181
|
-
getChannelInfo(): Promise<ChannelInfo>;
|
|
182
|
-
/**
|
|
183
|
-
* 获取用户信息
|
|
184
|
-
*/
|
|
185
|
-
getUserInfo(): UserInfo;
|
|
186
|
-
getSocket(check?: true): SocketInstance;
|
|
187
|
-
getSocket(check: false): SocketInstance | undefined;
|
|
188
|
-
/**
|
|
189
|
-
* 初始化 Socket
|
|
190
|
-
*/
|
|
191
|
-
protected _initSocket(): Promise<void>;
|
|
192
|
-
/**
|
|
193
|
-
* 连接 Socket
|
|
194
|
-
*/
|
|
195
|
-
protected _connectSocket(): Promise<void>;
|
|
196
|
-
/**
|
|
197
|
-
* 监听 socket 连接事件
|
|
254
|
+
* 创建并连接 socket
|
|
198
255
|
*/
|
|
199
|
-
|
|
256
|
+
setup(options?: SocketSetupOptions): Promise<void>;
|
|
200
257
|
/**
|
|
201
258
|
* 发送 socket 数据
|
|
202
259
|
* @param socketData socket 数据
|
|
203
260
|
* @param socketType socket 类型,默认:message
|
|
204
261
|
*/
|
|
205
|
-
emitSocket<D = unknown>(socketData: unknown, socketType?: SocketEventType, options?:
|
|
206
|
-
/** 是否直接回调参数,默认:false */
|
|
207
|
-
directCallback?: boolean;
|
|
208
|
-
/** 是否检查 code 返回,默认:true */
|
|
209
|
-
checkCode?: boolean;
|
|
210
|
-
}): Promise<D>;
|
|
262
|
+
emitSocket<D = unknown>(socketData: unknown, socketType?: SocketEventType, options?: EmitSocketOptions): Promise<D>;
|
|
211
263
|
/**
|
|
212
264
|
* 添加 socket 事件监听
|
|
213
265
|
* @param appName 应用名称
|
|
@@ -216,9 +268,29 @@ declare class PolyvSocketBase {
|
|
|
216
268
|
*/
|
|
217
269
|
addSocketHandles(appName: EventAppName, handlers: SocketEventStoreHandlers | EventHandler, socketType?: SocketEventType): void;
|
|
218
270
|
/**
|
|
219
|
-
*
|
|
271
|
+
* 清除 socket 事件监听
|
|
272
|
+
* @param appName 应用名称
|
|
220
273
|
*/
|
|
221
|
-
|
|
274
|
+
clearSocketHandles(appName: EventAppName): void;
|
|
275
|
+
/**
|
|
276
|
+
* 获取用户信息
|
|
277
|
+
*/
|
|
278
|
+
getUserInfo(): UserInfo;
|
|
279
|
+
/**
|
|
280
|
+
* 判断是否为特殊的用户身份
|
|
281
|
+
*
|
|
282
|
+
* 用户模块提供 Api 用于判断用户身份是否为内置的特殊用户身份,如讲师、管理员、助教等。
|
|
283
|
+
* @param userType 用户身份
|
|
284
|
+
* @param actor 用户头衔
|
|
285
|
+
* @returns 是否特殊身份
|
|
286
|
+
*/
|
|
287
|
+
isSpecialUserType(userType: SocketUserType | unknown, actor?: string): boolean;
|
|
288
|
+
/**
|
|
289
|
+
* 判断是否为当前用户
|
|
290
|
+
* @param userId 用户 id
|
|
291
|
+
*/
|
|
292
|
+
isCurrentUser(userId: string): boolean;
|
|
293
|
+
destroy(): Promise<void>;
|
|
222
294
|
}
|
|
223
295
|
|
|
224
296
|
/**
|
|
@@ -232,7 +304,7 @@ export declare interface PolyvSocketConfig {
|
|
|
232
304
|
/**
|
|
233
305
|
* 频道信息
|
|
234
306
|
*/
|
|
235
|
-
channelInfo:
|
|
307
|
+
channelInfo: ChannelInfoOptions;
|
|
236
308
|
/**
|
|
237
309
|
* 用户信息
|
|
238
310
|
*/
|
|
@@ -268,6 +340,10 @@ export declare interface PolyvSocketConfig {
|
|
|
268
340
|
* 获取频道令牌信息
|
|
269
341
|
*/
|
|
270
342
|
getChannelToken?: MaybePromiseFn<ChannelTokenData>;
|
|
343
|
+
/**
|
|
344
|
+
* 埋点上报总开关
|
|
345
|
+
*/
|
|
346
|
+
watchEventTrackEnabled?: boolean;
|
|
271
347
|
/**
|
|
272
348
|
* 授权方式
|
|
273
349
|
* @default RequestAuthorizeMethod.Token
|
|
@@ -325,7 +401,11 @@ export declare enum PolyvSocketEvent {
|
|
|
325
401
|
/**
|
|
326
402
|
* 登录失败
|
|
327
403
|
*/
|
|
328
|
-
LoginFailed = "LoginFailed"
|
|
404
|
+
LoginFailed = "LoginFailed",
|
|
405
|
+
/**
|
|
406
|
+
* 场次信息更新
|
|
407
|
+
*/
|
|
408
|
+
SessionUpdate = "SessionUpdate"
|
|
329
409
|
}
|
|
330
410
|
|
|
331
411
|
export declare type PolyvSocketEventRelations = {
|
|
@@ -359,6 +439,17 @@ export declare enum RequestAuthorizeMethod {
|
|
|
359
439
|
Sign = "sign"
|
|
360
440
|
}
|
|
361
441
|
|
|
442
|
+
declare class RtasModule extends SocketModuleBase {
|
|
443
|
+
private __rtasSender?;
|
|
444
|
+
constructor(plvSocket: PolyvSocket);
|
|
445
|
+
setup(_setupOptions: SocketSetupOptions): Promise<void>;
|
|
446
|
+
private __init;
|
|
447
|
+
/**
|
|
448
|
+
* 发送事件日志
|
|
449
|
+
*/
|
|
450
|
+
trackEvent(data: TrackEventData): Promise<void>;
|
|
451
|
+
}
|
|
452
|
+
|
|
362
453
|
/**
|
|
363
454
|
* 安全模式
|
|
364
455
|
*/
|
|
@@ -385,7 +476,7 @@ export declare type SocketEventStoreHandlers = {
|
|
|
385
476
|
*/
|
|
386
477
|
export declare type SocketEventType = typeof socketEventTypes[number];
|
|
387
478
|
|
|
388
|
-
export declare const socketEventTypes: readonly ["message", "product", "lottery", "questionnaire", "coupon", "activityLottery", "testQuestion", "emotion", "speak", "customMessage", "motivation"];
|
|
479
|
+
export declare const socketEventTypes: readonly ["message", "product", "lottery", "questionnaire", "coupon", "activityLottery", "testQuestion", "emotion", "speak", "customMessage", "motivation", "fakeLikes"];
|
|
389
480
|
|
|
390
481
|
export declare interface SocketInstance {
|
|
391
482
|
/** 是否已断开连接 */
|
|
@@ -404,6 +495,19 @@ export declare interface SocketInstance {
|
|
|
404
495
|
once: (event: string, callback: (...args: any[]) => void) => void;
|
|
405
496
|
}
|
|
406
497
|
|
|
498
|
+
declare class SocketModuleBase {
|
|
499
|
+
protected _plvSocket: PolyvSocket;
|
|
500
|
+
constructor(_plvSocket: PolyvSocket);
|
|
501
|
+
setup(_setupOptions: SocketSetupOptions): Promise<void>;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export declare interface SocketSetupOptions {
|
|
505
|
+
/**
|
|
506
|
+
* 自定义 socket 连接实例,如果提供了该实例,则不会自动创建 socket 连接和连接 socket
|
|
507
|
+
*/
|
|
508
|
+
customSocket?: SocketInstance;
|
|
509
|
+
}
|
|
510
|
+
|
|
407
511
|
/**
|
|
408
512
|
* 用户身份类型枚举
|
|
409
513
|
*/
|
|
@@ -472,6 +576,19 @@ export declare interface StatisticsParams {
|
|
|
472
576
|
param5?: string;
|
|
473
577
|
}
|
|
474
578
|
|
|
579
|
+
declare interface TrackEventData {
|
|
580
|
+
/** 事件名 */
|
|
581
|
+
event_id: string;
|
|
582
|
+
/** 事件类型 */
|
|
583
|
+
event_type: string;
|
|
584
|
+
/** 事件属性,不能为空对象 */
|
|
585
|
+
spec_attrs: Record<string, unknown>;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
declare interface UpdateSessionOptions {
|
|
589
|
+
sessionId?: string;
|
|
590
|
+
}
|
|
591
|
+
|
|
475
592
|
/**
|
|
476
593
|
* 用户信息
|
|
477
594
|
*/
|
|
@@ -500,6 +617,10 @@ export declare interface UserInfo {
|
|
|
500
617
|
* 头衔
|
|
501
618
|
*/
|
|
502
619
|
actor?: string;
|
|
620
|
+
/**
|
|
621
|
+
* 用户登录方式
|
|
622
|
+
*/
|
|
623
|
+
authType?: string;
|
|
503
624
|
/**
|
|
504
625
|
* 微信 unionId
|
|
505
626
|
*/
|