Skip to content

Commit 2f69db7

Browse files
committed
video
1 parent b727374 commit 2f69db7

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

resources/js/Pages/Welcome.vue

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,26 @@ const props = defineProps({
2020
})
2121
const hasStream = ref(false);
2222
const pc = new RTCPeerConnection();
23+
pc.oniceconnectionstatechange = () => {
24+
if (pc.iceConnectionState === "failed") {
25+
pc.restartIce();
26+
}
27+
};
28+
pc.onnegotiationneeded = async () => {
29+
try {
30+
await pc.setLocalDescription();
31+
//signaler.send({ description: pc.localDescription });
32+
} catch (err) {
33+
console.error(err);
34+
} finally {
35+
}
36+
};
2337
const stream = ref(null);
24-
const srcObject = ref(new MediaStream())
25-
const grantPermissions = async (evt, constraints = {audio: true, video: false}) => {
38+
const grantPermissions = async (evt, constraints = {video: true, video: true}) => {
2639
try {
27-
console.log(constraints)
2840
stream.value= await navigator.mediaDevices.getUserMedia(constraints);
2941
for (const track of stream.value.getTracks()) {
30-
pc.addTrack(track);
42+
pc.addTrack(track, stream.value);
3143
}
3244
hasStream.value = true
3345
/* use the stream */
@@ -87,12 +99,10 @@ pc.ondatachannel = (e) => {
8799
pc.ontrack = (e) => {
88100
console.log('New track', e)
89101
;
90-
srcObject.value.addTrack(e.track);
91-
console.log(srcObject)
92-
const audio = document.getElementById('audio');
93-
audio.srcObject = srcObject.value
94-
audio.play()
95-
console.log(audio.srcObject)
102+
const video = document.getElementById('caller_video');
103+
video.srcObject = e.streams[0]
104+
video.play()
105+
console.log(video.srcObject)
96106
}
97107
onMounted(() => {
98108
@@ -104,6 +114,7 @@ onMounted(() => {
104114
const session = notification.sdp;
105115
session.sdp += "\n";
106116
pc.setRemoteDescription(session);
117+
console.log('START CALLS')
107118
await answer(notification.caller_id)
108119
console.log(pc)
109120
break;
@@ -119,7 +130,7 @@ onMounted(() => {
119130
</script>
120131

121132
<template>
122-
<Head title="Welcome" />
133+
<Head title="WebRTC Laravel Echo Demo" />
123134
<div class="bg-gray-50 text-black/50 dark:bg-black dark:text-white/50">
124135
<img
125136
id="background"
@@ -210,13 +221,13 @@ onMounted(() => {
210221
</form>
211222

212223
<PrimaryButton
213-
class="ms-4"
224+
class="mt-2"
214225
@click="grantPermissions"
215226
v-if="!hasStream"
216227
>
217228
Grant Permissions
218229
</PrimaryButton>
219-
<audio id="audio" controls></audio>
230+
<video class="mt-2" id="caller_video"></video>
220231
</p>
221232

222233

0 commit comments

Comments
 (0)