(opts)
| 27 | */ |
| 28 | class Peer extends stream.Duplex { |
| 29 | constructor (opts) { |
| 30 | opts = Object.assign({ |
| 31 | allowHalfOpen: false |
| 32 | }, opts) |
| 33 | |
| 34 | super(opts) |
| 35 | |
| 36 | this._id = randombytes(4).toString('hex').slice(0, 7) |
| 37 | this._debug('new peer %o', opts) |
| 38 | |
| 39 | this.channelName = opts.initiator |
| 40 | ? opts.channelName || randombytes(20).toString('hex') |
| 41 | : null |
| 42 | |
| 43 | this.initiator = opts.initiator || false |
| 44 | this.channelConfig = opts.channelConfig || Peer.channelConfig |
| 45 | this.channelNegotiated = this.channelConfig.negotiated |
| 46 | this.config = Object.assign({}, Peer.config, opts.config) |
| 47 | this.offerOptions = opts.offerOptions || {} |
| 48 | this.answerOptions = opts.answerOptions || {} |
| 49 | this.sdpTransform = opts.sdpTransform || (sdp => sdp) |
| 50 | this.streams = opts.streams || (opts.stream ? [opts.stream] : []) // support old "stream" option |
| 51 | this.trickle = opts.trickle !== undefined ? opts.trickle : true |
| 52 | this.allowHalfTrickle = opts.allowHalfTrickle !== undefined ? opts.allowHalfTrickle : false |
| 53 | this.iceCompleteTimeout = opts.iceCompleteTimeout || ICECOMPLETE_TIMEOUT |
| 54 | |
| 55 | this.destroyed = false |
| 56 | this.destroying = false |
| 57 | this._connected = false |
| 58 | |
| 59 | this.remoteAddress = undefined |
| 60 | this.remoteFamily = undefined |
| 61 | this.remotePort = undefined |
| 62 | this.localAddress = undefined |
| 63 | this.localFamily = undefined |
| 64 | this.localPort = undefined |
| 65 | |
| 66 | this._wrtc = (opts.wrtc && typeof opts.wrtc === 'object') |
| 67 | ? opts.wrtc |
| 68 | : getBrowserRTC() |
| 69 | |
| 70 | if (!this._wrtc) { |
| 71 | if (typeof window === 'undefined') { |
| 72 | throw errCode(new Error('No WebRTC support: Specify `opts.wrtc` option in this environment'), 'ERR_WEBRTC_SUPPORT') |
| 73 | } else { |
| 74 | throw errCode(new Error('No WebRTC support: Not a supported browser'), 'ERR_WEBRTC_SUPPORT') |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | this._pcReady = false |
| 79 | this._channelReady = false |
| 80 | this._iceComplete = false // ice candidate trickle done (got null candidate) |
| 81 | this._iceCompleteTimer = null // send an offer/answer anyway after some timeout |
| 82 | this._channel = null |
| 83 | this._pendingCandidates = [] |
| 84 | |
| 85 | this._isNegotiating = false // is this peer waiting for negotiation to complete? |
| 86 | this._firstNegotiation = true |
nothing calls this directly
no test coverage detected