Skip to content

Commit 52042cf

Browse files
committed
Remove stream-replacemnt
Signed-off-by: Šimon Brandner <[email protected]>
1 parent 4a42418 commit 52042cf

File tree

4 files changed

+45
-156
lines changed

4 files changed

+45
-156
lines changed

spec/unit/webrtc/call.spec.ts

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -391,71 +391,6 @@ describe('Call', function() {
391391
}).track.id).toBe("video_track");
392392
});
393393

394-
describe("should handle stream replacement", () => {
395-
it("with both purpose and id", async () => {
396-
await startVoiceCall(client, call);
397-
398-
call.updateRemoteSDPStreamMetadata({
399-
"remote_stream1": {
400-
purpose: SDPStreamMetadataPurpose.Usermedia,
401-
},
402-
});
403-
call.pushRemoteFeed(new MockMediaStream("remote_stream1", []));
404-
const feed = call.getFeeds().find((feed) => feed.stream.id === "remote_stream1");
405-
406-
call.updateRemoteSDPStreamMetadata({
407-
"remote_stream2": {
408-
purpose: SDPStreamMetadataPurpose.Usermedia,
409-
},
410-
});
411-
call.pushRemoteFeed(new MockMediaStream("remote_stream2", []));
412-
413-
expect(feed?.stream?.id).toBe("remote_stream2");
414-
});
415-
416-
it("with just purpose", async () => {
417-
await startVoiceCall(client, call);
418-
419-
call.updateRemoteSDPStreamMetadata({
420-
"remote_stream1": {
421-
purpose: SDPStreamMetadataPurpose.Usermedia,
422-
},
423-
});
424-
call.pushRemoteFeed(new MockMediaStream("remote_stream1", []));
425-
const feed = call.getFeeds().find((feed) => feed.stream.id === "remote_stream1");
426-
427-
call.updateRemoteSDPStreamMetadata({
428-
"remote_stream2": {
429-
purpose: SDPStreamMetadataPurpose.Usermedia,
430-
},
431-
});
432-
call.pushRemoteFeed(new MockMediaStream("remote_stream2", []));
433-
434-
expect(feed?.stream?.id).toBe("remote_stream2");
435-
});
436-
437-
it("should not replace purpose is different", async () => {
438-
await startVoiceCall(client, call);
439-
440-
call.updateRemoteSDPStreamMetadata({
441-
"remote_stream1": {
442-
purpose: SDPStreamMetadataPurpose.Usermedia,
443-
},
444-
});
445-
call.pushRemoteFeed(new MockMediaStream("remote_stream1", []));
446-
const feed = call.getFeeds().find((feed) => feed.stream.id === "remote_stream1");
447-
448-
call.updateRemoteSDPStreamMetadata({
449-
"remote_stream2": {
450-
purpose: SDPStreamMetadataPurpose.Screenshare,
451-
},
452-
});
453-
call.pushRemoteFeed(new MockMediaStream("remote_stream2", []));
454-
455-
expect(feed?.stream?.id).toBe("remote_stream1");
456-
});
457-
});
458-
459394
it("should handle SDPStreamMetadata changes", async () => {
460395
await startVoiceCall(client, call);
461396

spec/unit/webrtc/callFeed.spec.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { SDPStreamMetadataPurpose } from "../../../src/webrtc/callEventTypes";
18-
import { CallFeed, CallFeedEvent } from "../../../src/webrtc/callFeed";
19-
import { MockMediaStream, MockMediaStreamTrack } from "../../test-utils/webrtc";
2017
import { TestClient } from "../../TestClient";
2118

2219
describe("CallFeed", () => {
23-
const roomId = "room_id";
24-
2520
let client;
2621

2722
beforeEach(() => {
@@ -31,31 +26,4 @@ describe("CallFeed", () => {
3126
afterEach(() => {
3227
client.stop();
3328
});
34-
35-
it("should handle stream replacement", () => {
36-
const feedNewStreamCallback = jest.fn();
37-
const feed = new CallFeed({
38-
client,
39-
roomId,
40-
userId: "user1",
41-
// @ts-ignore Mock
42-
stream: new MockMediaStream("stream1"),
43-
id: "id",
44-
purpose: SDPStreamMetadataPurpose.Usermedia,
45-
audioMuted: false,
46-
videoMuted: false,
47-
});
48-
feed.on(CallFeedEvent.NewStream, feedNewStreamCallback);
49-
50-
const replacementStream = new MockMediaStream("stream2");
51-
// @ts-ignore Mock
52-
feed.setNewStream(replacementStream);
53-
expect(feedNewStreamCallback).toHaveBeenCalledWith(replacementStream);
54-
expect(feed.stream).toBe(replacementStream);
55-
56-
feedNewStreamCallback.mockReset();
57-
58-
replacementStream.addTrack(new MockMediaStreamTrack("track_id", "audio"));
59-
expect(feedNewStreamCallback).toHaveBeenCalledWith(replacementStream);
60-
});
6129
});

src/webrtc/call.ts

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -523,24 +523,22 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
523523
return;
524524
}
525525

526-
// Try to find a feed with the same purpose as the new stream,
527-
// if we find it replace the old stream with the new one
528-
const existingFeed = this.getRemoteFeeds().find((feed) => feed.purpose === purpose);
529-
if (existingFeed) {
530-
existingFeed.setNewStream(stream);
531-
} else {
532-
this.feeds.push(new CallFeed({
533-
client: this.client,
534-
roomId: this.roomId,
535-
userId,
536-
stream,
537-
purpose,
538-
audioMuted,
539-
videoMuted,
540-
}));
541-
this.emit(CallEvent.FeedsChanged, this.feeds);
526+
if (this.getFeedByStreamId(stream.id)) {
527+
logger.warn(`Ignoring stream with id ${stream.id} because we already have a feed for it`);
528+
return;
542529
}
543530

531+
this.feeds.push(new CallFeed({
532+
client: this.client,
533+
roomId: this.roomId,
534+
userId,
535+
stream,
536+
purpose,
537+
audioMuted,
538+
videoMuted,
539+
}));
540+
this.emit(CallEvent.FeedsChanged, this.feeds);
541+
544542
logger.info(`Pushed remote stream (id="${stream.id}", active="${stream.active}", purpose=${purpose})`);
545543
}
546544

@@ -562,24 +560,22 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
562560
return;
563561
}
564562

565-
// Try to find a feed with the same stream id as the new stream,
566-
// if we find it replace the old stream with the new one
567-
const feed = this.getFeedByStreamId(stream.id);
568-
if (feed) {
569-
feed.setNewStream(stream);
570-
} else {
571-
this.feeds.push(new CallFeed({
572-
client: this.client,
573-
roomId: this.roomId,
574-
audioMuted: false,
575-
videoMuted: false,
576-
userId,
577-
stream,
578-
purpose,
579-
}));
580-
this.emit(CallEvent.FeedsChanged, this.feeds);
563+
if (this.getFeedByStreamId(stream.id)) {
564+
logger.warn(`Ignoring stream with id ${stream.id} because we already have a feed for it`);
565+
return;
581566
}
582567

568+
this.feeds.push(new CallFeed({
569+
client: this.client,
570+
roomId: this.roomId,
571+
audioMuted: false,
572+
videoMuted: false,
573+
userId,
574+
stream,
575+
purpose,
576+
}));
577+
this.emit(CallEvent.FeedsChanged, this.feeds);
578+
583579
logger.info(`Pushed remote stream (id="${stream.id}", active="${stream.active}")`);
584580
}
585581

@@ -592,25 +588,24 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
592588
setTracksEnabled(stream.getAudioTracks(), true);
593589
setTracksEnabled(stream.getVideoTracks(), true);
594590

595-
// We try to replace an existing feed if there already is one with the same purpose
596-
const existingFeed = this.getLocalFeeds().find((feed) => feed.purpose === purpose);
597-
if (existingFeed) {
598-
existingFeed.setNewStream(stream);
599-
} else {
600-
this.pushLocalFeed(
601-
new CallFeed({
602-
client: this.client,
603-
roomId: this.roomId,
604-
audioMuted: false,
605-
videoMuted: false,
606-
userId,
607-
stream,
608-
purpose,
609-
}),
610-
addToPeerConnection,
611-
);
612-
this.emit(CallEvent.FeedsChanged, this.feeds);
591+
if (this.getFeedByStreamId(stream.id)) {
592+
logger.warn(`Ignoring stream with id ${stream.id} because we already have a feed for it`);
593+
return;
613594
}
595+
596+
this.pushLocalFeed(
597+
new CallFeed({
598+
client: this.client,
599+
roomId: this.roomId,
600+
audioMuted: false,
601+
videoMuted: false,
602+
userId,
603+
stream,
604+
purpose,
605+
}),
606+
addToPeerConnection,
607+
);
608+
this.emit(CallEvent.FeedsChanged, this.feeds);
614609
}
615610

616611
/**

src/webrtc/callFeed.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,6 @@ export class CallFeed extends TypedEventEmitter<CallFeedEvent, EventHandlerMap>
174174
return this.speaking;
175175
}
176176

177-
/**
178-
* Replaces the current MediaStream with a new one.
179-
* This method should be only used by MatrixCall.
180-
* @param newStream new stream with which to replace the current one
181-
*/
182-
public setNewStream(newStream: MediaStream): void {
183-
this.updateStream(this.stream, newStream);
184-
}
185-
186177
/**
187178
* Set one or both of feed's internal audio and video video mute state
188179
* Either value may be null to leave it as-is

0 commit comments

Comments
 (0)