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

Commit 748e215

Browse files
committed
Authentication for WebTransport connections is changed.
1 parent 2e1683d commit 748e215

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

src/sdk/conference/client.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,6 @@ export const ConferenceClient = function(config, signalingImpl) {
346346
* @param {string} tokenString Token is issued by conference server(nuve).
347347
*/
348348
this.join = function(tokenString) {
349-
if (QuicConnection) {
350-
// TODO: Get URL from token.
351-
quicTransportChannel = new QuicConnection(
352-
'quic-transport://jianjunz-nuc-ubuntu.sh.intel.com:7700/echo',
353-
createSignalingForChannel());
354-
}
355349
return new Promise((resolve, reject) => {
356350
const token = JSON.parse(Base64.decodeBase64(tokenString));
357351
const isSecured = (token.secure === true);
@@ -395,6 +389,11 @@ export const ConferenceClient = function(config, signalingImpl) {
395389
}
396390
}
397391
}
392+
if (QuicConnection && token.webTransportUrl) {
393+
quicTransportChannel = new QuicConnection(
394+
token.webTransportUrl, resp.webTransportToken,
395+
createSignalingForChannel());
396+
}
398397
resolve(new ConferenceInfo(resp.room.id, Array.from(participants
399398
.values()), Array.from(remoteStreams.values()), me));
400399
}, (e) => {

src/sdk/conference/quicconnection.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
/* eslint-disable require-jsdoc */
6-
/* global Promise, Map, QuicTransport, Uint8Array, TextEncoder */
6+
/* global Promise, Map, QuicTransport, Uint8Array, Uint32Array, TextEncoder */
77

88
'use strict';
99

1010
import Logger from '../base/logger.js';
1111
import {EventDispatcher} from '../base/event.js';
1212
import {Publication} from '../base/publication.js';
1313
import {Subscription} from './subscription.js';
14+
import {Base64} from '../base/base64.js';
1415

1516
/**
1617
* @class QuicConnection
@@ -20,15 +21,19 @@ import {Subscription} from './subscription.js';
2021
* @private
2122
*/
2223
export class QuicConnection extends EventDispatcher {
23-
constructor(url, signaling) {
24+
// `tokenString` is a base64 string of the token object. It's in the return
25+
// value of `ConferenceClient.join`.
26+
constructor(url, tokenString, signaling) {
2427
super();
28+
this._token = JSON.parse(Base64.decodeBase64(tokenString));
2529
this._signaling = signaling;
2630
this._ended = false;
2731
this._quicStreams = new Map(); // Key is publication or subscription ID.
2832
this._quicTransport = new QuicTransport(url);
2933
this._subscribePromises = new Map(); // Key is subscription ID.
30-
this._transportId = undefined;
34+
this._transportId = this._token.transportId;
3135
this._init();
36+
this._authenticate(tokenString);
3237
}
3338

3439
/**
@@ -106,10 +111,14 @@ export class QuicConnection extends EventDispatcher {
106111
const quicStream = await this._quicTransport.createSendStream();
107112
const writer = quicStream.writable.getWriter();
108113
await writer.ready;
114+
// 128 bit of zero indicates this is a stream for signaling.
109115
writer.write(new Uint8Array(16));
116+
// Send token as described in
117+
// https://github.com/open-webrtc-toolkit/owt-server/blob/20e8aad216cc446095f63c409339c34c7ee770ee/doc/design/quic-transport-payload-format.md.
110118
const encoder = new TextEncoder();
111-
writer.write(encoder.encode(token));
112-
Logger.info('End of auth.');
119+
const encodedToken = encoder.encode(token);
120+
writer.write(Uint32Array.of(encodedToken.length));
121+
writer.write(encodedToken);
113122
}
114123

115124
async createSendStream() {
@@ -214,27 +223,14 @@ export class QuicConnection extends EventDispatcher {
214223
});
215224
}
216225

217-
async _updateTransportId(id) {
218-
if (this._transportId) {
219-
Logger.error('Update transport ID is not supported.');
220-
return;
221-
}
222-
this._transportId = id;
223-
await this._authenticate(id);
224-
}
225-
226226
async _initiatePublication() {
227227
const data = await this._signaling.sendSignalingMessage('publish', {
228228
media: null,
229229
data: true,
230230
transport: {type: 'quic', id: this._transportId},
231231
});
232-
if (data.transportId) {
233-
await this._updateTransportId(data.transportId);
234-
} else {
235-
if (this._transportId !== data.transportId) {
236-
throw new Error('Transport ID not match.');
237-
}
232+
if (this._transportId !== data.transportId) {
233+
throw new Error('Transport ID not match.');
238234
}
239235
return data.id;
240236
}

0 commit comments

Comments
 (0)