Skip to content

Commit ca9b30f

Browse files
committed
style: re-order methods
1 parent 5352caf commit ca9b30f

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

server.js

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,59 @@ Server.prototype._onWebSocketRequest = function (socket, opts, params) {
575575
})
576576
}
577577

578+
Server.prototype._onWebSocketSend = function (socket, err) {
579+
var self = this
580+
if (err) self._onWebSocketError(socket, err)
581+
}
582+
583+
Server.prototype._onWebSocketClose = function (socket) {
584+
var self = this
585+
debug('websocket close %s', socket.peerId)
586+
587+
if (socket.peerId) {
588+
socket.infoHashes.forEach(function (infoHash) {
589+
var swarm = self.torrents[infoHash]
590+
if (swarm) {
591+
swarm.announce({
592+
type: 'ws',
593+
event: 'stopped',
594+
numwant: 0,
595+
peer_id: socket.peerId
596+
}, noop)
597+
}
598+
})
599+
}
600+
601+
// ignore all future errors
602+
socket.onSend = noop
603+
socket.on('error', noop)
604+
605+
socket.peerId = null
606+
socket.infoHashes = null
607+
608+
if (typeof socket.onMessageBound === 'function') {
609+
socket.removeListener('message', socket.onMessageBound)
610+
}
611+
socket.onMessageBound = null
612+
613+
if (typeof socket.onErrorBound === 'function') {
614+
socket.removeListener('error', socket.onErrorBound)
615+
}
616+
socket.onErrorBound = null
617+
618+
if (typeof socket.onCloseBound === 'function') {
619+
socket.removeListener('close', socket.onCloseBound)
620+
}
621+
socket.onCloseBound = null
622+
}
623+
624+
Server.prototype._onWebSocketError = function (socket, err) {
625+
var self = this
626+
debug('websocket error %s', err.message || err)
627+
self.emit('warning', err)
628+
self._onWebSocketClose(socket)
629+
}
630+
578631
Server.prototype._onRequest = function (params, cb) {
579632
var self = this
580633
if (params && params.action === common.ACTIONS.CONNECT) {
@@ -757,59 +810,6 @@ function makeUdpPacket (params) {
757810
return packet
758811
}
759812

760-
Server.prototype._onWebSocketSend = function (socket, err) {
761-
var self = this
762-
if (err) self._onWebSocketError(socket, err)
763-
}
764-
765-
Server.prototype._onWebSocketClose = function (socket) {
766-
var self = this
767-
debug('websocket close %s', socket.peerId)
768-
769-
if (socket.peerId) {
770-
socket.infoHashes.forEach(function (infoHash) {
771-
var swarm = self.torrents[infoHash]
772-
if (swarm) {
773-
swarm.announce({
774-
type: 'ws',
775-
event: 'stopped',
776-
numwant: 0,
777-
peer_id: socket.peerId
778-
}, noop)
779-
}
780-
})
781-
}
782-
783-
// ignore all future errors
784-
socket.onSend = noop
785-
socket.on('error', noop)
786-
787-
socket.peerId = null
788-
socket.infoHashes = null
789-
790-
if (typeof socket.onMessageBound === 'function') {
791-
socket.removeListener('message', socket.onMessageBound)
792-
}
793-
socket.onMessageBound = null
794-
795-
if (typeof socket.onErrorBound === 'function') {
796-
socket.removeListener('error', socket.onErrorBound)
797-
}
798-
socket.onErrorBound = null
799-
800-
if (typeof socket.onCloseBound === 'function') {
801-
socket.removeListener('close', socket.onCloseBound)
802-
}
803-
socket.onCloseBound = null
804-
}
805-
806-
Server.prototype._onWebSocketError = function (socket, err) {
807-
var self = this
808-
debug('websocket error %s', err.message || err)
809-
self.emit('warning', err)
810-
self._onWebSocketClose(socket)
811-
}
812-
813813
function toNumber (x) {
814814
x = Number(x)
815815
return x >= 0 ? x : false

0 commit comments

Comments
 (0)