Skip to content

Commit

Permalink
fix(streaming): stream accept audio and video
Browse files Browse the repository at this point in the history
  • Loading branch information
chukitipok committed Jul 1, 2022
1 parent 3130e82 commit 44299e6
Showing 1 changed file with 21 additions and 46 deletions.
67 changes: 21 additions & 46 deletions src/components/Streaming/Streaming.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ export const Streaming = () => {
try {
const mediaStream = await navigator.mediaDevices.getUserMedia({
video: true,
audio: false,
audio: true,
});

const video = videoSelf.current;
video!.srcObject = mediaStream;
await video!.play();

if (!mediaStream || !video) {
console.log(mediaStream, video);
return;
} // todo: display error

video.srcObject = mediaStream;
await video.play();

const sp = new SimplePeer({
trickle: false,
Expand All @@ -58,62 +64,31 @@ export const Streaming = () => {
credential: 'somepassword',
},
],
iceTransportPolicy: 'relay',
},
});

if (isInitiator) setConnectionStatus(ConnectionStatus.OFFERING);
else offer && sp.signal(offer);
isInitiator
? setConnectionStatus(ConnectionStatus.OFFERING)
: offer && sp.signal(offer);

sp.on('signal', (data) => webSocketConnection.send(JSON.stringify(data)));
sp.on('connect', () => setConnectionStatus(ConnectionStatus.CONNECTED));
sp.on('stream', async (stream) => {
const video = videoCaller.current;
video!.srcObject = stream;
await video!.play();

if (!mediaStream || !video) {
console.error(mediaStream, video);
return;
} // todo: display error

video.srcObject = stream;
await video.play();
});
setSimplePeer(sp);
} catch (e) {
console.error(e);
}

// .then(async (mediaStream) => {
// const video = videoSelf.current;
// video!.srcObject = mediaStream;
// await video!.play();
//
// const sp = new SimplePeer({
// trickle: false,
// initiator: isInitiator,
// stream: mediaStream,
// config: {
// iceServers: [
// { urls: ['stun:stun.siwiorek.fr'] },
// {
// username: 'guest',
// credential: 'somepassword',
// urls: [
// 'turn:turn.siwiorek.fr?transport=tcp',
// 'turn:turn.siwiorek.fr?transport=udp',
// ],
// },
// ],
// },
// });
//
// if (isInitiator) setConnectionStatus(ConnectionStatus.OFFERING);
// else offer && sp.signal(offer);
//
// sp.on('signal', (data) =>
// webSocketConnection.send(JSON.stringify(data)),
// );
// sp.on('connect', () => setConnectionStatus(ConnectionStatus.CONNECTED));
// sp.on('stream', async (stream) => {
// const video = videoCaller.current;
// video!.srcObject = stream;
// await video!.play();
// });
// setSimplePeer(sp);
// });
};

return (
Expand Down

0 comments on commit 44299e6

Please sign in to comment.