-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlayingComponent.js
112 lines (103 loc) · 3.07 KB
/
PlayingComponent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import React, { useState, useEffect, useRef } from 'react';
import { Button, Container, Row, Col } from 'react-bootstrap';
import 'bootstrap/dist/css/bootstrap.min.css';
import { WebRTCAdaptor } from '@antmedia/webrtc_adaptor';
const PlayingComponent = () => {
const [playing, setPlaying] = useState(false);
const [websocketConnected, setWebsocketConnected] = useState(false);
const [streamId, setStreamId] = useState('stream123');
const webRTCAdaptor = useRef(null);
var playingStream = useRef(null);
const handlePlay = () => {
setPlaying(true);
playingStream.current=streamId
webRTCAdaptor.current.play(streamId);
};
const handleStopPlaying = () => {
setPlaying(false);
webRTCAdaptor.current.stop(playingStream.current);
};
const handleStreamIdChange = (event) => {
setStreamId(event.target.value);
};
useEffect(() => {
if(webRTCAdaptor.current === undefined || webRTCAdaptor.current === null){
webRTCAdaptor.current = new WebRTCAdaptor({
websocket_url: 'wss://test.antmedia.io:/WebRTCAppEE/websocket',
mediaConstraints: {
video: true,
audio: true,
},
peerconnection_config: {
iceServers: [{ urls: 'stun:stun1.l.google.com:19302' }],
},
sdp_constraints: {
OfferToReceiveAudio: true,
OfferToReceiveVideo: true, // Set to true to receive video
},
remoteVideoId: 'remoteVideo',
callback: (info, obj) => {
if (info === 'initialized') {
setWebsocketConnected(true);
}
},
callbackError: function (error, message) {
console.log(error, message);
if (error === 'no_stream_exist'){
handleStopPlaying();
setPlaying(false);
alert(error);
}
},
});
}
}, []);
return (
<Container className="text-center">
<h1>Play Page</h1>
<Row className="mb-4">
<Col>
<video
id="remoteVideo"
controls
autoPlay
muted="muted" playsinline="playsinline"
style={{
width: '40vw',
height: '60vh',
maxWidth: '100%',
maxHeight: '100%',
}}
></video>
</Col>
</Row>
<Row className="justify-content-center">
<Row>
<div className="mb-3">
<input
className="form-control form-control-lg"
type="text"
defaultValue={streamId}
onChange={handleStreamIdChange}
/>
<label className="form-label" htmlFor="streamId">
Enter Stream Id
</label>
</div>
</Row>
<Col>
{!playing ? (
<Button variant="primary" disabled={!websocketConnected} onClick={handlePlay}>
Start Playing
</Button>
) : (
<Button variant="danger" onClick={handleStopPlaying}>
Stop Playing
</Button>
)}
</Col>
</Row>
</Container>
);
};
export default PlayingComponent;