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

Commit 9580b1b

Browse files
committed
Add transport info in publication and subscription.
1 parent ee2ec0a commit 9580b1b

File tree

8 files changed

+127
-19
lines changed

8 files changed

+127
-19
lines changed

scripts/Gruntfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ window.L = L;\n\
5252
},
5353
transform: [
5454
["babelify", {
55-
"presets": ["@babel/preset-env"]
55+
"presets": ["@babel/preset-env"],
56+
"plugins": ["@babel/plugin-transform-runtime"]
5657
}]
5758
]
5859
},

src/samples/conference/public/scripts/quic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ conference.addEventListener('streamadded', async (event) => {
2626

2727
function updateConferenceStatus(message) {
2828
document.getElementById('conference-status').innerHTML +=
29-
('<p>' + message + '</p>');
29+
('<p>' + message + '</p>');
3030
}
3131

3232

@@ -104,7 +104,7 @@ document.getElementById('start-sending').addEventListener('click', async () => {
104104
return;
105105
}
106106
await writeUuid();
107-
// writeTask = setInterval(writeData, 500);
107+
writeTask = setInterval(writeData, 2000);
108108
updateConferenceStatus('Started sending.');
109109
});
110110

src/sdk/base/export.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
export * from './mediastream-factory.js';
88
export * from './stream.js';
99
export * from './mediaformat.js';
10+
export * from './transport.js';

src/sdk/base/publication.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class Publication extends EventDispatcher {
180180
*/
181181
export class PublishOptions {
182182
// eslint-disable-next-line require-jsdoc
183-
constructor(audio, video) {
183+
constructor(audio, video, transport) {
184184
/**
185185
* @member {?Array<Owt.Base.AudioEncodingParameters> | ?Array<RTCRtpEncodingParameters>} audio
186186
* @instance
@@ -195,5 +195,11 @@ export class PublishOptions {
195195
* @desc Parameters for video RtpSender. Publishing with RTCRtpEncodingParameters is an experimental feature. It is subject to change.
196196
*/
197197
this.video = video;
198+
/**
199+
* @member {?Owt.Base.TransportConstraints} transport
200+
* @instance
201+
* @memberof Owt.Base.PublishOptions
202+
*/
203+
this.transport = transport;
198204
}
199205
}

src/sdk/base/transport.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (C) <2020> Intel Corporation
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
'use strict';
6+
7+
/**
8+
* @class TransportType
9+
* @memberOf Owt.Base
10+
* @classDesc Transport type enumeration.
11+
* @hideconstructor
12+
*/
13+
export const TransportType = {
14+
QUIC: 'quic',
15+
WEBRTC: 'webrtc',
16+
};
17+
18+
/**
19+
* @class TransportConstraints
20+
* @memberOf Owt.Base
21+
* @classDesc Represents the transport constraints for publication and
22+
* subscription.
23+
* @hideconstructor
24+
*/
25+
export class TransportConstraints {
26+
// eslint-disable-next-line require-jsdoc
27+
constructor(type, id) {
28+
/**
29+
* @member {Array.<Owt.Base.TransportType>} type
30+
* @instance
31+
* @memberof Owt.Base.TransportConstraints
32+
* @desc Transport type for publication and subscription.
33+
*/
34+
this.type = type;
35+
/**
36+
* @member {?string} id
37+
* @instance
38+
* @memberof Owt.Base.TransportConstraints
39+
* @desc Transport ID. Undefined transport ID results server to assign a new
40+
* one. It should always be undefined if transport type is webrtc since the
41+
* webrtc agent of OWT server doesn't support multiple transceivers on a
42+
* single PeerConnection.
43+
*/
44+
this.id = id;
45+
}
46+
}
47+
48+
/**
49+
* @class TransportSettings
50+
* @memberOf Owt.Base
51+
* @classDesc Represents the transport settings for publication and
52+
* subscription.
53+
* @hideconstructor
54+
*/
55+
export class TransportSettings {
56+
// eslint-disable-next-line require-jsdoc
57+
constructor(type, id) {
58+
/**
59+
* @member {Array.<Owt.Base.TransportType>} type
60+
* @instance
61+
* @memberof Owt.Base.TransportConstraints
62+
* @desc Transport type for publication and subscription.
63+
*/
64+
this.type = type;
65+
/**
66+
* @member {string} id
67+
* @instance
68+
* @memberof Owt.Base.TransportConstraints
69+
* @desc Transport ID.
70+
*/
71+
this.id = id;
72+
}
73+
}

src/sdk/conference/client.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,9 @@ export const ConferenceClient = function(config, signalingImpl) {
488488
*/
489489
this.createQuicConnection = function() {
490490
const quicConnection = new QuicConnection(
491-
'quic-transport://example.com', me.id,
492-
createSignalingForChannel());
493-
quicTransportChannel=quicConnection;
491+
'quic-transport://jianjunz-nuc-ubuntu.sh.intel.com:7700/echo',
492+
createSignalingForChannel());
493+
quicTransportChannel = quicConnection;
494494
return quicConnection;
495495
};
496496
};

src/sdk/conference/quicconnection.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ import {Subscription} from './subscription.js';
2121
* @private
2222
*/
2323
export class QuicConnection extends EventDispatcher {
24-
constructor(url, token, signaling) {
24+
constructor(url, signaling) {
2525
super();
2626
this._signaling = signaling;
2727
this._ended = false;
2828
this._quicStreams = new Map(); // Key is publication or subscription ID.
2929
this._quicTransport = new QuicTransport(url);
3030
this._subscribePromises = new Map(); // Key is subscription ID.
31-
this._init(token);
31+
this._transportId = undefined;
32+
this._init();
3233
}
3334

3435
/**
@@ -57,8 +58,7 @@ export class QuicConnection extends EventDispatcher {
5758
}
5859
}
5960

60-
async _init(token) {
61-
this._authenticate(token);
61+
async _init() {
6262
const receiveStreamReader =
6363
this._quicTransport.receiveStreams().getReader();
6464
Logger.info('Reader: '+receiveStreamReader);
@@ -117,14 +117,16 @@ export class QuicConnection extends EventDispatcher {
117117
async createSendStream(sessionId) {
118118
Logger.info('Create stream.');
119119
await this._quicTransport.ready;
120-
// TODO: Creating quicStream and initializing publication concurrently.
121-
const quicStream = await this._quicTransport.createSendStream();
120+
// TODO: Potential failure because of publication stream is created faster
121+
// than signaling stream(created by the 1st call to initiatePublication).
122122
const publicationId = await this._initiatePublication();
123+
const quicStream = await this._quicTransport.createSendStream();
123124
const writer= quicStream.writable.getWriter();
124125
await writer.ready;
125126
writer.write(this._uuidToUint8Array(publicationId));
126-
writer.write(this._uuidToUint8Array(publicationId));
127+
writer.releaseLock();
127128
this._quicStreams.set(publicationId, quicStream);
129+
return quicStream;
128130
}
129131

130132
hasContentSessionId(id) {
@@ -178,16 +180,19 @@ export class QuicConnection extends EventDispatcher {
178180
subscribe(stream) {
179181
const p = new Promise((resolve, reject) => {
180182
this._signaling
181-
.sendSignalingMessage(
182-
'subscribe',
183-
{media: null, data: {from: stream.id}, transport: {type: 'quic'}})
183+
.sendSignalingMessage('subscribe', {
184+
media: null,
185+
data: {from: stream.id},
186+
transport: {type: 'quic', id: this._transportId},
187+
})
184188
.then((data) => {
185189
if (this._quicStreams.has(data.id)) {
186190
// QUIC stream created before signaling returns.
187191
const subscription = this._createSubscription(
188192
data.id, this._quicStreams.get(data.id));
189193
resolve(subscription);
190194
} else {
195+
this._quicStreams.set(data.id, null);
191196
// QUIC stream is not created yet, resolve promise after getting
192197
// QUIC stream.
193198
this._subscribePromises.set(
@@ -207,12 +212,28 @@ export class QuicConnection extends EventDispatcher {
207212
});
208213
}
209214

215+
_updateTransportId(id) {
216+
if (this._transportId) {
217+
Logger.error('Update transport ID is not supported.');
218+
return;
219+
}
220+
this._transportId = id;
221+
this._authenticate(id);
222+
}
223+
210224
async _initiatePublication() {
211225
const data = await this._signaling.sendSignalingMessage('publish', {
212226
media: null,
213227
data: true,
214-
transport: {type:'quic'}
228+
transport: {type: 'quic', id: this._transportId},
215229
});
230+
if (data.transportId) {
231+
this._updateTransportId(data.transportId);
232+
} else {
233+
if (this._transportId !== data.transportId) {
234+
throw new Error('Transport ID not match.');
235+
}
236+
}
216237
return data.id;
217238
}
218239

src/sdk/conference/subscription.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export class VideoSubscriptionConstraints {
172172
*/
173173
export class SubscribeOptions {
174174
// eslint-disable-next-line require-jsdoc
175-
constructor(audio, video) {
175+
constructor(audio, video, transport) {
176176
/**
177177
* @member {?Owt.Conference.AudioSubscriptionConstraints} audio
178178
* @instance
@@ -185,6 +185,12 @@ export class SubscribeOptions {
185185
* @memberof Owt.Conference.SubscribeOptions
186186
*/
187187
this.video = video;
188+
/**
189+
* @member {?Owt.Base.TransportConstraints} transport
190+
* @instance
191+
* @memberof Owt.Conference.SubscribeOptions
192+
*/
193+
this.transport = transport;
188194
}
189195
}
190196

0 commit comments

Comments
 (0)