mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 12:11:36 +00:00
feat(events): Support of paused
client event (#411)
* feat: Added `paused` client event * fix(events): fixed 'invalid event' response on 'paused' request from client * fix(styles): fixed extra semicolon
This commit is contained in:
parent
a048097ab4
commit
ef76b3f3b6
@ -11,18 +11,20 @@ exports.REMOVE_IPV4_MAPPED_IPV6_RE = /^::ffff:/
|
||||
|
||||
exports.CONNECTION_ID = Buffer.concat([toUInt32(0x417), toUInt32(0x27101980)])
|
||||
exports.ACTIONS = { CONNECT: 0, ANNOUNCE: 1, SCRAPE: 2, ERROR: 3 }
|
||||
exports.EVENTS = { update: 0, completed: 1, started: 2, stopped: 3 }
|
||||
exports.EVENTS = { update: 0, completed: 1, started: 2, stopped: 3, paused: 4 }
|
||||
exports.EVENT_IDS = {
|
||||
0: 'update',
|
||||
1: 'completed',
|
||||
2: 'started',
|
||||
3: 'stopped'
|
||||
3: 'stopped',
|
||||
4: 'paused'
|
||||
}
|
||||
exports.EVENT_NAMES = {
|
||||
update: 'update',
|
||||
completed: 'complete',
|
||||
started: 'start',
|
||||
stopped: 'stop'
|
||||
stopped: 'stop',
|
||||
paused: 'pause'
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,6 +47,8 @@ class Swarm {
|
||||
self._onAnnounceCompleted(params, peer, id)
|
||||
} else if (params.event === 'update') {
|
||||
self._onAnnounceUpdate(params, peer, id)
|
||||
} else if (params.event === 'paused') {
|
||||
self._onAnnouncePaused(params, peer, id)
|
||||
} else {
|
||||
cb(new Error('invalid event'))
|
||||
return
|
||||
@ -132,6 +134,15 @@ class Swarm {
|
||||
this.peers.set(id, peer)
|
||||
}
|
||||
|
||||
_onAnnouncePaused (params, peer, id) {
|
||||
if (!peer) {
|
||||
debug('unexpected `paused` event from peer that is not in swarm')
|
||||
return this._onAnnounceStarted(params, peer, id) // treat as a start
|
||||
}
|
||||
|
||||
this._onAnnounceUpdate(params, peer, id)
|
||||
}
|
||||
|
||||
_getPeers (numwant, ownPeerId, isWebRTC) {
|
||||
const peers = []
|
||||
const ite = randomIterate(this.peers.keys)
|
||||
|
Loading…
Reference in New Issue
Block a user