mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 12:11:36 +00:00
dry some code
This commit is contained in:
parent
3c544c0b34
commit
63c953cbea
@ -276,11 +276,7 @@ WebSocketTracker.prototype._onAnnounceResponse = function (data) {
|
|||||||
var peer
|
var peer
|
||||||
if (data.offer && data.peer_id) {
|
if (data.offer && data.peer_id) {
|
||||||
debug('creating peer (from remote offer)')
|
debug('creating peer (from remote offer)')
|
||||||
peer = self._createPeer({
|
peer = self._createPeer()
|
||||||
trickle: false,
|
|
||||||
config: self.client._rtcConfig,
|
|
||||||
wrtc: self.client._wrtc
|
|
||||||
})
|
|
||||||
peer.id = common.binaryToHex(data.peer_id)
|
peer.id = common.binaryToHex(data.peer_id)
|
||||||
peer.once('signal', function (answer) {
|
peer.once('signal', function (answer) {
|
||||||
var params = {
|
var params = {
|
||||||
@ -389,12 +385,7 @@ WebSocketTracker.prototype._generateOffers = function (numwant, cb) {
|
|||||||
function generateOffer () {
|
function generateOffer () {
|
||||||
var offerId = randombytes(20).toString('hex')
|
var offerId = randombytes(20).toString('hex')
|
||||||
debug('creating peer (from _generateOffers)')
|
debug('creating peer (from _generateOffers)')
|
||||||
var peer = self.peers[offerId] = self._createPeer({
|
var peer = self.peers[offerId] = self._createPeer({ initiator: true })
|
||||||
initiator: true,
|
|
||||||
trickle: false,
|
|
||||||
config: self.client._rtcConfig,
|
|
||||||
wrtc: self.client._wrtc
|
|
||||||
})
|
|
||||||
peer.once('signal', function (offer) {
|
peer.once('signal', function (offer) {
|
||||||
offers.push({
|
offers.push({
|
||||||
offer: offer,
|
offer: offer,
|
||||||
@ -421,6 +412,13 @@ WebSocketTracker.prototype._generateOffers = function (numwant, cb) {
|
|||||||
|
|
||||||
WebSocketTracker.prototype._createPeer = function (opts) {
|
WebSocketTracker.prototype._createPeer = function (opts) {
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
|
opts = Object.assign({
|
||||||
|
trickle: false,
|
||||||
|
config: self.client._rtcConfig,
|
||||||
|
wrtc: self.client._wrtc
|
||||||
|
}, opts)
|
||||||
|
|
||||||
var peer = new Peer(opts)
|
var peer = new Peer(opts)
|
||||||
|
|
||||||
peer.once('error', onError)
|
peer.once('error', onError)
|
||||||
|
Loading…
Reference in New Issue
Block a user