MCPcopy
hub / github.com/feross/simple-peer / replaceTrack

Method replaceTrack

index.js:321–338  ·  view source on GitHub ↗

* Replace a MediaStreamTrack by another in the connection. * @param {MediaStreamTrack} oldTrack * @param {MediaStreamTrack} newTrack * @param {MediaStream} stream

(oldTrack, newTrack, stream)

Source from the content-addressed store, hash-verified

319 * @param {MediaStream} stream
320 */
321 replaceTrack (oldTrack, newTrack, stream) {
322 if (this.destroying) return
323 if (this.destroyed) throw errCode(new Error('cannot replaceTrack after peer is destroyed'), 'ERR_DESTROYED')
324 this._debug('replaceTrack()')
325
326 const submap = this._senderMap.get(oldTrack)
327 const sender = submap ? submap.get(stream) : null
328 if (!sender) {
329 throw errCode(new Error('Cannot replace track that was never added.'), 'ERR_TRACK_NOT_ADDED')
330 }
331 if (newTrack) this._senderMap.set(newTrack, submap)
332
333 if (sender.replaceTrack != null) {
334 sender.replaceTrack(newTrack)
335 } else {
336 this.destroy(errCode(new Error('replaceTrack is not supported in this browser'), 'ERR_UNSUPPORTED_REPLACETRACK'))
337 }
338 }
339
340 /**
341 * Remove a MediaStreamTrack from the connection.

Callers 1

multistream.jsFile · 0.45

Calls 2

_debugMethod · 0.95
destroyMethod · 0.95

Tested by

no test coverage detected