Pepguy commited on
Commit
25ed14d
·
verified ·
1 Parent(s): 6539139

Update public/index.html

Browse files
Files changed (1) hide show
  1. public/index.html +44 -10
public/index.html CHANGED
@@ -1,14 +1,48 @@
 
1
  <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Document</title>
7
- <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"></script>
8
- <script src='index.js'></script>
9
- </head>
10
  <body>
11
- <button id='my-button'>Start Stream</button>
12
- <video autoplay id="video"></video>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  </body>
14
  </html>
 
1
+ <!-- producer.html -->
2
  <!DOCTYPE html>
3
+ <html>
 
 
 
 
 
 
 
4
  <body>
5
+ <h3>Broadcaster</h3>
6
+ <video id="localVideo" autoplay muted></video>
7
+ <script>
8
+ const ws = new WebSocket('ws://localhost:3000');
9
+ let transport, producer;
10
+
11
+ ws.onmessage = async ({ data }) => {
12
+ const { action, data: d } = JSON.parse(data);
13
+
14
+ if (action === 'producerTransportCreated') {
15
+ transport = device.createSendTransport(d);
16
+ transport.on('connect', ({ dtlsParameters }, cb) =>
17
+ ws.send(JSON.stringify({ action: 'connectProducerTransport', data: { dtlsParameters } })), cb()
18
+ );
19
+ transport.on('produce', ({ kind, rtpParameters }, cb) =>
20
+ ws.send(JSON.stringify({ action: 'produce', data: { kind, rtpParameters } })), cb({ id: '' })
21
+ );
22
+ }
23
+
24
+ if (action === 'produced') {
25
+ console.log('Producer ready:', d.producerId);
26
+ }
27
+ };
28
+
29
+ async function start() {
30
+ // 1) getUserMedia
31
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
32
+ document.getElementById('localVideo').srcObject = stream;
33
+
34
+ // 2) load device RTP capabilities
35
+ ws.send(JSON.stringify({ action: 'createProducerTransport' }));
36
+ const { rtpCapabilities } = await (await fetch('/rtpCapabilities')).json();
37
+ device = new mediasoupClient.Device();
38
+ await device.load({ routerRtpCapabilities: rtpCapabilities });
39
+
40
+ // 3) wait for transport then produce
41
+ stream.getTracks().forEach(track => transport.produce({ track }));
42
+ }
43
+
44
+ start();
45
+ </script>
46
+ <script src="https://unpkg.com/mediasoup-client@3/lib/index.js"></script>
47
  </body>
48
  </html>