-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeetings.html
More file actions
246 lines (227 loc) · 6.78 KB
/
meetings.html
File metadata and controls
246 lines (227 loc) · 6.78 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Spaces Meeting Review</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.3/socket.io.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<h1>Spaces Meeting Review</h1>
<div class="row">
<div class="col-4">
<label for="room">Room Number:</label>
<textarea class="form-control" id="room" rows="1"></textarea>
</div>
<div class="col-4">
<label for="password">Password:</label>
<input class="form-control" type="password" id="password" rows="1"></input>
</div>
<div class="col-4">
<br>
<button id="connect" class="btn btn-primary" onclick="startConnect()">Connect</button>
</div>
<br>
</div>
<hr/>
<div class="row">
<div class="col-12">
<textarea readonly="readonly" class="form-control" id="console-log" rows="40"></textarea>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(init);
function init() {
document.getElementById("connect").innerHTML = "Connect";
}
var spacesToken;
var socketURL = "https://spacesapis-socket.avayacloud.com/chat";
var spacesID;
var socketio = "";
var password;
function connectSocket() {
socketio = io.connect(
socketURL, {
query: 'tokenType=jwt&token=' + spacesToken,
transports: ['websocket']
}
);
socketio.on('connect', function () {
var spaceToSubscribe = {
channel: {
_id: spacesID,
type: 'topic',
password: password
}
};
socketio.emit('SUBSCRIBE_CHANNEL', spaceToSubscribe);
document.getElementById("connect").innerHTML = "Disconnect";
});
socketio.on('disconnect', function () {
console.log("Socket disconnect");
});
socketio.on('connect_error', function () {
console.log("Socket connect_error");
});
socketio.on('error', function () {
console.log("Socket error");
});
socketio.on('CHANNEL_SUBSCRIBED', function () {
getMeetingMembers();
});
socketio.on('CHANNEL_UNSUBSCRIBED', function () {
console.log("CHANNEL_UNSUBSCRIBED");
});
socketio.on('SUBSCRIBE_CHANNEL_FAILED', function () {
console.log("SUBSCRIBE_CHANNEL_FAILED");
});
socketio.on('SEND_MESSAGE_FAILED', function (msg) {
console.log("SEND_MESSAGE_FAILED");
});
socketio.on('MESSAGE_SENT', function (msg) {
});
}
function clearTrace() {
var consoleTxt = $('#console-log').val();
$('#console-log').val("");
}
function populateMeetings() {
$.ajax({
headers: {
'Authorization': 'jwt ' + spacesToken,
'Accept': 'application/json',
'spaces-x-space-password': password
},
url: 'https://spacesapis.avayacloud.com/api/spaces/' + spacesID + '/meetings',
type: "GET",
dataType: "json",
success: function (data) {
var entries = data.total;
var attendeesTotal;
var meeting;
var displayString;
for (i = entries - 1; i >= 0; i--) {
meeting = data.data[i];
var meetingId = meeting._id;
trace("Meeting Id " + meetingId + ": ");
attendeesTotal = meeting.content.attendees.length;
trace("Total Attendees " + attendeesTotal);
for (j = attendeesTotal - 1; j >= 0; j--) {
if (meeting.content.attendees[j].type == "user") {
displayString = "---- " + meeting.content.attendees[j].username + ", " + meeting.content.attendees[j].displayname + ", type = " + meeting.content.attendees[j].type;
} else if (meeting.content.attendees[j].type == "phone") {
displayString = "---- " + meeting.content.attendees[j].username + " " + meeting.content.attendees[j].displayname + ", type = " + meeting.content.attendees[j].type;
} else {
displayString = "---- " + meeting.content.attendees[j].displayname + ", type = " + meeting.content.attendees[j].type;
}
trace(displayString);
}
}
},
error: function (error) {
console.log(`Error ${error}`);
}
});
}
function getMeetingMembers() {
$.ajax({
headers: {
'Authorization': 'jwt ' + spacesToken,
'Accept': 'application/json',
'spaces-x-space-password': password
},
url: 'https://spacesapis.avayacloud.com/api/spaces/' + spacesID + '/members',
type: "GET",
dataType: "json",
success: function (data) {
var entries = data.total;
var phoneTotal;
var member;
var displayString;
trace("Registered Users:");
for (i = entries - 1; i >= 0; i--) {
member = data.data[i];
displayString = "---- " + member.displayname + " ";
phoneTotal = member.phone_numbers.length;
for (j = phoneTotal - 1; j >= 0; j--) {
displayString += member.phone_numbers[j].value + " ";
}
trace(displayString);
}
populateMeetings();
},
error: function (error) {
console.log(`Error ${error}`);
}
});
}
function disconnect() {
var spaceToUnsubscribe = {
channel: {
_id: spacesID,
type: 'topic',
password: password
}
};
socketio.emit('UNSUBSCRIBE_CHANNEL', spaceToUnsubscribe);
init();
clearTrace();
socketio = null;
}
function startConnect() {
if (document.getElementById("connect").innerHTML == "Disconnect") {
disconnect();
return;
}
input = document.getElementById("password").value;
if (input.trim() != '') {
password = document.getElementById("password").value;
} else {
password = null;
}
spacesID = document.getElementById('room').value;
// Create an anonymous user in order to obtain a jwt token
$.ajax({
data: JSON.stringify({
"displayname": "Chatty McChat",
"username": "Anonymous"
}),
url: "https://spacesapis.avayacloud.com/api/anonymous/auth",
contentType: 'application/json',
type: 'POST',
success: function (data) {
spacesToken = data.token;
joinRoom();
connectSocket();
},
error: function (error) {}
});
}
function joinRoom() {
// Join the space
$.ajax({
headers: {
'Authorization': 'jwt ' + spacesToken,
'Accept': 'application/json',
'spaces-x-space-password': password
},
url: 'https://spacesapis.avayacloud.com/api/spaces/' + spacesID + '/join',
type: "GET",
success: function (data) {
//console.log("Room joined");
}
});
}
function trace(text) {
text = text.trim();
const now = (window.performance.now() / 1000).toFixed(3);
var consoleTxt = $('#console-log').val();
var log = text;
$('#console-log').val(consoleTxt + "\n\n" + log);
}
</script>
</body>
</html>