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

Commit 302b79b

Browse files
committed
Add a sample for QUIC transport.
1 parent ed7c545 commit 302b79b

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!--
2+
Copyright (C) <2020> Intel Corporation
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
-->
6+
7+
<html>
8+
<meta charset="utf-8">
9+
10+
<head>
11+
<title>Open WebRTC Toolkit QUIC Sample</title>
12+
<style>
13+
html {
14+
font-family: "intel-clear", "tahoma", Helvetica, "helvetica", Arial, sans-serif;
15+
font-size: 90%;
16+
}
17+
18+
.operations {
19+
padding: 1em 0;
20+
}
21+
</style>
22+
</head>
23+
24+
<body>
25+
<h1>Open WebRTC Toolkit</h1>
26+
<h2>Sample of QuicTransport</h2>
27+
<div id="description">
28+
<p>This sample works with the latest Chrome.</p>
29+
</div>
30+
<div class="operations">
31+
<button id="start-sending">Start sending</button>
32+
<button id="stop-sending">Stop sending</button>
33+
</div>
34+
<div id="conference-status"></div>
35+
<div class="stats">
36+
</div>
37+
<script src="scripts/quic.js" type="text/javascript"></script>
38+
</body>
39+
40+
</html>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (C) <2020> Intel Corporation
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
'use strict';
6+
7+
//const conference = new Owt.Conference.ConferenceClient();
8+
let quicTransport=null;
9+
let bidirectionalStream = null;
10+
let writeTask;
11+
12+
function updateConferenceStatus(message) {
13+
document.getElementById('conference-status').innerHTML +=
14+
('<p>' + message + '</p>');
15+
}
16+
17+
18+
function joinConference() {
19+
const host = 'http://' + document.location.hostname + ':3001';
20+
return new Promise((resolve, reject) => {
21+
createToken(undefined, 'user', 'presenter', resp => {
22+
conference.join(resp).then(() => {
23+
updateConferenceStatus('Connected to conference server.');
24+
resolve();
25+
});
26+
}, host);
27+
});
28+
};
29+
30+
function createQuicTransport(){
31+
quicTransport= new QuicTransport('quic-transport://jianjunz-nuc-ubuntu.sh.intel.com:7700/echo');
32+
quicTransport.onstatechange=()=>{
33+
console.log('QuicTransport state changed.');
34+
};
35+
return quicTransport.ready;
36+
}
37+
38+
async function createSendChannel() {
39+
bidirectionalStream = await quicTransport.createSendStream();
40+
updateConferenceStatus('Created send channel.');
41+
}
42+
43+
async function windowOnLoad() {
44+
//await joinConference();
45+
await createQuicTransport();
46+
await createSendChannel();
47+
}
48+
49+
async function writeData() {
50+
const encoder = new TextEncoder();
51+
const encoded = encoder.encode('message', {stream: true});
52+
const writer = bidirectionalStream.writable.getWriter();
53+
await writer.ready;
54+
await writer.write(new ArrayBuffer(90000000));
55+
writer.releaseLock();
56+
return;
57+
}
58+
59+
window.addEventListener('load', () => {
60+
windowOnLoad();
61+
});
62+
63+
document.getElementById('start-sending').addEventListener('click', () => {
64+
if (!bidirectionalStream) {
65+
updateConferenceStatus('Stream is not created.');
66+
return;
67+
}
68+
writeTask = setInterval(writeData, 500);
69+
updateConferenceStatus('Started sending.');
70+
});
71+
72+
document.getElementById('stop-sending').addEventListener('click', () => {
73+
clearInterval(writeTask);
74+
updateConferenceStatus('Stopped sending.');
75+
});

0 commit comments

Comments
 (0)