Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/design/owt_with_webrtc_apis.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OWT SDK with WebRTC APIs
## Introduction
OWT(Open WebRTC Toolkit) Client SDKs provide convenient APIs to create, publish, and subscribe streams. Most of these APIs are wrappers of WebRTC APIs with signaling support. It helps WebRTC beginners easily involve WebRTC technology into their applications without too much knowledge of WebRTC evolution and browser differences. As WebRTC 1.0 is moving to PR, which means it is quite stable, we are planning to expose more WebRTC APIs to developers to enable advanced and custom usages with OWT.
OWT(Open WebRTC Toolkit) Client SDKs provide convenient APIs to create, publish, and subscribe streams. Most of these APIs are wrappers of WebRTC APIs with signaling support. It helps WebRTC beginners easily involve WebRTC technology into their applications without too much knowledge of WebRTC evolution and browser differences. As WebRTC 1.0 was officially made a W3C Recommendation, which means it is stable, we are planning to expose more WebRTC APIs to developers to enable advanced and custom usages with OWT.
## Potential Usages
- Replace a track in the middle of a call.
- Set custom encoding parameters, perhaps for simulcast.
Expand Down
24 changes: 22 additions & 2 deletions src/sdk/p2p/p2pclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,28 @@ const P2PClient = function(configuration, signalingChannel) {
return channels.get(remoteId).getStats();
};

const sendSignalingMessage = function(
remoteId, connectionId, type, message) {
/**
* @function getPeerConnection
* @instance
* @desc Get underlying PeerConnection.
* @memberof Owt.P2P.P2PClient
* @param {string} remoteId Remote endpoint's ID.
* @return {Promise<RTCPeerConnection, Error>} It returns a promise resolved
* with an RTCPeerConnection or reject with an Error if there is no
* connection with specific user.
* @private
*/
this.getPeerConnection = function(remoteId) {
if (!channels.has(remoteId)) {
return Promise.reject(new ErrorModule.P2PError(
ErrorModule.errors.P2P_CLIENT_INVALID_STATE,
'No PeerConnection between current endpoint and specific remote ' +
'endpoint.'));
}
return channels.get(remoteId).peerConnection;
};

const sendSignalingMessage = function(remoteId, connectionId, type, message) {
const msg = {
type,
connectionId,
Expand Down
22 changes: 19 additions & 3 deletions src/sdk/p2p/peerconnection-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as Utils from '../base/utils.js';
import * as ErrorModule from './error.js';
import * as StreamModule from '../base/stream.js';
import * as SdpUtils from '../base/sdputils.js';
import {TransportSettings, TransportType} from '../base/transport.js';

/**
* @class P2PPeerConnectionChannelEvent
Expand Down Expand Up @@ -100,6 +101,10 @@ class P2PPeerConnectionChannel extends EventDispatcher {
this._sendUa(sysInfo);
}

get peerConnection() {
return this._pc;
}

/**
* @function publish
* @desc Publish a stream to the remote endpoint.
Expand Down Expand Up @@ -288,7 +293,7 @@ class P2PPeerConnectionChannel extends EventDispatcher {
_tracksAddedHandler(ids) {
// Currently, |ids| contains all track IDs of a MediaStream. Following algorithm also handles |ids| is a part of a MediaStream's tracks.
for (const id of ids) {
// It could be a problem if there is a track published with different MediaStreams.
// It could be a problem if there is a track published with different MediaStreams, moving to mid.
this._publishingStreamTracks.forEach((mediaTrackIds, mediaStreamId) => {
for (let i = 0; i < mediaTrackIds.length; i++) {
if (mediaTrackIds[i] === id) {
Expand All @@ -311,9 +316,20 @@ class P2PPeerConnectionChannel extends EventDispatcher {
(element) => element.mediaStream.id == mediaStreamId);
const targetStream = this._publishingStreams[targetStreamIndex];
this._publishingStreams.splice(targetStreamIndex, 1);
// TODO: Set transceivers for Publication.

// Set transceivers for Publication.
const transport =
new TransportSettings(TransportType.WEBRTC, undefined);
transport.rtpTransceivers = [];
for (const transceiver of this._pc.getTransceivers()) {
if (transceiver.sender?.track in
this._publishedStreamTracks.get(mediaStreamId)) {
transport.rtpTransceivers.push(transceiver);
}
}

const publication = new Publication(
id, undefined, () => {
id, transport, () => {
this._unpublish(targetStream).then(() => {
publication.dispatchEvent(new OwtEvent('ended'));
}, (err) => {
Expand Down
7 changes: 6 additions & 1 deletion test/unit/resources/scripts/p2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import P2PClient from '../../../../src/sdk/p2p/p2pclient.js';
import SignalingChannel from './fake-p2p-signaling.js';
import * as StreamModule from '../../../../src/sdk/base/stream.js';
import * as EventModule from '../../../../src/sdk/base/event.js'
import * as EventModule from '../../../../src/sdk/base/event.js';
import {TransportSettings, TransportType} from '../../../../src/sdk/base/transport.js';

const expect = chai.expect;
const screenSharingExtensionId = 'jniliohjdiikfjjdlpapmngebedgigjn';
Expand Down Expand Up @@ -118,6 +119,10 @@ describe('Unit tests for P2PClient', function() {
p2pclient1.getStats('user2').then((stats)=>{
console.info('Stats: '+JSON.stringify(stats));
});
expect(p2pclient1.getPeerConnection('user2'))
.to.be.an.instanceof(RTCPeerConnection);
expect(publication.transport.type === TransportType.WEBRTC);
expect(publication.transport.rtpTransceivers.length === 1);
expect(publication.stop()).to.be.undefined;
done();
});
Expand Down