|
| 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