Skip to content

Commit 48c1264

Browse files
authored
check for server.clients undefined (#144)
1 parent 84e51c4 commit 48c1264

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ function fastifyWebsocket (fastify, opts, next) {
148148
oldClose.call(this, cb)
149149

150150
const server = fastify.websocketServer
151+
if (!server.clients) return
151152
for (const client of server.clients) {
152153
client.close()
153154
}

test/base.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,30 @@ test('Should be able to pass a custom server option to websocket-stream', (t) =>
280280
})
281281
})
282282

283+
test('Should be able to pass clientTracking option in false to websocket-stream', (t) => {
284+
t.plan(2)
285+
286+
const fastify = Fastify()
287+
288+
const options = {
289+
clientTracking: false
290+
}
291+
292+
fastify.register(fastifyWebsocket, { options })
293+
294+
fastify.get('/*', { websocket: true }, (connection, request) => {
295+
connection.destroy()
296+
})
297+
298+
fastify.listen(0, (err) => {
299+
t.error(err)
300+
301+
fastify.close(err => {
302+
t.error(err)
303+
})
304+
})
305+
})
306+
283307
test('Should gracefully close with a connected client', (t) => {
284308
t.plan(6)
285309

0 commit comments

Comments
 (0)