Spaces:
Sleeping
Sleeping
Update public/viewer.html
Browse files- public/viewer.html +40 -11
public/viewer.html
CHANGED
|
@@ -1,15 +1,44 @@
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Viewer</title>
|
| 7 |
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"></script>
|
| 8 |
-
<script src='viewer.js'></script>
|
| 9 |
-
</head>
|
| 10 |
<body>
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
</body>
|
| 15 |
</html>
|
|
|
|
| 1 |
+
<!-- consumer.html -->
|
| 2 |
<!DOCTYPE html>
|
| 3 |
+
<html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
<body>
|
| 5 |
+
<h3>Viewer</h3>
|
| 6 |
+
<video id="remoteVideo" autoplay></video>
|
| 7 |
+
<script>
|
| 8 |
+
const ws = new WebSocket('ws://https://pepguy-swarming-1.hf.space');
|
| 9 |
+
let transport, consumer;
|
| 10 |
+
|
| 11 |
+
ws.onmessage = async ({ data }) => {
|
| 12 |
+
const { action, data: d } = JSON.parse(data);
|
| 13 |
+
|
| 14 |
+
if (action === 'consumerTransportCreated') {
|
| 15 |
+
transport = device.createRecvTransport(d);
|
| 16 |
+
transport.on('connect', ({ dtlsParameters }, cb) =>
|
| 17 |
+
ws.send(JSON.stringify({ action: 'connectConsumerTransport', data: { dtlsParameters } })), cb()
|
| 18 |
+
);
|
| 19 |
+
// once connected, ask to consume
|
| 20 |
+
ws.send(JSON.stringify({ action: 'consume' }));
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
if (action === 'consumed') {
|
| 24 |
+
consumer = await transport.consume(d);
|
| 25 |
+
const stream = new MediaStream([consumer.track]);
|
| 26 |
+
document.getElementById('remoteVideo').srcObject = stream;
|
| 27 |
+
}
|
| 28 |
+
};
|
| 29 |
+
|
| 30 |
+
async function start() {
|
| 31 |
+
// load device
|
| 32 |
+
const { rtpCapabilities } = await (await fetch('/rtpCapabilities')).json();
|
| 33 |
+
device = new mediasoupClient.Device();
|
| 34 |
+
await device.load({ routerRtpCapabilities: rtpCapabilities });
|
| 35 |
+
|
| 36 |
+
// create transport
|
| 37 |
+
ws.send(JSON.stringify({ action: 'createConsumerTransport' }));
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
start();
|
| 41 |
+
</script>
|
| 42 |
+
<script src="https://unpkg.com/mediasoup-client@3/lib/index.js"></script>
|
| 43 |
</body>
|
| 44 |
</html>
|