From e66f52b02d370116cbaf8dab286c87fcb379a83d Mon Sep 17 00:00:00 2001 From: Jianjun Zhu Date: Mon, 26 Apr 2021 10:58:25 +0800 Subject: [PATCH 1/5] Add new properties for getting senders and receivers. --- docs/design/owt_with_webrtc_apis.md | 4 ++-- docs/mdfiles/changelog.md | 2 ++ src/sdk/base/publication.js | 29 ++++++++++++++++++++++- src/sdk/conference/channel.js | 36 +++++++++++++++++++---------- src/sdk/conference/subscription.js | 29 ++++++++++++++++++++++- 5 files changed, 84 insertions(+), 16 deletions(-) diff --git a/docs/design/owt_with_webrtc_apis.md b/docs/design/owt_with_webrtc_apis.md index 351a1c28..c6e12753 100644 --- a/docs/design/owt_with_webrtc_apis.md +++ b/docs/design/owt_with_webrtc_apis.md @@ -9,8 +9,8 @@ OWT(Open WebRTC Toolkit) Client SDKs provide convenient APIs to create, publish, - Set preferred codecs. - Disable or enable RTX / RED / FEC. #### API Changes -- A new method `getSender` will be added to `Publication`. It returns an `RTCRtpSender` for certain `Publication`. -- A new method `getReceiver` will be added to `Subscription`. It returns an `RTCRtpReceiver` for certain `Subscription`. +- A new member `senders` will be added to `Publication`. It returns an array of `RTCRtpSender`s for certain `Publication`. +- A new member `receivers` will be added to `Subscription`. It returns an array `RTCRtpReceiver`s for certain `Subscription`. - A new method `addTransceiver(DOMString trackKind, sequence sendEncodings)` will be added to `ConferenceClient`. It invokes `RTCPeerConnection.addTransceiver(trackKind, {direction:inactive, sendEncodings:sendEncodings})`, returns an `RTCRtpTransceiver`. Please note that direction is `inactive` until a `publish` with return transceiver is called. - The second parameter of `ConferenceClient.publish` accepts an `RTCRtpTransceiver` created by `RTCPeerConnection.addTransceiver`. When this method is called, certain `RTCRtpTransceiver`'s direction is changed to `sendonly`, and its sender's `setStreams` is called with the first parameter's `mediaStream`. #### Server Requirements diff --git a/docs/mdfiles/changelog.md b/docs/mdfiles/changelog.md index 6d773b58..f3ca8511 100644 --- a/docs/mdfiles/changelog.md +++ b/docs/mdfiles/changelog.md @@ -2,6 +2,8 @@ Change Log ========== # 5.1 * When subscribe a stream in conference mode, the subscribed MediaStream or BidirectionalStream is associated with a `Owt.Conference.Subscription` instead of a `Owt.Base.RemoteStream`. The `stream` property of a RemoteStream in conference mode is always undefined, while a new property `stream` is added to `Subscription`. It allows a RemoteStream to be subscribed multiple times, as well as subscribing audio and video tracks from different streams. +* Add a new property `senders` to `Publication` for get `RTCRtpSender`s. +* Add a new property `receivers` to `Subscription` for get `RTCRtpReceiver`s. # 5.0 * Add WebTransport support for conference mode, see [this design doc](../../design/webtransport.md) for detailed information. * All publications and subscriptions for the same conference use the same `PeerConnection`. diff --git a/src/sdk/base/publication.js b/src/sdk/base/publication.js index 9fb18a88..facb5147 100644 --- a/src/sdk/base/publication.js +++ b/src/sdk/base/publication.js @@ -123,7 +123,7 @@ export class PublicationSettings { */ export class Publication extends EventDispatcher { // eslint-disable-next-line require-jsdoc - constructor(id, stop, getStats, mute, unmute) { + constructor(id, transceivers, stop, getStats, mute, unmute) { super(); /** * @member {string} id @@ -135,6 +135,33 @@ export class Publication extends EventDispatcher { writable: false, value: id ? id : Utils.createUuid(), }); + /** + * @member {RTCRtpTransceiver[]} _transceivers + * @instance + * @private + * @desc A list of RTCRtpTransceiver associated with this Publication. For + * each RTCRtpTransceiver, it's `direction` should always be `sendonly`. + * @memberof Owt.Base.Publication + * @see {@link https://w3c.github.io/webrtc-pc/#rtcrtptransceiver-interface|RTCRtpTransceiver Interface of WebRTC 1.0}. + */ + Object.defineProperty(this, '_transceivers', { + configurable: false, + writable: false, + value: transceivers, + }); + /** + * @member {RTCRtpSenders[]} senders + * @instance + * @readonly + * @desc A list of RTCRtpSenders associated with this Publication. + * @memberof Owt.Base.Publication + * @see {@link https://w3c.github.io/webrtc-pc/#rtcrtpsender-interface|RTCRtpSender Interface of WebRTC 1.0}. + */ + Object.defineProperty(this, 'senders', { + configurable: false, + writable: false, + value: Array.from(this._transceivers, (t) => t.sender), + }); /** * @function stop * @instance diff --git a/src/sdk/conference/channel.js b/src/sdk/conference/channel.js index dcb35994..6b689c0d 100644 --- a/src/sdk/conference/channel.js +++ b/src/sdk/conference/channel.js @@ -876,12 +876,18 @@ export class ConferencePeerConnectionChannel extends EventDispatcher { const internalId = this._reverseIdMap.get(sessionId); if (this._subscribePromises.has(internalId)) { const mediaStream = this._remoteMediaStreams.get(sessionId); - const subscription = new Subscription(sessionId, mediaStream, () => { - this._unsubscribe(internalId); - }, () => this._getStats(), - (trackKind) => this._muteOrUnmute(sessionId, true, false, trackKind), - (trackKind) => this._muteOrUnmute(sessionId, false, false, trackKind), - (options) => this._applyOptions(sessionId, options)); + const subscription = new Subscription( + sessionId, mediaStream, + Array.from( + this._subscribeTransceivers.get(internalId).transceivers, + (t) => t.transceiver), + () => { + this._unsubscribe(internalId); + }, + () => this._getStats(), + (trackKind) => this._muteOrUnmute(sessionId, true, false, trackKind), + (trackKind) => this._muteOrUnmute(sessionId, false, false, trackKind), + (options) => this._applyOptions(sessionId, options)); this._subscriptions.set(sessionId, subscription); // Resolve subscription if mediaStream is ready. if (this._subscriptions.get(sessionId).stream) { @@ -889,12 +895,18 @@ export class ConferencePeerConnectionChannel extends EventDispatcher { this._subscribePromises.delete(internalId); } } else if (this._publishPromises.has(internalId)) { - const publication = new Publication(sessionId, () => { - this._unpublish(internalId); - return Promise.resolve(); - }, () => this._getStats(), - (trackKind) => this._muteOrUnmute(sessionId, true, true, trackKind), - (trackKind) => this._muteOrUnmute(sessionId, false, true, trackKind)); + const publication = new Publication( + sessionId, + Array.from( + this._publishTransceivers.get(internalId).transceivers, + (t) => t.transceiver), + () => { + this._unpublish(internalId); + return Promise.resolve(); + }, + () => this._getStats(), + (trackKind) => this._muteOrUnmute(sessionId, true, true, trackKind), + (trackKind) => this._muteOrUnmute(sessionId, false, true, trackKind)); this._publications.set(sessionId, publication); this._publishPromises.get(internalId).resolve(publication); // Do not fire publication's ended event when associated stream is ended. diff --git a/src/sdk/conference/subscription.js b/src/sdk/conference/subscription.js index a8056dbe..ced81bf7 100644 --- a/src/sdk/conference/subscription.js +++ b/src/sdk/conference/subscription.js @@ -270,7 +270,8 @@ export class SubscriptionUpdateOptions { */ export class Subscription extends EventDispatcher { // eslint-disable-next-line require-jsdoc - constructor(id, stream, stop, getStats, mute, unmute, applyOptions) { + constructor( + id, stream, transceivers, stop, getStats, mute, unmute, applyOptions) { super(); if (!id) { throw new TypeError('ID cannot be null or undefined.'); @@ -298,6 +299,32 @@ export class Subscription extends EventDispatcher { writable: true, value: stream, }); + /** + * @member {RTCRtpTransceiver[]} transceivers + * @instance + * @desc A list of RTCRtpTransceiver associated with this Subscription. For + * each RTCRtpTransceiver, it's `direction` should always be `recvonly`. + * @memberof Owt.Base.Subscription + * @see {@link https://w3c.github.io/webrtc-pc/#rtcrtptransceiver-interface|RTCRtpTransceiver Interface of WebRTC 1.0}. + */ + Object.defineProperty(this, '_transceivers', { + configurable: false, + writable: false, + value: transceivers, + }); + /** + * @member {RTCRtpReceivers[]} receivers + * @instance + * @readonly + * @desc A list of RTCRtpReceivers associated with this Subscription. + * @memberof Owt.Base.Subscription + * @see {@link https://w3c.github.io/webrtc-pc/#rtcrtpreceiver-interface|RTCRtpReceivers Interface of WebRTC 1.0}. + */ + Object.defineProperty(this, 'receivers', { + configurable: false, + writable: false, + value: Array.from(this._transceivers, (t) => t.receiver), + }); /** * @function stop * @instance From 7299e1941aab2dd88d0d476d9dd8300f61aba64c Mon Sep 17 00:00:00 2001 From: Jianjun Zhu Date: Mon, 26 Apr 2021 12:47:15 +0800 Subject: [PATCH 2/5] Property senders is not available in P2P mode. --- src/sdk/base/publication.js | 10 +++++++--- src/sdk/p2p/peerconnection-channel.js | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/sdk/base/publication.js b/src/sdk/base/publication.js index facb5147..55ea5f12 100644 --- a/src/sdk/base/publication.js +++ b/src/sdk/base/publication.js @@ -139,8 +139,9 @@ export class Publication extends EventDispatcher { * @member {RTCRtpTransceiver[]} _transceivers * @instance * @private - * @desc A list of RTCRtpTransceiver associated with this Publication. For + * @desc A list of RTCRtpTransceiver associated with this Publication. For * each RTCRtpTransceiver, it's `direction` should always be `sendonly`. + * This member is not available in P2P mode. * @memberof Owt.Base.Publication * @see {@link https://w3c.github.io/webrtc-pc/#rtcrtptransceiver-interface|RTCRtpTransceiver Interface of WebRTC 1.0}. */ @@ -153,14 +154,17 @@ export class Publication extends EventDispatcher { * @member {RTCRtpSenders[]} senders * @instance * @readonly - * @desc A list of RTCRtpSenders associated with this Publication. + * @desc A list of RTCRtpSenders associated with this Publication. This + * member is not available in P2P mode. * @memberof Owt.Base.Publication * @see {@link https://w3c.github.io/webrtc-pc/#rtcrtpsender-interface|RTCRtpSender Interface of WebRTC 1.0}. */ Object.defineProperty(this, 'senders', { configurable: false, writable: false, - value: Array.from(this._transceivers, (t) => t.sender), + value: this._transceivers ? + Array.from(this._transceivers, (t) => t.sender) : + undefined, }); /** * @function stop diff --git a/src/sdk/p2p/peerconnection-channel.js b/src/sdk/p2p/peerconnection-channel.js index 3847ae71..76808c9b 100644 --- a/src/sdk/p2p/peerconnection-channel.js +++ b/src/sdk/p2p/peerconnection-channel.js @@ -305,8 +305,9 @@ class P2PPeerConnectionChannel extends EventDispatcher { (element) => element.mediaStream.id == mediaStreamId); const targetStream = this._publishingStreams[targetStreamIndex]; this._publishingStreams.splice(targetStreamIndex, 1); + // TODO: Set transceivers for Publication. const publication = new Publication( - id, () => { + id, undefined, () => { this._unpublish(targetStream).then(() => { publication.dispatchEvent(new OwtEvent('ended')); }, (err) => { From 1c158b5c8275b62522c5c34795f4dfb65b50c611 Mon Sep 17 00:00:00 2001 From: Jianjun Zhu Date: Mon, 26 Apr 2021 14:54:39 +0800 Subject: [PATCH 3/5] Add test cases. --- docs/mdfiles/changelog.md | 4 ++-- test/unit/resources/scripts/base.js | 14 +++++++++++++- test/unit/resources/scripts/conference.js | 14 +++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/mdfiles/changelog.md b/docs/mdfiles/changelog.md index f3ca8511..15767808 100644 --- a/docs/mdfiles/changelog.md +++ b/docs/mdfiles/changelog.md @@ -2,8 +2,8 @@ Change Log ========== # 5.1 * When subscribe a stream in conference mode, the subscribed MediaStream or BidirectionalStream is associated with a `Owt.Conference.Subscription` instead of a `Owt.Base.RemoteStream`. The `stream` property of a RemoteStream in conference mode is always undefined, while a new property `stream` is added to `Subscription`. It allows a RemoteStream to be subscribed multiple times, as well as subscribing audio and video tracks from different streams. -* Add a new property `senders` to `Publication` for get `RTCRtpSender`s. -* Add a new property `receivers` to `Subscription` for get `RTCRtpReceiver`s. +* Add a new property `senders` to `Publication` for getting `RTCRtpSender`s. +* Add a new property `receivers` to `Subscription` for getting `RTCRtpReceiver`s. # 5.0 * Add WebTransport support for conference mode, see [this design doc](../../design/webtransport.md) for detailed information. * All publications and subscriptions for the same conference use the same `PeerConnection`. diff --git a/test/unit/resources/scripts/base.js b/test/unit/resources/scripts/base.js index 6978aad0..f5463ee4 100644 --- a/test/unit/resources/scripts/base.js +++ b/test/unit/resources/scripts/base.js @@ -8,9 +8,9 @@ import * as MediaStreamFactoryModule from '../../../../src/sdk/base/mediastream- import * as StreamModule from '../../../../src/sdk/base/stream.js'; import * as MediaFormatModule from '../../../../src/sdk/base/mediaformat.js' import * as SdpUtils from '../../../../src/sdk/base/sdputils.js' +import * as PublicationModule from '../../../../src/sdk/base/publication.js' const expect = chai.expect; -const screenSharingExtensionId = 'jniliohjdiikfjjdlpapmngebedgigjn'; chai.use(chaiAsPromised); describe('Unit tests for MediaStreamFactory', function() { function createMediaStream(constraints, audioTracksExpected, @@ -181,3 +181,15 @@ describe('Unit tests for SDP utils.', function() { done(); }); }); + +describe('Unit tests for Publication.', () => { + it('Get senders returns all transceivers\' sender.', () => { + const audioTransceiver = {sender: new sinon.spy(), receiver: sinon.spy()}; + const videoTransceiver = {sender: new sinon.spy(), receiver: sinon.spy()}; + const publication = new PublicationModule.Publication( + 'sessionId', [audioTransceiver, videoTransceiver]); + expect(publication.senders).to.deep.equal([ + audioTransceiver.sender, videoTransceiver.sender + ]); + }); +}); \ No newline at end of file diff --git a/test/unit/resources/scripts/conference.js b/test/unit/resources/scripts/conference.js index b34aa596..50efd629 100644 --- a/test/unit/resources/scripts/conference.js +++ b/test/unit/resources/scripts/conference.js @@ -8,9 +8,9 @@ import {ConferenceClient} from '../../../../src/sdk/conference/client.js'; import {ConferencePeerConnectionChannel} from '../../../../src/sdk/conference/channel.js'; import * as StreamModule from '../../../../src/sdk/base/stream.js'; import * as EventModule from '../../../../src/sdk/base/event.js' +import * as SubscriptionModule from '../../../../src/sdk/conference/subscription.js' const expect = chai.expect; -const screenSharingExtensionId = 'jniliohjdiikfjjdlpapmngebedgigjn'; chai.use(chaiAsPromised); describe('Unit tests for ConferenceClient', function() { @@ -98,4 +98,16 @@ describe('Unit tests for ConferencePeerConnectionChannel.', () => { } }); }); +}); + +describe('Unit tests for Subscription.', () => { + it('Get receivers returns all transceivers\' receiver.', () => { + const audioTransceiver = {sender: new sinon.spy(), receiver: sinon.spy()}; + const videoTransceiver = {sender: new sinon.spy(), receiver: sinon.spy()}; + const Subscription = new SubscriptionModule.Subscription( + 'sessionId', undefined, [audioTransceiver, videoTransceiver]); + expect(Subscription.receivers).to.deep.equal([ + audioTransceiver.receiver, videoTransceiver.receiver + ]); + }); }); \ No newline at end of file From e4bb819a27a923d28edbe698e8fe0b3b39f77b68 Mon Sep 17 00:00:00 2001 From: Jianjun Zhu Date: Fri, 30 Apr 2021 15:37:09 +0800 Subject: [PATCH 4/5] Move transceivers to TransportSettings. --- docs/design/owt_with_webrtc_apis.md | 4 ++-- docs/mdfiles/changelog.md | 4 ++-- src/sdk/base/publication.js | 29 ++++------------------- src/sdk/base/transport.js | 17 ++++++++++--- src/sdk/conference/channel.js | 18 ++++++++------ src/sdk/conference/subscription.js | 26 +++++--------------- test/unit/resources/scripts/base.js | 14 +++++------ test/unit/resources/scripts/conference.js | 15 ++++++------ 8 files changed, 54 insertions(+), 73 deletions(-) diff --git a/docs/design/owt_with_webrtc_apis.md b/docs/design/owt_with_webrtc_apis.md index c6e12753..43131541 100644 --- a/docs/design/owt_with_webrtc_apis.md +++ b/docs/design/owt_with_webrtc_apis.md @@ -9,8 +9,8 @@ OWT(Open WebRTC Toolkit) Client SDKs provide convenient APIs to create, publish, - Set preferred codecs. - Disable or enable RTX / RED / FEC. #### API Changes -- A new member `senders` will be added to `Publication`. It returns an array of `RTCRtpSender`s for certain `Publication`. -- A new member `receivers` will be added to `Subscription`. It returns an array `RTCRtpReceiver`s for certain `Subscription`. +- A new member `rtpTransceivers` will be added to `TransportSettings`. It returns an array `RTCRtpReceiver`s for RTP transport. +- A new member `transport` will be added to `Publication` and `Subscription`. Developers could get `RTPTransceiver`s from its `rtpTransceivers` property. - A new method `addTransceiver(DOMString trackKind, sequence sendEncodings)` will be added to `ConferenceClient`. It invokes `RTCPeerConnection.addTransceiver(trackKind, {direction:inactive, sendEncodings:sendEncodings})`, returns an `RTCRtpTransceiver`. Please note that direction is `inactive` until a `publish` with return transceiver is called. - The second parameter of `ConferenceClient.publish` accepts an `RTCRtpTransceiver` created by `RTCPeerConnection.addTransceiver`. When this method is called, certain `RTCRtpTransceiver`'s direction is changed to `sendonly`, and its sender's `setStreams` is called with the first parameter's `mediaStream`. #### Server Requirements diff --git a/docs/mdfiles/changelog.md b/docs/mdfiles/changelog.md index 15767808..a4ded8a2 100644 --- a/docs/mdfiles/changelog.md +++ b/docs/mdfiles/changelog.md @@ -2,8 +2,8 @@ Change Log ========== # 5.1 * When subscribe a stream in conference mode, the subscribed MediaStream or BidirectionalStream is associated with a `Owt.Conference.Subscription` instead of a `Owt.Base.RemoteStream`. The `stream` property of a RemoteStream in conference mode is always undefined, while a new property `stream` is added to `Subscription`. It allows a RemoteStream to be subscribed multiple times, as well as subscribing audio and video tracks from different streams. -* Add a new property `senders` to `Publication` for getting `RTCRtpSender`s. -* Add a new property `receivers` to `Subscription` for getting `RTCRtpReceiver`s. +* Add a new property `transport` to `Publication` for getting `TransportSettings`. +* Add a new property `rtpTransceivers` to `TransportSettings` and `TransportConstraints`. # 5.0 * Add WebTransport support for conference mode, see [this design doc](../../design/webtransport.md) for detailed information. * All publications and subscriptions for the same conference use the same `PeerConnection`. diff --git a/src/sdk/base/publication.js b/src/sdk/base/publication.js index 55ea5f12..7ead125e 100644 --- a/src/sdk/base/publication.js +++ b/src/sdk/base/publication.js @@ -123,7 +123,7 @@ export class PublicationSettings { */ export class Publication extends EventDispatcher { // eslint-disable-next-line require-jsdoc - constructor(id, transceivers, stop, getStats, mute, unmute) { + constructor(id, transport, stop, getStats, mute, unmute) { super(); /** * @member {string} id @@ -136,35 +136,16 @@ export class Publication extends EventDispatcher { value: id ? id : Utils.createUuid(), }); /** - * @member {RTCRtpTransceiver[]} _transceivers - * @instance - * @private - * @desc A list of RTCRtpTransceiver associated with this Publication. For - * each RTCRtpTransceiver, it's `direction` should always be `sendonly`. - * This member is not available in P2P mode. - * @memberof Owt.Base.Publication - * @see {@link https://w3c.github.io/webrtc-pc/#rtcrtptransceiver-interface|RTCRtpTransceiver Interface of WebRTC 1.0}. - */ - Object.defineProperty(this, '_transceivers', { - configurable: false, - writable: false, - value: transceivers, - }); - /** - * @member {RTCRtpSenders[]} senders + * @member {Owt.Base.TransportSettings} transport * @instance * @readonly - * @desc A list of RTCRtpSenders associated with this Publication. This - * member is not available in P2P mode. + * @desc Transport settings for the publication. * @memberof Owt.Base.Publication - * @see {@link https://w3c.github.io/webrtc-pc/#rtcrtpsender-interface|RTCRtpSender Interface of WebRTC 1.0}. */ - Object.defineProperty(this, 'senders', { + Object.defineProperty(this, 'transport', { configurable: false, writable: false, - value: this._transceivers ? - Array.from(this._transceivers, (t) => t.sender) : - undefined, + value: transport, }); /** * @function stop diff --git a/src/sdk/base/transport.js b/src/sdk/base/transport.js index e79afbf4..3bb5a79a 100644 --- a/src/sdk/base/transport.js +++ b/src/sdk/base/transport.js @@ -56,18 +56,29 @@ export class TransportSettings { // eslint-disable-next-line require-jsdoc constructor(type, id) { /** - * @member {Array.} type + * @member {Owt.Base.TransportType} type * @instance - * @memberof Owt.Base.TransportConstraints + * @memberof Owt.Base.TransportSettings * @desc Transport type for publication and subscription. */ this.type = type; /** * @member {string} id * @instance - * @memberof Owt.Base.TransportConstraints + * @memberof Owt.Base.TransportSettings * @desc Transport ID. */ this.id = id; + + /** + * @member {?Array.} rtpTransceivers + * @instance + * @memberof Owt.Base.TransportSettings + * @desc A list of RTCRtpTransceiver associated with the publication or + * subscription. It's only available in conference mode when TransportType + * is webrtc. + * @see {@link https://w3c.github.io/webrtc-pc/#rtcrtptransceiver-interface|RTCRtpTransceiver Interface of WebRTC 1.0}. + */ + this.rtpTransceivers = undefined; } } diff --git a/src/sdk/conference/channel.js b/src/sdk/conference/channel.js index 6b689c0d..e142bfe7 100644 --- a/src/sdk/conference/channel.js +++ b/src/sdk/conference/channel.js @@ -21,6 +21,7 @@ import {Subscription} from './subscription.js'; import {ConferenceError} from './error.js'; import * as Utils from '../base/utils.js'; import * as SdpUtils from '../base/sdputils.js'; +import {TransportSettings, TransportType} from '../base/transport.js'; /** * @class ConferencePeerConnectionChannel @@ -876,11 +877,12 @@ export class ConferencePeerConnectionChannel extends EventDispatcher { const internalId = this._reverseIdMap.get(sessionId); if (this._subscribePromises.has(internalId)) { const mediaStream = this._remoteMediaStreams.get(sessionId); + const transportSettings = + new TransportSettings(TransportType.WEBRTC, this._id); + transportSettings.rtpTransceivers = + this._subscribeTransceivers.get(internalId).transceivers; const subscription = new Subscription( - sessionId, mediaStream, - Array.from( - this._subscribeTransceivers.get(internalId).transceivers, - (t) => t.transceiver), + sessionId, mediaStream, transportSettings, () => { this._unsubscribe(internalId); }, @@ -895,11 +897,13 @@ export class ConferencePeerConnectionChannel extends EventDispatcher { this._subscribePromises.delete(internalId); } } else if (this._publishPromises.has(internalId)) { + const transportSettings = + new TransportSettings(TransportType.WEBRTC, this._id); + transportSettings.transceivers = + this._publishTransceivers.get(internalId).transceivers; const publication = new Publication( sessionId, - Array.from( - this._publishTransceivers.get(internalId).transceivers, - (t) => t.transceiver), + transportSettings, () => { this._unpublish(internalId); return Promise.resolve(); diff --git a/src/sdk/conference/subscription.js b/src/sdk/conference/subscription.js index ced81bf7..f08cfdb6 100644 --- a/src/sdk/conference/subscription.js +++ b/src/sdk/conference/subscription.js @@ -271,7 +271,7 @@ export class SubscriptionUpdateOptions { export class Subscription extends EventDispatcher { // eslint-disable-next-line require-jsdoc constructor( - id, stream, transceivers, stop, getStats, mute, unmute, applyOptions) { + id, stream, transport, stop, getStats, mute, unmute, applyOptions) { super(); if (!id) { throw new TypeError('ID cannot be null or undefined.'); @@ -300,30 +300,16 @@ export class Subscription extends EventDispatcher { value: stream, }); /** - * @member {RTCRtpTransceiver[]} transceivers - * @instance - * @desc A list of RTCRtpTransceiver associated with this Subscription. For - * each RTCRtpTransceiver, it's `direction` should always be `recvonly`. - * @memberof Owt.Base.Subscription - * @see {@link https://w3c.github.io/webrtc-pc/#rtcrtptransceiver-interface|RTCRtpTransceiver Interface of WebRTC 1.0}. - */ - Object.defineProperty(this, '_transceivers', { - configurable: false, - writable: false, - value: transceivers, - }); - /** - * @member {RTCRtpReceivers[]} receivers + * @member {Owt.Base.TransportSettings} transport * @instance * @readonly - * @desc A list of RTCRtpReceivers associated with this Subscription. - * @memberof Owt.Base.Subscription - * @see {@link https://w3c.github.io/webrtc-pc/#rtcrtpreceiver-interface|RTCRtpReceivers Interface of WebRTC 1.0}. + * @desc Transport settings for the publication. + * @memberof Owt.Base.Publication */ - Object.defineProperty(this, 'receivers', { + Object.defineProperty(this, 'transport', { configurable: false, writable: false, - value: Array.from(this._transceivers, (t) => t.receiver), + value: transport, }); /** * @function stop diff --git a/test/unit/resources/scripts/base.js b/test/unit/resources/scripts/base.js index f5463ee4..faf6e921 100644 --- a/test/unit/resources/scripts/base.js +++ b/test/unit/resources/scripts/base.js @@ -184,12 +184,12 @@ describe('Unit tests for SDP utils.', function() { describe('Unit tests for Publication.', () => { it('Get senders returns all transceivers\' sender.', () => { - const audioTransceiver = {sender: new sinon.spy(), receiver: sinon.spy()}; - const videoTransceiver = {sender: new sinon.spy(), receiver: sinon.spy()}; - const publication = new PublicationModule.Publication( - 'sessionId', [audioTransceiver, videoTransceiver]); - expect(publication.senders).to.deep.equal([ - audioTransceiver.sender, videoTransceiver.sender - ]); + it('Get transport returns correct TransportSettings.', () => { + const transportSettings = + new TransportSettings(TransportType.WEBRTC, 'randomId'); + const publication = + new PublicationModule.Publication('sessionId', transportSettings); + expect(publication.transport).to.equal(transportSettings); + }); }); }); \ No newline at end of file diff --git a/test/unit/resources/scripts/conference.js b/test/unit/resources/scripts/conference.js index 50efd629..1913e9be 100644 --- a/test/unit/resources/scripts/conference.js +++ b/test/unit/resources/scripts/conference.js @@ -9,6 +9,7 @@ import {ConferencePeerConnectionChannel} from '../../../../src/sdk/conference/ch import * as StreamModule from '../../../../src/sdk/base/stream.js'; import * as EventModule from '../../../../src/sdk/base/event.js' import * as SubscriptionModule from '../../../../src/sdk/conference/subscription.js' +import { TransportSettings, TransportType } from '../../../../src/sdk/base/transport.js'; const expect = chai.expect; chai.use(chaiAsPromised); @@ -101,13 +102,11 @@ describe('Unit tests for ConferencePeerConnectionChannel.', () => { }); describe('Unit tests for Subscription.', () => { - it('Get receivers returns all transceivers\' receiver.', () => { - const audioTransceiver = {sender: new sinon.spy(), receiver: sinon.spy()}; - const videoTransceiver = {sender: new sinon.spy(), receiver: sinon.spy()}; - const Subscription = new SubscriptionModule.Subscription( - 'sessionId', undefined, [audioTransceiver, videoTransceiver]); - expect(Subscription.receivers).to.deep.equal([ - audioTransceiver.receiver, videoTransceiver.receiver - ]); + it('Get transport returns correct TransportSettings.', () => { + const transportSettings = + new TransportSettings(TransportType.WEBRTC, 'randomId'); + const subscription = new SubscriptionModule.Subscription( + 'sessionId', undefined, transportSettings); + expect(subscription.transport).to.equal(transportSettings); }); }); \ No newline at end of file From 68c15b20a2d228ed6e12520c7fabfe490cafd2af Mon Sep 17 00:00:00 2001 From: Jianjun Zhu Date: Thu, 6 May 2021 10:33:56 +0800 Subject: [PATCH 5/5] Fix a typo. --- src/sdk/conference/subscription.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdk/conference/subscription.js b/src/sdk/conference/subscription.js index f08cfdb6..16676f24 100644 --- a/src/sdk/conference/subscription.js +++ b/src/sdk/conference/subscription.js @@ -303,8 +303,8 @@ export class Subscription extends EventDispatcher { * @member {Owt.Base.TransportSettings} transport * @instance * @readonly - * @desc Transport settings for the publication. - * @memberof Owt.Base.Publication + * @desc Transport settings for the subscription. + * @memberof Owt.Base.Subscription */ Object.defineProperty(this, 'transport', { configurable: false,