@netifyjs/protocol 1.0.0-alpha.3 → 1.0.0-beta.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.
Files changed (175) hide show
  1. package/package.json +2 -2
  2. package/src/codec/index.ts +51 -221
  3. package/src/dispatch/dispatcher/index.ts +89 -47
  4. package/src/dispatch/session/index.ts +6 -24
  5. package/src/index.ts +2 -4
  6. package/src/photon/balancing/codec/index.ts +27 -53
  7. package/src/photon/balancing/format/authenticate/request/index.ts +52 -6
  8. package/src/photon/balancing/format/friends/request/index.ts +21 -5
  9. package/src/photon/balancing/format/game/create/request/index.ts +45 -8
  10. package/src/photon/balancing/format/game/debug/request/index.ts +19 -4
  11. package/src/photon/balancing/format/game/join/request/index.ts +65 -13
  12. package/src/photon/balancing/format/game/list/request/index.ts +29 -3
  13. package/src/photon/balancing/format/game/random/request/index.ts +58 -10
  14. package/src/photon/balancing/format/groups/request/index.ts +19 -3
  15. package/src/photon/balancing/format/index.ts +7 -0
  16. package/src/photon/balancing/format/leave/request/index.ts +19 -3
  17. package/src/photon/balancing/format/lobby/join/request/index.ts +23 -3
  18. package/src/photon/balancing/format/lobby/stats/request/index.ts +19 -3
  19. package/src/photon/balancing/format/once/request/index.ts +31 -8
  20. package/src/photon/balancing/format/properties/get/request/index.ts +31 -4
  21. package/src/photon/balancing/format/properties/set/request/index.ts +36 -7
  22. package/src/photon/balancing/format/raise/request/index.ts +76 -10
  23. package/src/photon/balancing/format/reader/index.ts +75 -6
  24. package/src/photon/balancing/format/regions/request/index.ts +16 -1
  25. package/src/photon/balancing/format/rpc/request/index.ts +26 -3
  26. package/src/photon/balancing/format/settings/request/index.ts +15 -2
  27. package/src/photon/balancing/format/shared/credentials/index.ts +77 -33
  28. package/src/photon/balancing/format/shared/lobby/index.ts +41 -5
  29. package/src/photon/balancing/format/shared/options/index.ts +56 -24
  30. package/src/photon/balancing/format/table/index.ts +399 -0
  31. package/src/photon/balancing/index.ts +11 -1
  32. package/src/photon/balancing/travel/index.ts +15 -12
  33. package/src/photon/client/connection/index.ts +6 -6
  34. package/src/photon/cluster/back/index.ts +32 -45
  35. package/src/photon/cluster/dresser/index.ts +7 -8
  36. package/src/photon/cluster/front/index.ts +25 -49
  37. package/src/photon/cluster/grid/index.ts +1 -1
  38. package/src/photon/cluster/mover/index.ts +12 -12
  39. package/src/photon/cluster/press/index.ts +2 -18
  40. package/src/photon/cluster/route/game/index.ts +9 -11
  41. package/src/photon/cluster/route/master/index.ts +15 -34
  42. package/src/photon/cluster/route/name/index.ts +4 -21
  43. package/src/photon/cluster/seat/game/index.ts +6 -26
  44. package/src/photon/cluster/seat/master/index.ts +1 -1
  45. package/src/photon/cluster/sessions/index.ts +5 -6
  46. package/src/photon/cluster/spread/index.ts +8 -147
  47. package/src/photon/enet/client/index.ts +1 -8
  48. package/src/photon/enet/gateway/index.ts +5 -15
  49. package/src/photon/enet/index.ts +1 -1
  50. package/src/photon/enet/link/index.ts +34 -15
  51. package/src/photon/enet/outbound/index.ts +279 -0
  52. package/src/photon/enet/peer/index.ts +59 -0
  53. package/src/photon/enet/transport/index.ts +8 -24
  54. package/src/photon/game/admission/index.ts +353 -0
  55. package/src/photon/game/bag/index.ts +13 -0
  56. package/src/photon/game/broadcast/index.ts +79 -0
  57. package/src/photon/game/editor/index.ts +446 -0
  58. package/src/photon/game/gate/index.ts +9 -8
  59. package/src/photon/game/handler/index.ts +30 -3
  60. package/src/photon/game/history/index.ts +234 -0
  61. package/src/photon/game/hooked/index.ts +16 -15
  62. package/src/photon/game/index.ts +12 -1
  63. package/src/photon/game/lifecycle/index.ts +193 -0
  64. package/src/photon/game/peer/index.ts +1 -10
  65. package/src/photon/game/properties/index.ts +342 -0
  66. package/src/photon/game/room/index.ts +435 -1793
  67. package/src/photon/game/rooms/index.ts +2 -1
  68. package/src/photon/game/seats/index.ts +237 -0
  69. package/src/photon/game/server/index.ts +12 -2
  70. package/src/photon/game/services/index.ts +41 -0
  71. package/src/photon/game/settings/index.ts +22 -0
  72. package/src/photon/game/snapshot/index.ts +133 -0
  73. package/src/photon/game/throttle/index.ts +60 -0
  74. package/src/photon/game/touch/index.ts +2 -5
  75. package/src/photon/game/venue/index.ts +31 -0
  76. package/src/photon/master/application/index.ts +7 -0
  77. package/src/photon/master/gate/index.ts +12 -8
  78. package/src/photon/master/handler/index.ts +36 -748
  79. package/src/photon/master/index.ts +5 -0
  80. package/src/photon/master/list/sql/index.ts +37 -3
  81. package/src/photon/master/listing/index.ts +133 -0
  82. package/src/photon/master/lobby/index.ts +9 -0
  83. package/src/photon/master/login/index.ts +424 -0
  84. package/src/photon/master/matchmaking/index.ts +282 -0
  85. package/src/photon/master/query/index.ts +45 -0
  86. package/src/photon/master/redirect/index.ts +8 -7
  87. package/src/photon/master/services/index.ts +35 -0
  88. package/src/photon/master/settings/index.ts +44 -0
  89. package/src/photon/master/sql/cost/index.ts +263 -0
  90. package/src/photon/master/sql/index.ts +1 -0
  91. package/src/photon/message/client/index.ts +14 -11
  92. package/src/photon/message/handler/index.ts +22 -64
  93. package/src/photon/message/pipeline/index.ts +12 -12
  94. package/src/photon/message/server/index.ts +87 -43
  95. package/src/photon/message/watch/index.ts +14 -37
  96. package/src/photon/server/deferral/index.ts +57 -0
  97. package/src/photon/server/host/index.ts +32 -10
  98. package/src/photon/server/index.ts +1 -0
  99. package/src/photon/tcp/client/index.ts +1 -1
  100. package/src/photon/tcp/codec/index.ts +13 -42
  101. package/src/photon/tcp/server/index.ts +4 -4
  102. package/src/photon/websocket/bridge/index.ts +16 -20
  103. package/src/photon/websocket/message/index.ts +27 -39
  104. package/src/photon/websocket/path/index.ts +2 -5
  105. package/src/scale/fanout/index.ts +6 -6
  106. package/src/scale/index.ts +2 -4
  107. package/src/scale/outbound/index.ts +192 -0
  108. package/src/scale/relay/index.ts +20 -31
  109. package/src/scale/sink/index.ts +6 -11
  110. package/src/scale/transport/index.ts +27 -44
  111. package/src/scale/tunnel/index.ts +37 -91
  112. package/src/smartfox/common/bluebox/gateway/index.ts +401 -0
  113. package/src/smartfox/common/bluebox/index.ts +4 -0
  114. package/src/smartfox/{x2 → common}/bluebox/transport/index.ts +36 -23
  115. package/src/smartfox/common/index.ts +5 -0
  116. package/src/smartfox/common/strikes/index.ts +74 -0
  117. package/src/smartfox/pro/bluebox/index.ts +176 -4
  118. package/src/smartfox/pro/codec/index.ts +8 -7
  119. package/src/smartfox/pro/escalation/index.ts +28 -20
  120. package/src/smartfox/pro/flood/index.ts +2 -2
  121. package/src/smartfox/pro/format/extension/raw/index.ts +12 -2
  122. package/src/smartfox/pro/handler/chat/index.ts +11 -8
  123. package/src/smartfox/pro/handler/login/index.ts +2 -25
  124. package/src/smartfox/pro/handler/shared/index.ts +4 -3
  125. package/src/smartfox/pro/index.ts +11 -5
  126. package/src/smartfox/pro/login/gate/index.ts +166 -0
  127. package/src/smartfox/pro/login/index.ts +1 -0
  128. package/src/smartfox/pro/moderation/index.ts +220 -0
  129. package/src/smartfox/pro/options/index.ts +5 -5
  130. package/src/smartfox/pro/protocol/index.ts +62 -8
  131. package/src/smartfox/pro/web/index.ts +33 -26
  132. package/src/smartfox/pro/zone/index.ts +59 -282
  133. package/src/smartfox/pro/zones/index.ts +3 -3
  134. package/src/smartfox/x2/bluebox/index.ts +149 -4
  135. package/src/smartfox/x2/chat/index.ts +9 -19
  136. package/src/smartfox/x2/codec/index.ts +31 -39
  137. package/src/smartfox/x2/config/index.ts +6 -1
  138. package/src/smartfox/x2/data/array/index.ts +96 -60
  139. package/src/smartfox/x2/data/object/index.ts +144 -82
  140. package/src/smartfox/x2/data/serializer/index.ts +41 -23
  141. package/src/smartfox/x2/flood/gate/index.ts +19 -13
  142. package/src/smartfox/x2/format/buddy/init/response/index.ts +4 -3
  143. package/src/smartfox/x2/format/find/rooms/response/index.ts +4 -3
  144. package/src/smartfox/x2/format/find/users/response/index.ts +4 -3
  145. package/src/smartfox/x2/format/group/subscribe/response/index.ts +4 -3
  146. package/src/smartfox/x2/format/login/response/index.ts +4 -3
  147. package/src/smartfox/x2/format/mmo/position/response/index.ts +8 -6
  148. package/src/smartfox/x2/format/room/join/response/index.ts +4 -3
  149. package/src/smartfox/x2/games/index.ts +35 -8
  150. package/src/smartfox/x2/hall/index.ts +0 -6
  151. package/src/smartfox/x2/handler/session/index.ts +1 -1
  152. package/src/smartfox/x2/index.ts +8 -3
  153. package/src/smartfox/x2/member/index.ts +10 -3
  154. package/src/smartfox/x2/packet/login/response/index.ts +12 -0
  155. package/src/smartfox/x2/protocol/index.ts +11 -1
  156. package/src/smartfox/x2/rooms/index.ts +1 -2
  157. package/src/smartfox/x2/sessions/index.ts +6 -0
  158. package/src/smartfox/x2/udp/index.ts +61 -24
  159. package/src/smartfox/x2/web/index.ts +35 -17
  160. package/src/smartfox/x2/websocket/index.ts +18 -36
  161. package/src/smartfox/x2/zone/index.ts +77 -28
  162. package/src/smartfox/x2/zones/index.ts +17 -5
  163. package/src/photon/enet/handler/index.ts +0 -65
  164. package/src/scale/hosted/index.ts +0 -68
  165. package/src/scale/outlet/index.ts +0 -121
  166. package/src/smartfox/pro/bluebox/gateway/index.ts +0 -310
  167. package/src/smartfox/pro/bluebox/session/index.ts +0 -63
  168. package/src/smartfox/pro/bluebox/transport/index.ts +0 -104
  169. package/src/smartfox/x2/bluebox/gateway/index.ts +0 -315
  170. /package/src/smartfox/{x2 → common}/bluebox/session/index.ts +0 -0
  171. /package/src/smartfox/{pro → common}/counters/index.ts +0 -0
  172. /package/src/smartfox/{pro → common}/counters/memory/index.ts +0 -0
  173. /package/src/smartfox/{pro → common}/counters/offender/index.ts +0 -0
  174. /package/src/smartfox/{pro → common}/counters/store/index.ts +0 -0
  175. /package/src/smartfox/{pro → common}/sequence/index.ts +0 -0
@@ -1,310 +0,0 @@
1
- import {
2
- AttributeKey,
3
- Channel,
4
- type ChannelSetup,
5
- type ShardLink,
6
- } from '@netifyjs/netify'
7
-
8
- import { Courier } from '../../../../scale/courier/index.ts'
9
- import { Switchboard } from '../../../../scale/switchboard/index.ts'
10
-
11
- import { SmartFoxPro } from '../../protocol/index.ts'
12
- import { BlueBoxSession } from '../session/index.ts'
13
- import { BlueBoxTransport } from '../transport/index.ts'
14
-
15
- /**
16
- * How the HTTP tunnel is set up
17
- */
18
- export type BlueBoxOptions = {
19
- /**
20
- * Builds the pipeline of each tunnelled connection
21
- */
22
- readonly setup: ChannelSetup
23
-
24
- /**
25
- * Quiet time before a session is dropped, 30000 ms by default
26
- */
27
- readonly timeout?: number
28
-
29
- /**
30
- * What crossdomain.xml answers, null to switch it off
31
- */
32
- readonly policy?: string | null
33
-
34
- /**
35
- * Connects the server's shards
36
- */
37
- readonly link?: ShardLink | null
38
-
39
- /**
40
- * Goes in front of the link topics the tunnel uses
41
- */
42
- readonly topic?: string
43
- }
44
-
45
- /**
46
- * A client's request as it travels to the shard that holds its session
47
- */
48
- type Forwarded = {
49
- /**
50
- * The form field's value
51
- */
52
- readonly request: string
53
-
54
- /**
55
- * Where the request came from
56
- */
57
- readonly address: string
58
-
59
- /**
60
- * Port the request came from
61
- */
62
- readonly port: number
63
- }
64
-
65
- /**
66
- * Lets clients that can't open a socket talk over HTTP requests
67
- * @class
68
- */
69
- export class BlueBox {
70
- /**
71
- * Goes in front of the link topics the tunnel uses by default
72
- */
73
- public static readonly topic: string = 'netify:protocol:smartfox:bluebox'
74
-
75
- /**
76
- * Marks a connection that's tunnelled over HTTP
77
- */
78
- private static readonly tunnelled: AttributeKey<boolean> =
79
- new AttributeKey<boolean>('netify:protocol:smartfox:bluebox')
80
-
81
- /**
82
- * Path the client posts to
83
- */
84
- public static readonly path: string = '/BlueBox/HttpBox.do'
85
-
86
- /**
87
- * Form field the client puts its request in
88
- */
89
- public static readonly field: string = 'sfsHttp'
90
-
91
- /**
92
- * What a client with no session is told
93
- */
94
- public static readonly lost: string = 'ERR#01'
95
-
96
- /**
97
- * What a poll with nothing waiting is told
98
- */
99
- public static readonly idle: string = 'ok'
100
-
101
- /**
102
- * Length of a session id
103
- */
104
- private static readonly idLength: number = 32
105
-
106
- /**
107
- * What crossdomain.xml answers, or null
108
- */
109
- public readonly policy: string | null
110
-
111
- /**
112
- * Builds the pipeline of each tunnelled connection
113
- */
114
- private readonly setup: ChannelSetup
115
-
116
- /**
117
- * Quiet time before a session is dropped, in ms
118
- */
119
- private readonly timeout: number
120
-
121
- /**
122
- * Open sessions by id
123
- */
124
- private readonly sessions: Map<string, BlueBoxSession>
125
-
126
- /**
127
- * Turns client text into bytes
128
- */
129
- private readonly encoder: TextEncoder
130
-
131
- /**
132
- * Looks for quiet sessions
133
- */
134
- private readonly sweeper: Timer
135
-
136
- /**
137
- * Finds the shard that holds a session
138
- */
139
- private readonly switchboard: Switchboard<Forwarded, string>
140
-
141
- /**
142
- * @param options how the tunnel is set up
143
- */
144
- private constructor(options: BlueBoxOptions) {
145
- const timeout = options.timeout ?? 30_000
146
- if (!(timeout > 0)) throw new RangeError('Timeout is invalid')
147
-
148
- this.policy =
149
- options.policy === undefined ? SmartFoxPro.defaultPolicy : options.policy
150
- this.setup = options.setup
151
- this.timeout = timeout
152
- this.sessions = new Map<string, BlueBoxSession>()
153
- this.switchboard = Switchboard.of<Forwarded, string>(
154
- options.link ?? null,
155
- options.topic ?? BlueBox.topic,
156
- (forwarded: Forwarded): Promise<string> =>
157
- this.handle(forwarded.request, forwarded.address, forwarded.port),
158
- )
159
- this.encoder = new TextEncoder()
160
- this.sweeper = setInterval(
161
- (): void => {
162
- void this.sweep()
163
- },
164
- Math.max(10, timeout / 4),
165
- )
166
- this.sweeper.unref()
167
- }
168
-
169
- /**
170
- * A tunnel with no sessions
171
- * @param options how the tunnel is set up
172
- */
173
- public static of(options: BlueBoxOptions): BlueBox {
174
- return new BlueBox(options)
175
- }
176
-
177
- /**
178
- * Whether a connection is tunnelled over HTTP
179
- * @param channel the connection handlers see
180
- */
181
- public static carries(channel: Channel): boolean {
182
- return channel.attributes.get<boolean>(BlueBox.tunnelled) === true
183
- }
184
-
185
- /**
186
- * How many sessions are open
187
- */
188
- public get size(): number {
189
- return this.sessions.size
190
- }
191
-
192
- /**
193
- * Answers one request from a client
194
- * @param request the form field's value
195
- * @param address where the request came from
196
- * @param port port the request came from
197
- * @param now current time in ms
198
- */
199
- public async handle(
200
- request: string,
201
- address: string,
202
- port: number,
203
- now: number = performance.now(),
204
- ): Promise<string> {
205
- if (request === 'connect') return this.connect(address, port, now)
206
-
207
- const id = request.slice(0, BlueBox.idLength)
208
- const elsewhere = this.switchboard.route(id, { request, address, port })
209
- if (elsewhere !== null) return this.relayed(elsewhere)
210
-
211
- const session = this.sessions.get(id)
212
- if (session === undefined) return BlueBox.lost
213
-
214
- session.seen = now
215
-
216
- const message = request.slice(BlueBox.idLength)
217
- switch (message) {
218
- case 'poll':
219
- return this.poll(session)
220
- case 'disconnect':
221
- await this.drop(session)
222
- return ''
223
- default:
224
- await session.channel.handleData(this.encoder.encode(`${message}\0`))
225
- return ''
226
- }
227
- }
228
-
229
- /**
230
- * Drops every session and stops looking for quiet ones
231
- */
232
- public async shutdown(): Promise<void> {
233
- clearInterval(this.sweeper)
234
- this.switchboard.close()
235
-
236
- for (const session of [...this.sessions.values()]) {
237
- await this.drop(session)
238
- }
239
- }
240
-
241
- /**
242
- * Opens a session and tells the client its id
243
- * @param address where the request came from
244
- * @param port port the request came from
245
- * @param now current time in ms
246
- */
247
- private async connect(
248
- address: string,
249
- port: number,
250
- now: number,
251
- ): Promise<string> {
252
- const id = this.switchboard.mint()
253
- const transport = new BlueBoxTransport(address, port)
254
- const channel = new Channel(transport)
255
- channel.attributes.set<boolean>(BlueBox.tunnelled, true)
256
-
257
- this.sessions.set(id, BlueBoxSession.of(id, channel, transport, now))
258
- await channel.activate(this.setup)
259
-
260
- return `#${id}`
261
- }
262
-
263
- /**
264
- * The answer of the shard that holds a session
265
- * @param answer what that shard is asked
266
- */
267
- private async relayed(answer: Promise<string>): Promise<string> {
268
- try {
269
- return await answer
270
- } catch (cause) {
271
- if (cause instanceof Error && cause.message === Courier.down) {
272
- return BlueBox.lost
273
- }
274
-
275
- throw new Error('Tunnel request failed', { cause })
276
- }
277
- }
278
-
279
- /**
280
- * Hands a client everything that's waiting for it
281
- * @param session who's polling
282
- */
283
- private async poll(session: BlueBoxSession): Promise<string> {
284
- const waiting = session.transport.drain()
285
- if (waiting.length > 0) return waiting
286
- if (!session.transport.ended) return BlueBox.idle
287
-
288
- await this.drop(session)
289
- return BlueBox.lost
290
- }
291
-
292
- /**
293
- * Closes a session's connection and forgets it
294
- * @param session what to drop
295
- */
296
- private async drop(session: BlueBoxSession): Promise<void> {
297
- this.sessions.delete(session.id)
298
- await session.channel.handleClose()
299
- }
300
-
301
- /**
302
- * Drops sessions that stopped polling
303
- * @param now current time in ms
304
- */
305
- private async sweep(now: number = performance.now()): Promise<void> {
306
- for (const session of [...this.sessions.values()]) {
307
- if (now - session.seen >= this.timeout) await this.drop(session)
308
- }
309
- }
310
- }
@@ -1,63 +0,0 @@
1
- import type { Channel } from '@netifyjs/netify'
2
-
3
- import type { BlueBoxTransport } from '../transport/index.ts'
4
-
5
- /**
6
- * One client tunnelled over HTTP
7
- * @class
8
- */
9
- export class BlueBoxSession {
10
- /**
11
- * The 32 characters the client sends with every request
12
- */
13
- public readonly id: string
14
-
15
- /**
16
- * The connection handlers see
17
- */
18
- public readonly channel: Channel
19
-
20
- /**
21
- * Where replies wait for a poll
22
- */
23
- public readonly transport: BlueBoxTransport
24
-
25
- /**
26
- * Time of the client's last request in ms
27
- */
28
- public seen: number
29
-
30
- /**
31
- * @param id the 32 characters the client sends with every request
32
- * @param channel the connection handlers see
33
- * @param transport where replies wait for a poll
34
- * @param seen time of the client's first request in ms
35
- */
36
- private constructor(
37
- id: string,
38
- channel: Channel,
39
- transport: BlueBoxTransport,
40
- seen: number,
41
- ) {
42
- this.id = id
43
- this.channel = channel
44
- this.transport = transport
45
- this.seen = seen
46
- }
47
-
48
- /**
49
- * A session that was just opened
50
- * @param id the 32 characters the client sends with every request
51
- * @param channel the connection handlers see
52
- * @param transport where replies wait for a poll
53
- * @param seen time of the client's first request in ms
54
- */
55
- public static of(
56
- id: string,
57
- channel: Channel,
58
- transport: BlueBoxTransport,
59
- seen: number,
60
- ): BlueBoxSession {
61
- return new BlueBoxSession(id, channel, transport, seen)
62
- }
63
- }
@@ -1,104 +0,0 @@
1
- import type { Transport } from '@netifyjs/netify'
2
-
3
- /**
4
- * Holds what a tunnelled connection is sent until its client polls
5
- * @class
6
- */
7
- export class BlueBoxTransport implements Transport {
8
- /**
9
- * Never a datagram socket
10
- */
11
- public readonly datagram: boolean = false
12
-
13
- /**
14
- * Where the client's first request came from
15
- */
16
- public readonly remoteAddress: string
17
-
18
- /**
19
- * Port the client's first request came from
20
- */
21
- public readonly remotePort: number
22
-
23
- /**
24
- * Whether the server hung up
25
- */
26
- public ended: boolean
27
-
28
- /**
29
- * Whether the server asked for reads to stop
30
- */
31
- public paused: boolean
32
-
33
- /**
34
- * Turns queued bytes into text
35
- */
36
- private readonly decoder: TextDecoder
37
-
38
- /**
39
- * Bytes written since the last poll
40
- */
41
- private pending: Uint8Array[]
42
-
43
- /**
44
- * @param remoteAddress where the client's first request came from
45
- * @param remotePort port the client's first request came from
46
- */
47
- public constructor(remoteAddress: string, remotePort: number) {
48
- this.remoteAddress = remoteAddress
49
- this.remotePort = remotePort
50
- this.ended = false
51
- this.paused = false
52
- this.decoder = new TextDecoder()
53
- this.pending = []
54
- }
55
-
56
- /**
57
- * Queues bytes for the next poll
58
- * @param bytes zero terminated messages
59
- */
60
- public write(bytes: Uint8Array): number {
61
- if (this.ended) return -1
62
-
63
- this.pending.push(bytes.slice())
64
- return bytes.length
65
- }
66
-
67
- /**
68
- * Notes that the server hung up
69
- */
70
- public end(): void {
71
- this.ended = true
72
- }
73
-
74
- /**
75
- * Notes that the server asked for reads to stop
76
- */
77
- public pause(): void {
78
- this.paused = true
79
- }
80
-
81
- /**
82
- * Notes that the server takes reads again
83
- */
84
- public resume(): void {
85
- this.paused = false
86
- }
87
-
88
- /**
89
- * Every whole message queued so far, one per line
90
- */
91
- public drain(): string {
92
- if (this.pending.length === 0) return ''
93
-
94
- const bytes = Buffer.concat(this.pending)
95
- const end = bytes.lastIndexOf(0)
96
- if (end === -1) return ''
97
-
98
- this.pending = end + 1 < bytes.length ? [bytes.subarray(end + 1)] : []
99
-
100
- return this.decoder
101
- .decode(bytes.subarray(0, end + 1))
102
- .replaceAll('\0', '\n')
103
- }
104
- }