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

Commit 0ab3437

Browse files
committed
Modifying SDK for QUIC.
1 parent d48c3e7 commit 0ab3437

File tree

4 files changed

+125
-211
lines changed

4 files changed

+125
-211
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
'use strict';
66

7-
// const conference = new Owt.Conference.ConferenceClient();
8-
let quicTransport = null;
7+
let quicChannel = null;
98
let bidirectionalStream = null;
109
let writeTask;
1110
const conference=new Owt.Conference.ConferenceClient();
@@ -29,8 +28,10 @@ function joinConference() {
2928
};
3029

3130
function createQuicTransport() {
31+
quicChannel = conference.createQuicChannel();
32+
return;
3233
quicTransport = new QuicTransport(
33-
'quic-transport://jianjunz-nuc-ubuntu.sh.intel.com:7700/echo');
34+
'quic-transport://jianjunz-nuc-ubuntu.sh.intel.com:7700/echo');
3435
quicTransport.onstatechange = () => {
3536
console.log('QuicTransport state changed.');
3637
};
@@ -47,7 +48,7 @@ function createRandomContentSessionId() {
4748
}
4849

4950
async function createSendChannel() {
50-
bidirectionalStream = await quicTransport.createSendStream();
51+
bidirectionalStream = await quicChannel.createSendStream();
5152
updateConferenceStatus('Created send channel.');
5253
}
5354

src/sdk/conference/client.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as StreamModule from '../base/stream.js'
1616
import { Participant } from './participant.js'
1717
import { ConferenceInfo } from './info.js'
1818
import { ConferencePeerConnectionChannel, ConferenceQuicChannel } from './channel.js'
19-
import { ConferenceDataChannel } from './datachannel.js'
19+
import { QuicChannel } from './quicchannel.js'
2020
import { RemoteMixedStream, ActiveAudioInputChangeEvent, LayoutChangeEvent } from './mixedstream.js'
2121
import * as StreamUtilsModule from './streamutils.js'
2222
import { timingSafeEqual, createSign } from 'crypto';
@@ -113,9 +113,7 @@ export const ConferenceClient = function(config, signalingImpl) {
113113
const participants = new Map(); // Key is participant ID, value is a Participant object.
114114
const publishChannels = new Map(); // Key is MediaStream's ID, value is pc channel.
115115
const channels = new Map(); // Key is channel's internal ID, value is channel.
116-
let dataChannel = null;
117-
let dataChannelId = null;
118-
let incomingDataChannels = new Map(); // TODO: Mutiplexing.
116+
const quicTransportChannels = [];
119117

120118
/**
121119
* @function onSignalingMessage
@@ -491,11 +489,11 @@ export const ConferenceClient = function(config, signalingImpl) {
491489
* @desc Create a bidirectional stream.
492490
* @return {Promise<void, Error>} Returned promise will be resolved with a bidirectional stream once stream is created.
493491
*/
494-
this.createDataStream = function() {
495-
dataChannel = createDataChannel();
496-
dataChannel.addEventListener('id', (messageEvent) => {
497-
dataChannelId = messageEvent.message;
498-
});
499-
return dataChannel.createStream();
492+
this.createQuicChannel = function() {
493+
const quicChannel = new QuicChannel(
494+
'quic-transport://jianjunz-nuc-ubuntu.sh.intel.com:7700/echo',
495+
createSignalingForChannel());
496+
quicTransportChannels.push(quicChannel);
497+
return quicChannel;
500498
};
501499
};

src/sdk/conference/datachannel.js

Lines changed: 0 additions & 197 deletions
This file was deleted.

src/sdk/conference/quicchannel.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright (C) <2018> Intel Corporation
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
/* eslint-disable require-jsdoc */
6+
/* global Promise */
7+
8+
'use strict';
9+
10+
import Logger from '../base/logger.js';
11+
import {
12+
EventDispatcher,
13+
MessageEvent,
14+
} from '../base/event.js';
15+
16+
/**
17+
* @class QuicChannel
18+
* @classDesc A channel for a QUIC transport between client and conference server.
19+
* @hideconstructor
20+
* @private
21+
*/
22+
export class QuicChannel extends EventDispatcher {
23+
constructor(url, signaling) {
24+
super();
25+
this._signaling = signaling;
26+
this._ended = false;
27+
this._quicStreams = new Map(); // Key is publication or subscription ID.
28+
this._quicTransport = new QuicTransport(url);
29+
}
30+
31+
/**
32+
* @function onMessage
33+
* @desc Received a message from conference portal. Defined in client-server protocol.
34+
* @param {string} notification Notification type.
35+
* @param {object} message Message received.
36+
* @private
37+
*/
38+
onMessage(notification, message) {
39+
switch (notification) {
40+
case 'progress':
41+
if (message.status === 'soac') {
42+
this._soacHandler(message.data);
43+
} else if (message.status === 'ready') {
44+
this._readyHandler();
45+
} else if (message.status === 'error') {
46+
this._errorHandler(message.data);
47+
}
48+
break;
49+
case 'stream':
50+
this._onStreamEvent(message);
51+
break;
52+
default:
53+
Logger.warning('Unknown notification from MCU.');
54+
}
55+
}
56+
57+
async createSendStream(sessionId) {
58+
Logger.info('Create stream.');
59+
await this._quicTransport.ready;
60+
const quicStream=this._quicTransport.createSendStream();
61+
const publicationId=await this._initializePublication();
62+
// Send publication ID to quicStream.
63+
}
64+
65+
/**
66+
* @function createStream
67+
* @desc Create a bidirectional stream.
68+
* @param {string} sessionId Publication or subscription ID.
69+
* @private
70+
*/
71+
createStream(sessionId) {
72+
Logger.info('Create stream.');
73+
if (this._quicTransport && this._quicTransport.state == 'connected') {
74+
this._quicStreams.push(stream);
75+
return Promise.resolve(stream);
76+
}
77+
if (!this._quicTransport) {
78+
this._initialize();
79+
}
80+
return new Promise((resolve, reject) => {
81+
this._createStreamPromise = {
82+
resolve: resolve,
83+
reject: reject
84+
};
85+
});
86+
}
87+
88+
subscribe(stream) {
89+
this._outgoing=false;
90+
this._streamSubscribed = stream;
91+
if (!this._quicTransport) {
92+
this.createStream();
93+
}
94+
}
95+
96+
_readAndPrint(){
97+
this._quicStreams[0].waitForReadable(5).then(()=>{
98+
let data = new Uint8Array(this._quicStreams[0].readBufferedAmount);
99+
this._quicStreams[0].readInto(data);
100+
Logger.info('Read data: ' + data);
101+
this._readAndPrint();
102+
});
103+
}
104+
105+
async _initializePublication() {
106+
const data = await this._signaling.sendSignalingMessage('publish', {
107+
media: null,
108+
data: true
109+
});
110+
return data.id;
111+
}
112+
};

0 commit comments

Comments
 (0)