(data)
| 180 | } |
| 181 | |
| 182 | signal (data) { |
| 183 | if (this.destroying) return |
| 184 | if (this.destroyed) throw errCode(new Error('cannot signal after peer is destroyed'), 'ERR_DESTROYED') |
| 185 | if (typeof data === 'string') { |
| 186 | try { |
| 187 | data = JSON.parse(data) |
| 188 | } catch (err) { |
| 189 | data = {} |
| 190 | } |
| 191 | } |
| 192 | this._debug('signal()') |
| 193 | |
| 194 | if (data.renegotiate && this.initiator) { |
| 195 | this._debug('got request to renegotiate') |
| 196 | this._needsNegotiation() |
| 197 | } |
| 198 | if (data.transceiverRequest && this.initiator) { |
| 199 | this._debug('got request for transceiver') |
| 200 | this.addTransceiver(data.transceiverRequest.kind, data.transceiverRequest.init) |
| 201 | } |
| 202 | if (data.candidate) { |
| 203 | if (this._pc.remoteDescription && this._pc.remoteDescription.type) { |
| 204 | this._addIceCandidate(data.candidate) |
| 205 | } else { |
| 206 | this._pendingCandidates.push(data.candidate) |
| 207 | } |
| 208 | } |
| 209 | if (data.sdp) { |
| 210 | this._pc.setRemoteDescription(new (this._wrtc.RTCSessionDescription)(data)) |
| 211 | .then(() => { |
| 212 | if (this.destroyed) return |
| 213 | |
| 214 | this._pendingCandidates.forEach(candidate => { |
| 215 | this._addIceCandidate(candidate) |
| 216 | }) |
| 217 | this._pendingCandidates = [] |
| 218 | |
| 219 | if (this._pc.remoteDescription.type === 'offer') this._createAnswer() |
| 220 | }) |
| 221 | .catch(err => { |
| 222 | this.destroy(errCode(err, 'ERR_SET_REMOTE_DESCRIPTION')) |
| 223 | }) |
| 224 | } |
| 225 | if (!data.sdp && !data.candidate && !data.renegotiate && !data.transceiverRequest) { |
| 226 | this.destroy(errCode(new Error('signal() called with invalid signal data'), 'ERR_SIGNALING')) |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | _addIceCandidate (candidate) { |
| 231 | const iceCandidateObj = new this._wrtc.RTCIceCandidate(candidate) |
no test coverage detected