dry some code

This commit is contained in:
Feross Aboukhadijeh 2017-04-07 18:24:16 -07:00
parent 3c544c0b34
commit 63c953cbea

View File

@ -276,11 +276,7 @@ WebSocketTracker.prototype._onAnnounceResponse = function (data) {
var peer
if (data.offer && data.peer_id) {
debug('creating peer (from remote offer)')
peer = self._createPeer({
trickle: false,
config: self.client._rtcConfig,
wrtc: self.client._wrtc
})
peer = self._createPeer()
peer.id = common.binaryToHex(data.peer_id)
peer.once('signal', function (answer) {
var params = {
@ -389,12 +385,7 @@ WebSocketTracker.prototype._generateOffers = function (numwant, cb) {
function generateOffer () {
var offerId = randombytes(20).toString('hex')
debug('creating peer (from _generateOffers)')
var peer = self.peers[offerId] = self._createPeer({
initiator: true,
trickle: false,
config: self.client._rtcConfig,
wrtc: self.client._wrtc
})
var peer = self.peers[offerId] = self._createPeer({ initiator: true })
peer.once('signal', function (offer) {
offers.push({
offer: offer,
@ -421,6 +412,13 @@ WebSocketTracker.prototype._generateOffers = function (numwant, cb) {
WebSocketTracker.prototype._createPeer = function (opts) {
var self = this
opts = Object.assign({
trickle: false,
config: self.client._rtcConfig,
wrtc: self.client._wrtc
}, opts)
var peer = new Peer(opts)
peer.once('error', onError)