Skip to content

Commit 9713553

Browse files
committed
safer send
1 parent f58ecc6 commit 9713553

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

server/socket.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,7 @@ export class PlayerSocket{
172172
this.arena.add(blob)
173173
}
174174
}
175-
send({buffer}, i, critical = true){
176-
if(this.ws._socket._writableState.buffered.length){
177-
//can't reuse buffer; must clone
178-
if(!critical)return //skip
179-
const b = Buffer.alloc(i)
180-
b.set(new Uint8Array(buffer, 0, i), 0)
181-
this.ws.send(b)
182-
}else this.ws.send(new Uint8Array(buffer, 0, i))
183-
}
175+
send({buffer}, i){ this.ws.send(buffer.slice(0, i)) }
184176
[Symbol.for('nodejs.util.inspect.custom')](){
185177
return this.cells.size ? 'Player(\x1b[33m'+this.cells.size+'\x1b[m) [...]' : 'Player []'
186178
}

0 commit comments

Comments
 (0)