Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 739c3c1

Browse files
authored
Refine closing media section in SDP (#830)
1 parent 814a0c4 commit 739c3c1

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

source/agent/webrtc/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
8888
rid: trackInfo.rid,
8989
active: true,
9090
};
91-
log.warn('notifyTrackUpdate', controller, publicTrackId, updateInfo);
91+
log.debug('notifyTrackUpdate', controller, publicTrackId, updateInfo);
9292
notifyTrackUpdate(controller, transportId, updateInfo);
9393

9494
} else if (trackInfo.type === 'track-removed') {
@@ -350,7 +350,7 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
350350
if (conn) {
351351
promises = tracks.map(trackId => new Promise((resolve, reject) => {
352352
if (mediaTracks.has(trackId)) {
353-
log.warn('got on off track:', trackId);
353+
log.debug('got on off track:', trackId);
354354
mediaTracks.get(trackId).onTrackControl(
355355
'av', direction, action, resolve, reject);
356356
} else {

source/agent/webrtc/sdpInfo.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class SdpInfo {
2424
this.obj = transform.parse(str);
2525
this.obj.media.forEach((media, i) => {
2626
if (media.mid === undefined) {
27-
log.info(`Media ${i} missing mid`);
27+
log.warn(`Media ${i} missing mid`);
2828
media.mid = -1;
2929
}
3030
});
@@ -366,12 +366,22 @@ class SdpInfo {
366366
});
367367
}
368368

369+
filterMedia(mids) {
370+
this.obj.media = mids.map((mid) => {
371+
const media = this.media(mid);
372+
if (!media) {
373+
log.warn(`Media ${i} missing mid`);
374+
}
375+
return media;
376+
});
377+
}
378+
369379
isMediaClosed(mid) {
370380
const mediaInfo = this.media(mid);
371381
if (!mediaInfo) {
372382
return true;
373383
}
374-
if (mediaInfo.port === 0 && mediaInfo.direction === 'inactive') {
384+
if (mediaInfo.direction === 'inactive') {
375385
return true;
376386
}
377387
return false;
@@ -380,8 +390,10 @@ class SdpInfo {
380390
closeMedia(mid) {
381391
const mediaInfo = this.media(mid);
382392
if (mediaInfo) {
393+
if (!mediaInfo.candidates) {
394+
mediaInfo.port = 0;
395+
}
383396
mediaInfo.direction = 'inactive';
384-
mediaInfo.port = 0;
385397
delete mediaInfo.ext;
386398
delete mediaInfo.ssrcs;
387399
delete mediaInfo.ssrcGroups;

source/agent/webrtc/wrtcConnection.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class WrtcStream extends EventEmitter {
8080
this.audioFramePacketizer = new AudioFramePacketizer(audio.mid, audio.midExtId);
8181
this.audioFramePacketizer.bindTransport(wrtc.getMediaStream(id));
8282
if (this.owner) {
83-
log.warn('set owner!!!', this.owner);
8483
this.audioFramePacketizer.setOwner(this.owner);
8584
}
8685
}
@@ -276,6 +275,9 @@ module.exports = function (spec, on_status, on_track) {
276275
op.enabled = false;
277276
destroyTransport(mid);
278277
ret = true;
278+
if (localSdp) {
279+
localSdp.closeMedia(mid);
280+
}
279281
}
280282
});
281283
if (msidMap.has(operationId)) {
@@ -442,6 +444,7 @@ module.exports = function (spec, on_status, on_track) {
442444
if (!operationMap.has(mid)) {
443445
log.warn(`MID ${mid} in offer has no mapped operations (disabled)`);
444446
remoteSdp.closeMedia(mid);
447+
localSdp.closeMedia(mid);
445448
return;
446449
}
447450
if (operationMap.get(mid).sdpDirection !== remoteSdp.mediaDirection(mid)) {
@@ -498,7 +501,6 @@ module.exports = function (spec, on_status, on_track) {
498501
} else {
499502
// Later offer
500503
const laterSdp = new SdpInfo(sdp);
501-
const changedMids = laterSdp.compareMedia(remoteSdp);
502504
const addedMids = [];
503505
const removedMids = [];
504506

@@ -539,7 +541,10 @@ module.exports = function (spec, on_status, on_track) {
539541
// Should already be destroyed by 'removeTrackOperation'
540542
// destroyTransport(mid);
541543
}
542-
localSdp.setBundleMids(remoteSdp.bundleMids());
544+
remoteSdp.filterMedia(laterSdp.mids());
545+
localSdp.filterMedia(laterSdp.mids());
546+
remoteSdp.setBundleMids(laterSdp.bundleMids());
547+
localSdp.setBundleMids(laterSdp.bundleMids());
543548
// Produce answer
544549
const message = localSdp.toString();
545550
log.debug('Answer SDP', message);

0 commit comments

Comments
 (0)