forked from AgoraIO/Agora-with-QT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInRoom.qml
executable file
·162 lines (154 loc) · 5.25 KB
/
InRoom.qml
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import QtQuick 2.5
InRoomForm {
id: inroom
anchors.fill: parent
property bool isVideoEnabled: true
property bool isVideoViewNormal: true
property bool isVoiceMuted: false
property var views:[]
btnEndCall.onClicked: {
agoraRtcEngine.setupLocalVideo(null)
main.leaveChannel()
}
btnSettingsCall.onClicked: containerWindow.openDeviceSettings()
btnMuteVoice.onClicked: {
isVoiceMuted = !isVoiceMuted
main.muteLocalAudioStream(isVoiceMuted)
if (isVoiceMuted) {
btnMuteVoice.defaultImageSource = "images/btn_mute_open.png"
btnMuteVoice.hoverImageSource = "images/btn_mute_open_touch.png"
btnMuteVoice.pressedImageSource = "images/btn_mute_open_push.png"
} else {
btnMuteVoice.defaultImageSource = "images/btn_mute_close.png"
btnMuteVoice.hoverImageSource = "images/btn_mute_close_touch.png"
btnMuteVoice.pressedImageSource = "images/btn_mute_close_push.png"
}
}
btnVoiceCall.onClicked: {
isVideoEnabled = !isVideoEnabled
main.enableVideo(isVideoEnabled)
if (isVideoEnabled) {
btnVoiceCall.defaultImageSource = "images/btn_voice.png"
btnVoiceCall.hoverImageSource = "images/btn_voice_touch.png"
btnVoiceCall.pressedImageSource = "images/btn_voice_push.png"
} else {
btnVoiceCall.defaultImageSource = "images/btn_video.png"
btnVoiceCall.hoverImageSource = "images/btn_video_touch.png"
btnVoiceCall.pressedImageSource = "images/btn_video_push.png"
localVideo.showVideo = isVideoEnabled
}
}
btnExpandView.onClicked: {
isVideoViewNormal = !isVideoViewNormal
if (isVideoViewNormal) {
containerWindow.showNormal()
btnExpandView.defaultImageSource = "images/btn_maximize.png"
btnExpandView.hoverImageSource = "images/btn_maximize_touch.png"
btnExpandView.pressedImageSource = "images/btn_maximize_push.png"
} else {
containerWindow.showMaximized()
btnExpandView.defaultImageSource = "images/btn_restore.png"
btnExpandView.hoverImageSource = "images/btn_restore_touch.png"
btnExpandView.pressedImageSource = "images/btn_restore_push.png"
}
}
Component.onCompleted: {
inroom.views = [localVideo, remoteVideo1, remoteVideo2, remoteVideo3, remoteVideo4]
channelName.text = main.channelName
agoraRtcEngine.setupLocalVideo(localVideo.videoWidget)
}
localVideo.onDoubleClicked: {
inroom.maximizeView(localVideo)
}
remoteVideo1.onDoubleClicked: {
inroom.maximizeView(remoteVideo1)
}
remoteVideo2.onDoubleClicked: {
inroom.maximizeView(remoteVideo2)
}
remoteVideo3.onDoubleClicked: {
inroom.maximizeView(remoteVideo3)
}
remoteVideo4.onDoubleClicked: {
inroom.maximizeView(remoteVideo4)
}
Connections {
target: agoraRtcEngine
onFirstLocalVideoFrame: {
localVideo.showVideo = true
}
onUserJoined: {
inroom.handleUserJoined(uid)
}
onFirstRemoteVideoDecoded: {
inroom.handleUserJoined(uid)
}
onUserOffline: {
var view = inroom.findRemoteView(uid)
if (view)
inroom.unbindView(uid, view)
}
}
function handleUserJoined(uid) {
//check if the user is already binded
var view = inroom.findRemoteView(uid)
// console.log("handle user joined for user " + uid + " view " + view)
if (view !== undefined)
return
//find a free view to bind
view = inroom.findRemoteView(0)
// console.log("foud free view " + view + "to bind")
if (view && agoraRtcEngine.setupRemoteVideo(uid, view.videoWidget) === 0) {
// console.log("bind view view " + view + "for user" + uid)
inroom.bindView(uid, view)
}
}
function maximizeView(view) {
if (view.width === view.parent.width)
return
var i, v, mv
//find the maximized view
for (i in inroom.views) {
v = inroom.views[i]
if (v.width === v.parent.width) {
mv = v
break
}
}
if (mv) {
view.swap(mv)
}
for (i in inroom.views) {
v = inroom.views[i]
if (v === view)
v.z = 0
else
v.z = 1
}
}
function findRemoteView(uid) {
for (var i in inroom.views) {
var v = inroom.views[i]
if (v.uid === uid && v !== localVideo)
return v
}
}
function bindView(uid, view) {
if (view.uid !== 0)
return false
view.uid = uid
view.showVideo = true
view.visible = true
// console.log("bind view " + view + " for user " + uid)
return true
}
function unbindView(uid, view) {
if (uid !== view.uid)
return false
view.showVideo = false
view.visible = false
view.uid = 0
// console.log("unbind view " + view + " for user " + uid)
return true
}
}