Skip to content

Commit dee1c22

Browse files
committed
Act gracefully when a client has aborted at an inconvenient time and
we try to forward an offer to them.
1 parent e6f9989 commit dee1c22

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

server.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,18 @@ Server.prototype._onWebSocketRequest = function (socket, params) {
326326
debug('got offers %s from %s', JSON.stringify(params.offers), params.peer_id)
327327
debug('got %s peers from swarm %s', peers.length, params.info_hash)
328328
peers.forEach(function (peer, i) {
329-
peer.socket.send(JSON.stringify({
330-
offer: params.offers[i].offer,
331-
offer_id: params.offers[i].offer_id,
332-
peer_id: common.hexToBinary(params.peer_id),
333-
info_hash: common.hexToBinary(params.info_hash)
334-
}))
335-
debug('sent offer to %s from %s', peer.peerId, params.peer_id)
329+
var data_for_peer = JSON.stringify({
330+
offer: params.offers[i].offer,
331+
offer_id: params.offers[i].offer_id,
332+
peer_id: common.hexToBinary(params.peer_id),
333+
info_hash: common.hexToBinary(params.info_hash)
334+
})
335+
try {
336+
peer.socket.send(data_for_peer);
337+
debug('sent offer to %s from %s', peer.peerId, params.peer_id)
338+
} catch (ex) {
339+
debug('error sending to peer %s: %s', peer.peerId, ex)
340+
}
336341
})
337342
}
338343

0 commit comments

Comments
 (0)