@polyv/socket 2.1.0-rc-20251023.2 → 2.3.0-rc-20251204.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.es.d.ts CHANGED
@@ -10,10 +10,29 @@ 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
+ * 是否指定场次
24
+ */
25
+ inTargetSession: boolean;
26
+ /**
27
+ * 保利威账号 id
28
+ */
29
+ accountId?: string;
30
+ }
31
+
13
32
  /**
14
33
  * 频道信息
15
34
  */
16
- export declare interface ChannelInfo {
35
+ export declare interface ChannelInfoOptions {
17
36
  /**
18
37
  * 频道号
19
38
  */
@@ -22,12 +41,48 @@ export declare interface ChannelInfo {
22
41
  * 场次号
23
42
  */
24
43
  sessionId?: string;
44
+ /**
45
+ * 是否指定场次
46
+ * @default false
47
+ */
48
+ inTargetSession?: boolean;
25
49
  /**
26
50
  * 保利威账号 id
27
51
  */
28
52
  accountId?: string;
29
53
  }
30
54
 
55
+ declare class ChannelModule extends SocketModuleBase {
56
+ /**
57
+ * 频道号
58
+ */
59
+ private __channelId;
60
+ /**
61
+ * 场次号
62
+ */
63
+ private __sessionId?;
64
+ /**
65
+ * 保利威账号 id
66
+ */
67
+ private __accountId?;
68
+ /**
69
+ * 是否指定场次
70
+ */
71
+ private __inTargetSession;
72
+ /**
73
+ * 讲师信息
74
+ */
75
+ private __teacherInfo?;
76
+ constructor(plvSocket: PolyvSocket);
77
+ private __onTeacherInfo;
78
+ getTeacherInfo(): TeacherInfo | undefined;
79
+ getChannelInfo(): Promise<ChannelInfo>;
80
+ /**
81
+ * 更新场次信息
82
+ */
83
+ updateSession(options: UpdateSessionOptions): void;
84
+ }
85
+
31
86
  /**
32
87
  * 频道令牌数据
33
88
  */
@@ -91,6 +146,77 @@ export declare enum ConnectFailReason {
91
146
  SocketConnectTimeout = "SocketConnectTimeout"
92
147
  }
93
148
 
149
+ declare class ConnectModule extends SocketModuleBase {
150
+ customSocket?: SocketInstance;
151
+ /**
152
+ * 事件存储
153
+ */
154
+ private __eventStore;
155
+ /**
156
+ * Socket 连接实例
157
+ */
158
+ private __socket?;
159
+ constructor(plvSocket: PolyvSocket);
160
+ setup(options: SocketSetupOptions): Promise<void>;
161
+ /**
162
+ * 获取连接令牌
163
+ */
164
+ getToken(): Promise<string | undefined>;
165
+ getSocket(check?: true): SocketInstance;
166
+ getSocket(check: false): SocketInstance | undefined;
167
+ /**
168
+ * 初始化 Socket
169
+ */
170
+ private __initSocket;
171
+ /**
172
+ * 连接 Socket
173
+ */
174
+ private __connectSocket;
175
+ /**
176
+ * 登录聊天室 socket
177
+ */
178
+ private __loginSocket;
179
+ /**
180
+ * 监听 socket 连接事件
181
+ */
182
+ private __bindConnectEvent;
183
+ /**
184
+ * 发送 socket 数据
185
+ * @param socketData socket 数据
186
+ * @param socketType socket 类型,默认:message
187
+ */
188
+ emitSocket<D = unknown>(socketData: unknown, socketType?: SocketEventType, options?: EmitSocketOptions): Promise<D>;
189
+ /**
190
+ * 添加 socket 事件监听
191
+ * @param appName 应用名称
192
+ * @param handlers 消息事件处理对象
193
+ * @param socketType socket 事件类型
194
+ */
195
+ addSocketHandles(appName: EventAppName, handlers: SocketEventStoreHandlers | EventHandler, socketType?: SocketEventType): void;
196
+ /**
197
+ * 清除 socket 事件监听
198
+ * @param appName 应用名称
199
+ */
200
+ clearSocketHandles(appName: EventAppName): void;
201
+ /**
202
+ * 断开 Socket 连接
203
+ */
204
+ disconnect(): Promise<void>;
205
+ }
206
+
207
+ export declare interface EmitSocketOptions {
208
+ /**
209
+ * 是否直接回调参数
210
+ * @default false
211
+ */
212
+ directCallback?: boolean;
213
+ /**
214
+ * 是否检查 code 返回
215
+ * @default true
216
+ */
217
+ checkCode?: boolean;
218
+ }
219
+
94
220
  /** 应用名 */
95
221
  export declare type EventAppName = string;
96
222
 
@@ -100,6 +226,8 @@ export declare type EventHandler = (msg: any) => unknown;
100
226
  /** 事件 key */
101
227
  export declare type EventKey = string;
102
228
 
229
+ export declare const GlobalVariable = "PolyvSocket";
230
+
103
231
  export declare type MaybePromiseFn<R> = () => Promise<R> | R;
104
232
 
105
233
  declare class PolyvApiRequest extends PolyvRequest<PolyvApiRequestOptions> {
@@ -114,10 +242,12 @@ declare class PolyvApiRequest extends PolyvRequest<PolyvApiRequestOptions> {
114
242
  declare interface PolyvApiRequestOptions extends RequestOptions {
115
243
  }
116
244
 
117
- export declare class PolyvSocket extends PolyvSocketBase {
245
+ export declare class PolyvSocket {
118
246
  ConnectFailReason: typeof ConnectFailReason;
119
247
  SocketUserType: typeof SocketUserType;
120
248
  PolyvSocketEvent: typeof PolyvSocketEvent;
249
+ eventEmitter: EventEmitter<PolyvSocketEventRelations, PolyvSocketEvent>;
250
+ config: PolyvSocketConfig;
121
251
  /**
122
252
  * 聊天室 api 请求器
123
253
  */
@@ -126,88 +256,29 @@ export declare class PolyvSocket extends PolyvSocketBase {
126
256
  * 保利威 api 请求器
127
257
  */
128
258
  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
- /**
140
- * 判断是否为特殊的用户身份
141
- *
142
- * 用户模块提供 Api 用于判断用户身份是否为内置的特殊用户身份,如讲师、管理员、助教等。
143
- * @param userType 用户身份
144
- * @param actor 用户头衔
145
- * @returns 是否特殊身份
146
- */
147
- isSpecialUserType(userType: SocketUserType | unknown, actor?: string): boolean;
148
259
  /**
149
- * 判断是否为当前用户
150
- * @param userId 用户 id
260
+ * 连接模块
151
261
  */
152
- isCurrentUser(userId: string): boolean;
153
- }
154
-
155
- /**
156
- * Polyv Socket 基类
157
- */
158
- declare class PolyvSocketBase {
159
- config: PolyvSocketConfig;
160
- eventEmitter: EventEmitter<PolyvSocketEventRelations, PolyvSocketEvent>;
262
+ connect: ConnectModule;
161
263
  /**
162
- * 事件存储
264
+ * 频道模块
163
265
  */
164
- private __eventStore;
266
+ channel: ChannelModule;
165
267
  /**
166
- * Socket 连接实例
268
+ * 埋点
167
269
  */
168
- private __socket?;
270
+ rtas: RtasModule;
169
271
  constructor(config: PolyvSocketConfig);
170
272
  /**
171
- * @hook 连接成功后
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 连接事件
273
+ * 创建并连接 socket
198
274
  */
199
- private __bindConnectEvent;
275
+ setup(options?: SocketSetupOptions): Promise<void>;
200
276
  /**
201
277
  * 发送 socket 数据
202
278
  * @param socketData socket 数据
203
279
  * @param socketType socket 类型,默认:message
204
280
  */
205
- emitSocket<D = unknown>(socketData: unknown, socketType?: SocketEventType, options?: {
206
- /** 是否直接回调参数,默认:false */
207
- directCallback?: boolean;
208
- /** 是否检查 code 返回,默认:true */
209
- checkCode?: boolean;
210
- }): Promise<D>;
281
+ emitSocket<D = unknown>(socketData: unknown, socketType?: SocketEventType, options?: EmitSocketOptions): Promise<D>;
211
282
  /**
212
283
  * 添加 socket 事件监听
213
284
  * @param appName 应用名称
@@ -216,9 +287,30 @@ declare class PolyvSocketBase {
216
287
  */
217
288
  addSocketHandles(appName: EventAppName, handlers: SocketEventStoreHandlers | EventHandler, socketType?: SocketEventType): void;
218
289
  /**
219
- * 断开 Socket 连接
290
+ * 清除 socket 事件监听
291
+ * @param appName 应用名称
220
292
  */
221
- disconnect(): Promise<void>;
293
+ clearSocketHandles(appName: EventAppName): void;
294
+ /**
295
+ * 获取用户信息
296
+ */
297
+ getUserInfo(): UserInfo;
298
+ /**
299
+ * 判断是否为特殊的用户身份
300
+ *
301
+ * 用户模块提供 Api 用于判断用户身份是否为内置的特殊用户身份,如讲师、管理员、助教等。
302
+ * @param userType 用户身份
303
+ * @param actor 用户头衔
304
+ * @returns 是否特殊身份
305
+ */
306
+ isSpecialUserType(userType: SocketUserType | unknown, actor?: string): boolean;
307
+ currentIsSpecialUser(): boolean;
308
+ /**
309
+ * 判断是否为当前用户
310
+ * @param userId 用户 id
311
+ */
312
+ isCurrentUser(userId: string): boolean;
313
+ destroy(): Promise<void>;
222
314
  }
223
315
 
224
316
  /**
@@ -232,11 +324,15 @@ export declare interface PolyvSocketConfig {
232
324
  /**
233
325
  * 频道信息
234
326
  */
235
- channelInfo: ChannelInfo;
327
+ channelInfo: ChannelInfoOptions;
236
328
  /**
237
329
  * 用户信息
238
330
  */
239
331
  userInfo: UserInfo | (() => UserInfo);
332
+ /**
333
+ * 讲师信息
334
+ */
335
+ teacherInfo?: TeacherInfo;
240
336
  /**
241
337
  * 域名信息
242
338
  */
@@ -268,6 +364,10 @@ export declare interface PolyvSocketConfig {
268
364
  * 获取频道令牌信息
269
365
  */
270
366
  getChannelToken?: MaybePromiseFn<ChannelTokenData>;
367
+ /**
368
+ * 埋点上报总开关
369
+ */
370
+ watchEventTrackEnabled?: boolean;
271
371
  /**
272
372
  * 授权方式
273
373
  * @default RequestAuthorizeMethod.Token
@@ -325,7 +425,11 @@ export declare enum PolyvSocketEvent {
325
425
  /**
326
426
  * 登录失败
327
427
  */
328
- LoginFailed = "LoginFailed"
428
+ LoginFailed = "LoginFailed",
429
+ /**
430
+ * 场次信息更新
431
+ */
432
+ SessionUpdate = "SessionUpdate"
329
433
  }
330
434
 
331
435
  export declare type PolyvSocketEventRelations = {
@@ -359,6 +463,17 @@ export declare enum RequestAuthorizeMethod {
359
463
  Sign = "sign"
360
464
  }
361
465
 
466
+ declare class RtasModule extends SocketModuleBase {
467
+ private __rtasSender?;
468
+ constructor(plvSocket: PolyvSocket);
469
+ setup(_setupOptions: SocketSetupOptions): Promise<void>;
470
+ private __init;
471
+ /**
472
+ * 发送事件日志
473
+ */
474
+ trackEvent(data: TrackEventData): Promise<void>;
475
+ }
476
+
362
477
  /**
363
478
  * 安全模式
364
479
  */
@@ -385,7 +500,7 @@ export declare type SocketEventStoreHandlers = {
385
500
  */
386
501
  export declare type SocketEventType = typeof socketEventTypes[number];
387
502
 
388
- export declare const socketEventTypes: readonly ["message", "product", "lottery", "questionnaire", "coupon", "activityLottery", "testQuestion", "emotion", "speak", "customMessage", "motivation"];
503
+ export declare const socketEventTypes: readonly ["message", "product", "lottery", "questionnaire", "coupon", "activityLottery", "testQuestion", "emotion", "speak", "customMessage", "motivation", "fakeLikes"];
389
504
 
390
505
  export declare interface SocketInstance {
391
506
  /** 是否已断开连接 */
@@ -404,6 +519,19 @@ export declare interface SocketInstance {
404
519
  once: (event: string, callback: (...args: any[]) => void) => void;
405
520
  }
406
521
 
522
+ declare class SocketModuleBase {
523
+ protected _plvSocket: PolyvSocket;
524
+ constructor(_plvSocket: PolyvSocket);
525
+ setup(_setupOptions: SocketSetupOptions): Promise<void>;
526
+ }
527
+
528
+ export declare interface SocketSetupOptions {
529
+ /**
530
+ * 自定义 socket 连接实例,如果提供了该实例,则不会自动创建 socket 连接和连接 socket
531
+ */
532
+ customSocket?: SocketInstance;
533
+ }
534
+
407
535
  /**
408
536
  * 用户身份类型枚举
409
537
  */
@@ -472,6 +600,48 @@ export declare interface StatisticsParams {
472
600
  param5?: string;
473
601
  }
474
602
 
603
+ /**
604
+ * 讲师信息
605
+ */
606
+ export declare interface TeacherInfo {
607
+ /**
608
+ * 用户 id
609
+ */
610
+ userId: string;
611
+ /**
612
+ * 用户昵称
613
+ */
614
+ nick: string;
615
+ /**
616
+ * 用户头像
617
+ */
618
+ pic: string;
619
+ /**
620
+ * 头衔
621
+ */
622
+ actor?: string;
623
+ }
624
+
625
+ declare interface TrackEventData {
626
+ /** 事件名 */
627
+ event_id: string;
628
+ /** 事件类型 */
629
+ event_type: string;
630
+ /** 事件属性,不能为空对象 */
631
+ spec_attrs: Record<string, unknown>;
632
+ }
633
+
634
+ declare interface UpdateSessionOptions {
635
+ /**
636
+ * 场次号
637
+ */
638
+ sessionId?: string;
639
+ /**
640
+ * 是否指定场次
641
+ */
642
+ inTargetSession?: boolean;
643
+ }
644
+
475
645
  /**
476
646
  * 用户信息
477
647
  */
@@ -500,6 +670,14 @@ export declare interface UserInfo {
500
670
  * 头衔
501
671
  */
502
672
  actor?: string;
673
+ /**
674
+ * 用户登录方式
675
+ */
676
+ authType?: string;
677
+ /**
678
+ * 分组 id
679
+ */
680
+ groupId?: string;
503
681
  /**
504
682
  * 微信 unionId
505
683
  */