forked from lznt/Oulutest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMumbleFunc.js
323 lines (289 loc) · 8.27 KB
/
MumbleFunc.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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*
* Authors: Xiaori Hu
* MumlbeFunc.js includes most of the functions handling the events happening in the mumble
*
*/
/*
* Set the state of connection, and all buttons(excpet connect button) in widget of mumble client
* aren't enable before the mumble actually connects to mumble server.
*/
function SetConnectionState(connected, strState)
{
var stateLabel = findChild(_mumbleClientWidget, "labelConnectionState");
stateLabel.text = strState;
_buttonConnect.enabled = !connected;
_buttonDisconnect.enabled = connected;
_buttonWizard.enabled = connected;
_buttonSelfMute.enabled = connected;
_buttonSelfDeaf.enabled = connected;
}
/*
* set the mumble server channnle name, the default value is Root if keeping it blank.
*/
function SetChannelName(channelName)
{
var channelLabel = findChild(_mumbleClientWidget, "labelChannelName");
channelLabel.text = channelName;
}
/*
* Everytime connecting to server, it will get all parameters from the connection widget in case that some parameters are modified.
*/
function GetConnectionDataWidgets(widget)
{
if (widget == null)
return null;
var widgets =
{
host : findChild(widget, "hostLineEdit"),
port : findChild(widget, "portSpinBox"),
username : findChild(widget, "usernameLineEdit"),
password : findChild(widget, "passwordLineEdit"),
channel : findChild(widget, "channelLineEdit"),
connectButton : findChild(widget, "buttonConnect"),
cancelButton : findChild(widget, "buttonCancel")
};
return widgets;
}
/*
* connect to server via using the mumble plugin and also show the state of connection
*/
function Connect()
{
var widgets = GetConnectionDataWidgets(_mumbleConnectWidget);
mumble.Connect(widgets.host.text, widgets.port.value, widgets.username.text, widgets.password.text, widgets.channel.text, _connectionInfo.outputMuted, _connectionInfo.intputMuted);
MumbleConnectProxy.visible = false;
//_mumbleConnectWidget.visible = false;
SetConnectionState(false, "Connecting to " + widgets.host.text + ":" + widgets.port.value.toString() + "...");
}
/*
* show the reason of failing to connect to server
*/
function OnRejected(rejectType, reason)
{
// enum RejectReasonWrongServerPW
if (rejectType.value == 4)
QMessageBox.warning(ui.MainWindow(), "", reason);
// enum RejectReasonServerFull
else if (rejectType.value == 6)
QMessageBox.warning(ui.MainWindow(), "", "Server is full");
}
/*
* show the state of connection when succfully connect to server
*/
function OnConnected(host, port, username)
{
SetConnectionState(true, "Connected to " + host + ":" + port.toString() +'<br>' + " as "+ username);
}
/*
* show the reason of disconnecting to server
*/
function OnDisconnected(reason)
{
if (reason != "")
SetConnectionState(false, "Disconnected: " + reason);
else
SetConnectionState(false, "Disconnected");
}
function OnMeCreated(mumbleMe)
{
// Can hook to own user ptr signals here.
// Depends if you want to use own functions for processing 'me' signals.
// Or a generic function to handle all like this example script shows.
// You can use the signaling model you feel is best for you.
}
/*
* show the users joining to channel of server
*/
function OnJoinedChannel(mumbleChannel)
{
SetChannelName(mumbleChannel.fullName);
mumbleChannel.UserJoined.connect(OnUserJoinedPresentChannel);
mumbleChannel.UserLeft.connect(OnUserLeftPresentChannel);
}
/*
* get the user via user identification number from server
*/
function GetUser(userId)
{
var user = null;
for(var i=0; i<_userList.count; ++i)
{
var item = _userList.item(i);
if (item != null && item.data(Qt.UserRole) == userId)
{
user = { listItem: item, row: i };
break;
}
}
return user;
}
/*
* show the current user joining to channel of server
*/
function OnUserJoinedPresentChannel(user)
{
//var listItem = new QListWidgetItem(_iconInactive, user.name + " (" + user.id.toString() + ")");
var listItem = new QListWidgetItem(user.name + " (" + user.id.toString() + ")");
listItem.setData(Qt.UserRole, user.id);
if (user.isMe)
{
var font = listItem.font();
font.setBold(true);
listItem.setFont(font);
}
_userList.addItem(listItem);
}
/*
* show the user of leaving current channel of server
*/
function OnUserLeftPresentChannel(userId)
{
var listItem = GetUser(userId);
if (listItem != null)
//_userList.takeAt(listItem.row);
_userList.takeItem(listItem.row);
}
/*
* focus on the selected user in the userlist
*/
function OnUserSelected(listItem)
{
if (listItem == null)
listItem = _userList.currentItem();
if (listItem != null && listItem.data(Qt.UserRole) != null)
{
var mumbleUser = mumble.User(listItem.data(Qt.UserRole));
if (mumbleUser.isMe)
{
_buttonMuteSelected.enabled = false;
_buttonMuteSelected.text = "";
}
else
{
_buttonMuteSelected.enabled = true;
_buttonMuteSelected.text = mumbleUser.isMuted ? "Unmute " + mumbleUser.name : "Mute " + mumbleUser.name;
}
}
}
/*
* respond to the event of mute self
*/
function OnSelfMuteToggle()
{
var mumbleMe = mumble.Me();
if (mumbleMe != null)
mumble.SetOutputAudioMuted(!mumbleMe.isSelfMuted);
}
/*
* respond to the event of deaf self
*/
function OnSelfDeafToggle()
{
var mumbleMe = mumble.Me();
if (mumbleMe != null)
mumble.SetInputAudioMuted(!mumbleMe.isSelfDeaf);
}
/*
* mute the selected user
*/
function OnMuteSelectedToggle()
{
var currentItem = _userList.currentItem();
if (currentItem != null && currentItem.data(Qt.UserRole) != null)
{
var user = mumble.User(currentItem.data(Qt.UserRole));
if (user != null && !user.isMe)
user.isMuted = !user.isMuted;
}
}
/*
* update the state of user
*/
function UpdateUserState(mumbleUser)
{
var iter = GetUser(mumbleUser.id);
if (iter != null)
{
var text = mumbleUser.name + " (" + mumbleUser.id.toString() + ")";
var props = [];
if (mumbleUser.isMuted)
props.push("muted");
if (mumbleUser.isSelfMuted)
props.push("self muted");
if (mumbleUser.isSelfDeaf)
props.push("deaf");
if (!mumbleUser.isPositional)
props.push("non-positional");
if (props.length > 0)
text += " [" + props.join(", ") + "]";
iter.listItem.setText(text);
//OnUserSelected(iter.listItem);
}
}
/*
* the state of muting local users changes.
*/
function OnUserLocalMuteChanged(mumbleUser, isMuted)
{
UpdateUserState(mumbleUser);
}
/*
* the state of muting self changes.
*/
function OnUserSelfMutedChange(mumbleUser, isMuted)
{
UpdateUserState(mumbleUser);
if (mumbleUser.isMe)
_buttonSelfMute.text = mumbleUser.isSelfMuted ? "Unmute Self" : "Mute self";
}
/*
* the state of deafing self changes.
*/
function OnUserSelfDeafChange(mumbleUser, isDeaf)
{
UpdateUserState(mumbleUser);
if (mumbleUser.isMe)
_buttonSelfDeaf.text = mumbleUser.isSelfDeaf ? "Unmute Everyone" : "Mute Everyone";
}
/*
* the position of user changes, here it doesn't need to show the user position, remain it to be used in the future.
*/
// function OnUserPositionalChange(mumbleUser, isPositional)
// {
// UpdateUserState(mumbleUser);
// }
/*
* speak to concrete user,here it doesn't need to show the icon status, remain it to be used in the future.
*/
// function OnUserSpeakingChange(mumbleUser, speaking)
// {
// var iter = GetUser(mumbleUser.id);
// if (iter != null)
// iter.listItem.setIcon(speaking ? _iconActive : _iconInactive);
// }
/*
* send the text message
*/
function SendTextMessage()
{
var message = _chatLine.text;
if (message != "")
{
// Own messages are of course not relayed back to us, add by hand.
OnChannelTextMessageReceived(mumble.Me(), message);
// Send message to current channel.
mumble.SendTextMessage(message);
_chatLine.text = "";
}
}
/*
* receive the text message from concrete user in the channel
*/
function OnChannelTextMessageReceived(mumbleUser, message)
{
if (message != "")
_chatLog.appendHtml("[<span style=\"color:" + (mumbleUser.isMe == true ? "red" : "blue") + ";\">" + mumbleUser.name + "</span>] " + message);
}
// Bootstrap and utility functions
function LogInfo(msg) { console.LogInfo("[MumbleApplication]: " + msg); }
function LogError(msg) { console.LogError("[MumbleApplication]: " + msg); }