|
|
@@ -191,8 +191,7 @@ export class TPCUtils {
|
|
191
|
191
|
/**
|
|
192
|
192
|
* Adds {@link JitsiLocalTrack} to the WebRTC peerconnection for the first time.
|
|
193
|
193
|
* @param {JitsiLocalTrack} track - track to be added to the peerconnection.
|
|
194
|
|
- * @param {boolean} isInitiator - boolean that indicates if the endpoint is offerer
|
|
195
|
|
- * in a p2p connection.
|
|
|
194
|
+ * @param {boolean} isInitiator - boolean that indicates if the endpoint is offerer in a p2p connection.
|
|
196
|
195
|
* @returns {void}
|
|
197
|
196
|
*/
|
|
198
|
197
|
addTrack(localTrack, isInitiator) {
|
|
|
@@ -238,13 +237,18 @@ export class TPCUtils {
|
|
238
|
237
|
}
|
|
239
|
238
|
logger.debug(`Adding ${localTrack} on ${this.pc}`);
|
|
240
|
239
|
|
|
241
|
|
- // If the client starts with audio/video muted setting, the transceiver direction
|
|
242
|
|
- // will be set to 'recvonly'. Use addStream here so that a MSID is generated for the stream.
|
|
|
240
|
+ // If the client starts with audio/video muted setting, the transceiver direction will be set to 'recvonly'.
|
|
243
|
241
|
if (transceiver.direction === 'recvonly') {
|
|
244
|
242
|
const stream = localTrack.getOriginalStream();
|
|
245
|
243
|
|
|
246
|
|
- if (stream) {
|
|
247
|
|
- this.pc.peerconnection.addStream(localTrack.getOriginalStream());
|
|
|
244
|
+ if (stream && track) {
|
|
|
245
|
+ try {
|
|
|
246
|
+ this.pc.peerconnection.addTrack(track, stream);
|
|
|
247
|
+ } catch (error) {
|
|
|
248
|
+ logger.error(`Adding ${localTrack} failed on ${this.pc}:${error?.message}`);
|
|
|
249
|
+
|
|
|
250
|
+ return Promise.reject(error);
|
|
|
251
|
+ }
|
|
248
|
252
|
|
|
249
|
253
|
return this.setEncodings(localTrack).then(() => {
|
|
250
|
254
|
this.pc.localTracks.set(localTrack.rtcId, localTrack);
|
|
|
@@ -395,6 +399,12 @@ export class TPCUtils {
|
|
395
|
399
|
.find(t => t.sender && t.sender.track && t.sender.track.kind === track.getType());
|
|
396
|
400
|
const parameters = transceiver.sender.getParameters();
|
|
397
|
401
|
|
|
|
402
|
+ // Resolve if the encodings are not available yet. This happens immediately after the track is added to the
|
|
|
403
|
+ // peerconnection on chrome in unified-plan. It is ok to ignore and not report the error here since the
|
|
|
404
|
+ // action that triggers 'addTrack' (like unmute) will also configure the encodings and set bitrates after that.
|
|
|
405
|
+ if (!parameters?.encodings?.length) {
|
|
|
406
|
+ return Promise.resolve();
|
|
|
407
|
+ }
|
|
398
|
408
|
parameters.encodings = this._getStreamEncodings(track);
|
|
399
|
409
|
|
|
400
|
410
|
return transceiver.sender.setParameters(parameters);
|