@esengine/server 4.4.0 → 4.5.0

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.
@@ -14,6 +14,7 @@ interface IPlayer<TData = Record<string, unknown>> {
14
14
  readonly roomId: string;
15
15
  data: TData;
16
16
  send<T>(type: string, data: T): void;
17
+ sendBinary(data: Uint8Array): void;
17
18
  leave(reason?: string): void;
18
19
  }
19
20
  /**
@@ -26,12 +27,14 @@ declare class Player<TData = Record<string, unknown>> implements IPlayer<TData>
26
27
  data: TData;
27
28
  private _conn;
28
29
  private _sendFn;
30
+ private _sendBinaryFn?;
29
31
  private _leaveFn;
30
32
  constructor(options: {
31
33
  id: string;
32
34
  roomId: string;
33
35
  conn: Connection<any>;
34
36
  sendFn: (conn: Connection<any>, type: string, data: unknown) => void;
37
+ sendBinaryFn?: (conn: Connection<any>, data: Uint8Array) => void;
35
38
  leaveFn: (player: Player<TData>, reason?: string) => void;
36
39
  initialData?: TData;
37
40
  });
@@ -45,6 +48,19 @@ declare class Player<TData = Record<string, unknown>> implements IPlayer<TData>
45
48
  * @en Send message to player
46
49
  */
47
50
  send<T>(type: string, data: T): void;
51
+ /**
52
+ * @zh 发送二进制数据给玩家
53
+ * @en Send binary data to player
54
+ *
55
+ * @zh 如果底层连接支持原生二进制帧,则直接发送;否则降级为 base64 编码通过 JSON 发送
56
+ * @en If underlying connection supports native binary frames, sends directly; otherwise falls back to base64 encoding via JSON
57
+ */
58
+ sendBinary(data: Uint8Array): void;
59
+ /**
60
+ * @zh 将 Uint8Array 转换为 base64 字符串
61
+ * @en Convert Uint8Array to base64 string
62
+ */
63
+ private _toBase64;
48
64
  /**
49
65
  * @zh 让玩家离开房间
50
66
  * @en Make player leave the room
@@ -114,6 +130,7 @@ declare abstract class Room<TState = any, TPlayerData = Record<string, unknown>>
114
130
  private _lastTickTime;
115
131
  private _broadcastFn;
116
132
  private _sendFn;
133
+ private _sendBinaryFn;
117
134
  private _disposeFn;
118
135
  /**
119
136
  * @zh 房间 ID
@@ -211,6 +228,7 @@ declare abstract class Room<TState = any, TPlayerData = Record<string, unknown>>
211
228
  _init(options: {
212
229
  id: string;
213
230
  sendFn: (conn: any, type: string, data: unknown) => void;
231
+ sendBinaryFn?: (conn: any, data: Uint8Array) => void;
214
232
  broadcastFn: (type: string, data: unknown) => void;
215
233
  disposeFn: () => void;
216
234
  }): void;
@@ -1,7 +1,7 @@
1
- import { I as IAuthContext, A as AuthResult, a as IAuthProvider, b as AuthServerConfig, c as AuthGameServer, d as AuthRoomConfig, R as RequireAuthOptions, e as RequireRoleOptions } from '../types-C7sS8Sfi.js';
2
- export { i as AuthApiContext, h as AuthConnection, g as AuthConnectionData, f as AuthErrorCode, j as AuthMsgContext, C as ConnectionRequest } from '../types-C7sS8Sfi.js';
3
- import { G as GameServer, c as ServerConnection } from '../index-lcuKuQsL.js';
4
- import { R as Room, P as Player } from '../Room-BnKpl5Sj.js';
1
+ import { a as IAuthContext, A as AuthResult, I as IAuthProvider, b as AuthServerConfig, c as AuthGameServer, d as AuthRoomConfig, R as RequireAuthOptions, e as RequireRoleOptions } from '../types-BCTRacMF.js';
2
+ export { i as AuthApiContext, h as AuthConnection, g as AuthConnectionData, f as AuthErrorCode, j as AuthMsgContext, C as ConnectionRequest } from '../types-BCTRacMF.js';
3
+ import { G as GameServer, S as ServerConnection } from '../index-B1sr5YAl.js';
4
+ import { R as Room, P as Player } from '../Room-5owFVIFR.js';
5
5
  import '@esengine/rpc';
6
6
  import 'node:http';
7
7
 
@@ -1,5 +1,5 @@
1
- import { a as IAuthProvider, A as AuthResult } from '../../types-C7sS8Sfi.js';
2
- import '../../index-lcuKuQsL.js';
1
+ import { I as IAuthProvider, A as AuthResult } from '../../types-BCTRacMF.js';
2
+ import '../../index-B1sr5YAl.js';
3
3
  import '@esengine/rpc';
4
4
  import 'node:http';
5
5