Skip to content

Commit 04b188e

Browse files
authored
Merge pull request #517 from ruxailab/ScreenShare
Screen share
2 parents f03184a + 06b1be8 commit 04b188e

File tree

6 files changed

+297
-303
lines changed

6 files changed

+297
-303
lines changed

public/R.png

19 KB
Loading

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8" />
55
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
66
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
7-
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
7+
<link rel="icon" href="<%= BASE_URL %>R.png" />
88
<title><%= htmlWebpackPlugin.options.title %></title>
99
<link
1010
rel="stylesheet"
Lines changed: 57 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
11
<template>
22
<v-row>
3-
<v-col class="mt-8" cols="12">
4-
<video ref="remoteVideo" class="video" autoplay playsinline />
5-
<video
6-
ref="localVideo"
7-
class="video ml-8"
8-
style="height: 10vw"
9-
muted
10-
autoplay
11-
playsinline
12-
/>
3+
<v-col class="mt-8" cols="8">
4+
<video ref="remoteMedia" class="video" muted autoplay playsinline />
5+
</v-col>
6+
<v-col class="mt-8" cols="4">
7+
<video ref="localMedia" class="video" muted autoplay playsinline />
138
</v-col>
149
<v-col cols="12">
1510
<v-row justify="center">
1611
<v-btn
17-
v-if="localStream"
18-
disabled
19-
class="mt-4 mx-2"
20-
:dark="isSharingScreen"
21-
:class="{ red: isSharingScreen, ' ': !isSharingScreen }"
22-
fab
23-
@click="toggleScreen()"
24-
>
25-
<v-icon v-if="!isSharingScreen">
26-
mdi-monitor-screenshot
27-
</v-icon>
28-
<v-icon v-else>
29-
mdi-monitor-off
30-
</v-icon>
31-
</v-btn>
32-
<v-btn
33-
v-if="localStream"
12+
v-if="localCameraStream"
3413
class="mt-4 mx-2"
3514
:dark="isMicrophoneMuted"
3615
:class="{ red: isMicrophoneMuted, white: !isMicrophoneMuted }"
@@ -44,28 +23,18 @@
4423
mdi-microphone-off
4524
</v-icon>
4625
</v-btn>
47-
<!-- <v-btn
48-
v-if="localStream"
49-
class="mt-4 mx-2"
50-
dark
51-
color="red"
52-
fab
53-
@click="hangUp()"
26+
<v-btn class="mt-4 mx-2 white" fab @click="toggleCameraScreen">
27+
<v-icon>
28+
mdi-monitor-screenshot
29+
</v-icon></v-btn
5430
>
55-
<v-icon>mdi-phone-hangup</v-icon>
56-
</v-btn> -->
5731
</v-row>
5832
</v-col>
59-
<VideoCall ref="VideoCall" />
6033
</v-row>
6134
</template>
6235

6336
<script>
64-
import VideoCall from './VideoCall.vue'
6537
export default {
66-
components: {
67-
VideoCall,
68-
},
6938
props: {
7039
isAdmin: {
7140
type: Boolean,
@@ -80,48 +49,73 @@ export default {
8049
hide: true,
8150
isMicrophoneMuted: false,
8251
isSharingScreen: false,
52+
usingCamera: true,
8353
}
8454
},
85-
8655
computed: {
87-
localStream() {
88-
return this.$store.getters.localStream
56+
localCameraStream() {
57+
return this.$store.getters.localCameraStream
8958
},
90-
remoteStream() {
91-
return this.$store.getters.remoteStream
59+
remoteCameraStream() {
60+
return this.$store.getters.remoteCameraStream
9261
},
9362
roomTestId() {
9463
return this.$store.getters.test.id
9564
},
65+
peerConnection() {
66+
return this.$store.getters.peerConnection
67+
},
9668
},
9769
mounted() {
9870
this.setupStreams()
9971
},
100-
methods: {
101-
async toggleScreen() {
102-
if (!this.isSharingScreen) {
103-
await this.$refs.VideoCall.switchMediaStream()
104-
this.isSharingScreen = true
105-
this.setupStreams()
106-
} else if (this.isSharingScreen) {
107-
this.isSharingScreen = false
108-
this.setupStreams()
109-
this.$refs.VideoCall.joinRoomById(this.roomTestId)
110-
}
72+
watch: {
73+
localCameraStream(newVal) {
74+
this.setupStreams()
75+
},
76+
remoteCameraStream(newVal) {
77+
this.setupStreams()
11178
},
79+
},
80+
methods: {
11281
setupStreams() {
113-
this.$refs.localVideo.srcObject = this.localStream
114-
this.$refs.remoteVideo.srcObject = this.remoteStream
82+
this.$refs.localMedia.srcObject = this.localCameraStream
83+
this.$refs.remoteMedia.srcObject = this.remoteCameraStream
11584
},
11685
toggleMicrophone() {
117-
if (this.localStream && this.localStream.getAudioTracks().length > 0) {
118-
const audioTrack = this.localStream
86+
if (
87+
this.localCameraStream &&
88+
this.localCameraStream.getAudioTracks().length > 0
89+
) {
90+
const audioTrack = this.localCameraStream
11991
.getTracks()
12092
.find((track) => track.kind == 'audio')
12193
audioTrack.enabled = !audioTrack.enabled
12294
this.isMicrophoneMuted = !audioTrack.enabled
12395
}
12496
},
97+
async toggleCameraScreen() {
98+
try {
99+
let stream
100+
101+
if (this.usingCamera) {
102+
stream = await navigator.mediaDevices.getDisplayMedia({
103+
video: true,
104+
})
105+
} else {
106+
stream = await navigator.mediaDevices.getUserMedia({
107+
video: true,
108+
})
109+
}
110+
111+
if (stream) {
112+
await this.$store.dispatch('changeTrack', stream)
113+
this.usingCamera = !this.usingCamera
114+
}
115+
} catch (e) {
116+
this.$toast.error('Error in toggling camera/screen: ' + e.message)
117+
}
118+
},
125119
hangUp() {
126120
this.$router.push('/testslist')
127121
},
@@ -132,6 +126,7 @@ export default {
132126
<style scoped>
133127
.video {
134128
border-radius: 30px;
135-
height: 36vw;
129+
width: 100%;
130+
object-fit: contain;
136131
}
137132
</style>

0 commit comments

Comments
 (0)