|
@@ -5,6 +5,7 @@ import transform from 'sdp-transform';
|
5
|
5
|
|
6
|
6
|
import * as GlobalOnErrorHandler from '../util/GlobalOnErrorHandler';
|
7
|
7
|
import JitsiRemoteTrack from './JitsiRemoteTrack';
|
|
8
|
+import * as JitsiTrackEvents from '../../JitsiTrackEvents';
|
8
|
9
|
import * as MediaType from '../../service/RTC/MediaType';
|
9
|
10
|
import LocalSdpMunger from './LocalSdpMunger';
|
10
|
11
|
import RTC from './RTC';
|
|
@@ -1546,6 +1547,16 @@ TraceablePeerConnection.prototype.removeTrack = function(localTrack) {
|
1546
|
1547
|
}
|
1547
|
1548
|
};
|
1548
|
1549
|
|
|
1550
|
+/**
|
|
1551
|
+ * Returns the sender corresponding to the given media type.
|
|
1552
|
+ * @param {MEDIA_TYPE} mediaType - The media type 'audio' or 'video' to be used for the search.
|
|
1553
|
+ * @returns {RTPSender|undefined} - The found sender or undefined if no sender
|
|
1554
|
+ * was found.
|
|
1555
|
+ */
|
|
1556
|
+TraceablePeerConnection.prototype.findSenderByKind = function(mediaType) {
|
|
1557
|
+ return this.peerconnection.getSenders().find(s => s.track && s.track.kind === mediaType);
|
|
1558
|
+};
|
|
1559
|
+
|
1549
|
1560
|
/**
|
1550
|
1561
|
* Returns the sender corresponding to the given MediaStream.
|
1551
|
1562
|
*
|
|
@@ -1633,6 +1644,33 @@ TraceablePeerConnection.prototype.replaceTrack = function(oldTrack, newTrack) {
|
1633
|
1644
|
return Promise.resolve(true);
|
1634
|
1645
|
};
|
1635
|
1646
|
|
|
1647
|
+/**
|
|
1648
|
+ * Replaces the existing media stream from the underlying peerconnection with the new
|
|
1649
|
+ * mediastream that has been added to the JitsiLocalTrack. Renegotiation with the remote
|
|
1650
|
+ * peer is not needed in this case.
|
|
1651
|
+ * @param {JitsiLocalTrack} localTrack - the localtrack whose mediastream has been updated.
|
|
1652
|
+ * @return {Promise} - Promise resolved with undefined if the track is replaced,
|
|
1653
|
+ * or rejected with <tt>InvalidModificationError<tt> if the track cannot be replaced.
|
|
1654
|
+ */
|
|
1655
|
+TraceablePeerConnection.prototype.replaceTrackWithoutOfferAnswer = function(localTrack) {
|
|
1656
|
+ const newTrack = localTrack.stream.getTracks()[0];
|
|
1657
|
+ const sender = this.findSenderByKind(newTrack.kind);
|
|
1658
|
+
|
|
1659
|
+ if (!sender) {
|
|
1660
|
+ return Promise.reject(new Error(`Could not find RTCRtpSender for ${newTrack.kind}`));
|
|
1661
|
+ }
|
|
1662
|
+
|
|
1663
|
+ return sender.replaceTrack(newTrack)
|
|
1664
|
+ .then(() => {
|
|
1665
|
+ this._addedStreams = this._addedStreams.filter(s => s !== localTrack._originalStream);
|
|
1666
|
+ this._addedStreams.push(localTrack.stream);
|
|
1667
|
+ localTrack.emit(JitsiTrackEvents.TRACK_MUTE_CHANGED, localTrack);
|
|
1668
|
+ })
|
|
1669
|
+ .catch(err => {
|
|
1670
|
+ logger.error(`replaceTrackWithoutOfferAnswer - replaceTrack failed for ${newTrack.kind}`, err);
|
|
1671
|
+ });
|
|
1672
|
+};
|
|
1673
|
+
|
1636
|
1674
|
/**
|
1637
|
1675
|
* Removes local track as part of the mute operation.
|
1638
|
1676
|
* @param {JitsiLocalTrack} localTrack the local track to be remove as part of
|