-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
577 lines (499 loc) · 18.7 KB
/
index.html
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
<html>
<head>
<link type="text/css" href="css/styleOyatelAPI.custom.css" rel="stylesheet" />
<link type="text/css" href="css/custom-theme/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="js/cometd.js"></script>
<script type="text/javascript" src="js/jquery.cometd.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="js/jquery.json-2.2.js"></script>
<script type="text/javascript" src="js/jquery.jsonp-2.1.4.min.js"></script>
<script type="text/javascript" src="js/oyatelapi.js"></script>
<script type="text/javascript" src="js/Oyatel.js"></script>
<script type="text/javascript" src="js/jquery-blink.js"></script>
<script type="text/javascript">
$(function(){
// Accordion
$("#accordion").accordion({ header: "h3" });
// Tabs
$('#tabs').tabs();
// Tabs2
$('#tabs2').tabs();
// Dialog
$('#dialog1').dialog({
autoOpen: false,
width: 600,
buttons: {
"Ok": function() {
$(this).dialog("close");
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
// Dialog Link
$('#dialog_link1').click(function(){
$('#dialog1').dialog('open');
return false;
});
// Dialog
$('#dialog2').dialog({
autoOpen: false,
width: 600,
buttons: {
"Ok": function() {
$(this).dialog("close");
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
// Dialog Link
$('#dialog_link2').click(function(){
$('#dialog2').dialog('open');
return false;
});
// Datepicker
$('#datepicker').datepicker({
inline: true
});
// Slider
$('#slider').slider({
range: true,
values: [17, 67]
});
// Progressbar
$("#progressbar").progressbar({
value: 20
});
//hover states on the static widgets
$('ul#icons li').hover(
function() { $(this).addClass('ui-state-hover'); },
function() { $(this).removeClass('ui-state-hover'); }
);
});
</script>
</head>
<body>
<!-- Header -->
<div class="headerOyatelLogo">
<div id="connect">
<div class="not-authorized">
<div class="btn-oyatel-login"><span>Connect with Oyatel</span></div>
</div>
<div class="authorized">
<div>Logged in as: <span class="oyatel-username"></span> <button class="oyatel-logout">Logout</button></div>
</div>
</div>
<div class="docsURL"><a href="http://dev.oyatel.com/documentation/">Documentation</a></div>
</div>
<div class="authorized">
<div class="mainContent">
<div id="dialog2" title="Channels">
<p>Channels are streams of data being sent to your client based on the topic you are interested in subscribing to.
On the client side you will subscribe to a channel, to receive events matching the channel to your listener/callback.
You can subscribe to multiple channels with individual listeners for each..</p>
</div>
<div id="dialog1" title="Streaming API">
<p>The Oyatel Streaming API is a HTTP service using a long-polling technique often referred to as Comet. You can use this API to get real-time events for inbound/outbound calls, presence notifications and queue status updates. Since it is based on the HTTP protocol, it can easily be implemented in both web- and desktop-applications.
.</p>
</div>
<!-- Tabs -->
<div class="ballsTest">
</div>
<div class="sectionTitle">
<h2>Streaming javaScript API:</h2>
<div id="dialog_link1" class="helpImg"></div>
</div>
<div class="leftWrapper">
<div id="tabs" >
<div class="dynamicNavigationBar" >
<ul>
<li>
<a href="#callJQ" onclick="clearCount('#callCountDNB','call');">Call</a>
<div id="callCountDNB" class="newEvent"><p>0</p></div>
</li>
<li>
<a href="#presenceJQ" onclick="clearCount('#presenceCountDNB','presence');">Presence</a>
<div id="presenceCountDNB" class="newEvent"><p>0</p></div>
</li>
<li>
<a href="#queueJQ" onclick="clearCount('#queueCountDNB','queue');">Queue</a>
<div id="queueCountDNB" class="newEvent"><p>0</p></div>
</li>
</ul>
</div>
<div id="callJQ">
<p class="ui-state-highlight ui-corner-all height30">Waiting for call events...</p>
</div>
<div id="presenceJQ">
<p class="ui-state-highlight ui-corner-all height30">Waiting for presence events...</p>
</div>
<div id="queueJQ">
<p class="ui-state-highlight ui-corner-all height30">Waiting for queue events...</p>
</div>
</div>
</div>
<div class="rightWrapper">
<div id="tabs2" >
<ul>
<li><a href="#userCurrentUserJQ">User:currentUser</a></li>
<li><a href="#fdQueueJQ">Fulldump:Queue</a></li>
<li><a href="#voicemailMailboxJQ">Voicemail:Mailbox</a></li>
<li><a href="#voicemailGetMessagesJQ">Voicemail:getMessages</a></li>
<li><a href="#fdPresenceJQ">Fulldump:Presence</a></li>
</ul>
<div id="userCurrentUserJQ"></div>
<div id="fdQueueJQ"></div>
<div id="voicemailMailboxJQ"></div>
<div id="voicemailGetMessagesJQ"></div>
<div id="fdPresenceJQ"></div>
</div>
</div>
<!-- Accordion -->
<div class="sectionTitle">
<h2>Channels:</h2>
<div id="dialog_link2" class="helpImg"></div>
</div>
<div class="bottomWrapper">
<!-- <h2>Channels:<div id="dialog_link2" class="helpImg"></div></h2> -->
<div id="accordion">
<div>
<h3><a href="#">Contacts</a></h3>
<div class="userListJQ">
<div class="userPresenceEvent"></div>
<p id="loadingUserList" class="ui-state-highlight ui-corner-all height30">Loading user list...</p>
</div>
</div>
<div id="showPresenceEventsHistory">
<div>
<h3><a href="#">Presence events history</a></h3>
<div id="presenceEventsHistoryTab">
<div class="presenceEventsJQ"></div>
</div>
</div>
</div>
<div id="showCallEventsHistory">
<div>
<h3><a href="#">Call events history</a></h3>
<div id="callEventsHistoryTab">
<div class="callEventsJQ"></div>
</div>
</div>
</div>
<div id="showCallPackageHistory">
<div>
<h3><a href="#">Call packages history</a></h3>
<div id="callPackageHistoryTab">
<div class="callPackagesJQ"></div>
</div>
</div>
</div>
<div id="showPresencePackageHistory">
<div>
<h3><a href="#">Presence packages history</a></h3>
<div id="presencePackageHistoryTab">
<div class="presencePackagesJQ"></div>
</div>
</div>
</div>
<div id="showQueuePackageHistory">
<div>
<h3><a href="#">Queue packages history</a></h3>
<div id="queuePackageHistoryTab">
<div class="queuePackagesJQ"></div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var _Ids = new Array();
var _usernames = new Array();
var callCount = 0;
var presenceCount = 0;
var queueCount = 0;
function clearCount(id,count) {
$(id).css('display','none');
if (count == 'call') return callCount=0;
else if (count == 'presence') return presenceCount=0;
else return queueCount=0;
};
$(document).ready(function() {
Oyatel.init('558f6868-0a98-45db-ab57-35173f4ec960', 'http://127.0.0.1/~even/oyatel-api-examples/javascript/oauth_cb.html');
// Setup callbacks for deauth/auth-orization
Oyatel.bind('authorized', function() {
console.log('onAuthorized callback called');
authorized();
});
Oyatel.bind('authorizationfailed', function(errormsg) {
console.log('The user rejected the authorization, or some error occured: ' + errormsg);
});
Oyatel.bind('deauthorized', function() {
console.log('onDeauthorized callback called');
deauthorized();
});
Oyatel.checkAuthorization();
// setup GUI to show we are authorized and start listening to events
function authorized() {
console.log('calling authorized');
$('#connect .authorized').css('display', 'block');
$('#connect .not-authorized').css('display', 'none');
$('.mainContent').css('display', 'block');
//print_r
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;
//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += " ";
if(typeof(arr) == 'object') { //Array/Hashes/Objects
for(var item in arr) {
var value = arr[item];
if(typeof(value) == 'object') { //If it is an array,
dumped_text += level_padding + "<div class=\"objHeader\">'" + item + "' ...\n</div>";
dumped_text += dump(value,level+1);
} else {
dumped_text += level_padding + "<div class=\"objContent\">'" + item + "' => \"" + value + "\"\n</div>";
}
}
} else { //Stings/Chars/Numbers etc.
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}
Oyatel.User.currentUser(function(msg) {
console.log('Oyatel.User.currentUser :', msg);
});
console.log('Oyatel.Voicemail.getMessageRecordingURL :', Oyatel.Voicemail.getMessageRecordingURL("1314606524_37887000","wav"));
//events
Oyatel.Events.subscribe('/events/queue', function(msg) {
console.log('Oyatel.Events.subscribe' + msg.channel + ' :', msg);
});
//call events
Oyatel.Events.subscribe('/events/call', function(msg) {
console.log('Oyatel.Events.subscribe' + msg.channel + ' msg :', msg);
});
Oyatel.Events.subscribe('/events/call', function(msg) {
console.log('Oyatel.Events.subscribe' + msg.channel + ' msg.data :', msg.data);
});
Oyatel.Events.subscribe('/events/call', function(msg) {
console.log('Oyatel.Events.subscribe' + msg.channel + ' msg.data.callerId :', msg.data.callerId);
});
//presence events
Oyatel.Events.subscribe('/events/presence', function(msg) {
console.log('Oyatel.Events.subscribe' + msg.channel + ' msg :', msg);
});
Oyatel.Events.subscribe('/events/presence', function(msg) {
console.log('Got presence package: ', msg.data);
var eventString = "";
var fulldumpString = "";
var allEvents = "";
if (msg.data.event == "fulldump") {
fulldumpString = "";
for (var i in msg.data.events) {
$('.userListJQ').append('<div class="users_list" id="'
+ msg.data.events[i].userId
+ '">'
+ msg.data.events[i].username
+ '<div class="availableImg" id="available' + msg.data.events[i].userId
+ '"></div>'
+ '<div class="ringingImg" id="ringing' + msg.data.events[i].userId
+ '"></div>'
+ '<div class="busyImg" id="busy' + msg.data.events[i].userId
+ '"></div>'
+ '</div>');
//arrays for ID>username convertion
_Ids[i] = msg.data.events[i].userId;
_usernames[i] = msg.data.events[i].username;
$('#loadingUserList').css('display', 'none');
if (msg.data.events[i].state == "AVAILABLE") {
$('#available' + msg.data.events[i].userId).css('display', 'block');
$('#busy' + msg.data.events[i].userId).css('display', 'none');
$('#ringing' + msg.data.events[i].userId).css('display', 'none');
}
else if (msg.data.events[i].state == "BUSY") {
$('#available' + msg.data.events[i].userId).css('display', 'none');
$('#busy' + msg.data.events[i].userId).css('display', 'block');
$('#ringing' + msg.data.events[i].userId).css('display', 'none');
}
else if (msg.data.events[i].state == "RINGING") {
$('#available' + msg.data.events[i].userId).css('display', 'none');
$('#busy' + msg.data.events[i].userId).css('display', 'none');
$('#ringing' + msg.data.events[i].userId).css('display', 'block');
}
else $('#' + msg.data.events[i].userId).css('display', 'none');
}
}
else {
eventString = ''
+ msg.data.firstname
+ ' '
+ msg.data.lastname
+ ' changed status to '
+ msg.data.state;
//make a function out of it!
if (msg.data.state == "AVAILABLE") {
$('#available' + msg.data.userId).css('display', 'block');
$('#busy' + msg.data.userId).css('display', 'none');
$('#ringing' + msg.data.userId).css('display', 'none');
}
else if (msg.data.state == "BUSY") {
$('#available' + msg.data.userId).css('display', 'none');
$('#busy' + msg.data.userId).css('display', 'block');
$('#ringing' + msg.data.userId).css('display', 'none');
}
else if (msg.data.state == "RINGING") {
$('#available' + msg.data.userId).css('display', 'none');
$('#busy' + msg.data.userId).css('display', 'none');
$('#ringing' + msg.data.userId).css('display', 'block');
}
else $('#' + msg.data.userId).css('display', 'none');
$('.presenceEventsJQ').append('<div class="presence_event">' + eventString + '</div');
$('.userPresenceEvent').fadeIn('slow').html('<div class="ui-state-highlight ui-corner-all height30">' + eventString + '</div');
$('.userPresenceEvent').fadeOut('slow');
}
});
// get ME info...
Oyatel.User.currentUser(function(user) {
$('.oyatel-username').html(user.username + ' (' + user.firstname + ' ' + user.lastname + ')');
});
Oyatel.Events.subscribe('/events/call', function(msg) {
// add call info to the output...
var string = "";
if (msg.data.direction == "out") {
string = "User ";
for (var i in _Ids) if (msg.data.userId == _Ids[i]) string += _usernames[i];
string += " calls ";
string += msg.data.destination;
string += " from ";
string += msg.data.callerId.number;
string += ". Current call state is: ";
string += msg.data.event;
} else {
string = "User ";
for (var i in _Ids) if (msg.data.userId == _Ids[i]) string += _usernames[i];
string += " receives call from from ";
string += msg.data.callerId.number;
string += ". Current call state is: "
+ msg.data.event;
}
var dataString = '<div class="callevent">' + string + '</div>';
$('.callEventsJQ').append(dataString);
console.log("Got call package: ", msg.data);
});
//dumping packages for print
Oyatel.Events.subscribe('/events/call', function(msg) {
var string = dump(msg);
callCount = callCount+1;
//if(callCount > 9) $('#callCountDNB').css('font-size',7).css('top','4px');
//else if(callCount > 99) $('#callCountDNB').css('font-size',5);
var dataString = '<div class="wrapperTab"><div class=\"packageTitle\">Recieved CALL package:</div>' + string + '</div>';
var dataStringHistory = '<div class=\"packageTitle\">Recieved CALL package:</div>' + string;
var dataStringJQYellow = '<div id="callFade" class="ui-state-disabled">' + string + '</div>';
var dataStringJQ = '<div>' + string + '</div>';
$('#callJQ').html(dataStringJQYellow);
$('#callCountDNB p').html(callCount);
$('#callFade').switchClass( "ui-state-disabled", 1500 );
$('#showCallEventsHistory').css('display', 'block');
$('#showCallPackageHistory').css('display', 'block');
$('.callPackagesJQ').append(dataStringHistory);
$('#callCountDNB').effect("bounce", { times:3 }, 200).css('display','block');
});
Oyatel.Events.subscribe('/events/presence', function(msg) {
if (msg.data.event == "fulldump") {
$('#fdPresenceJQ').html(dump(msg));
}
else {
var string = dump(msg);
presenceCount = presenceCount+1;
//if(presenceCount > 9) $('#presenceCountDNB').css('font-size',7).css('top','4px');
//else if(presenceCount > 99) $('#presenceCountDNB').css('font-size',5);
var dataString = '<div class="wrapperTab"><div class=\"packageTitle\">Recieved PRESENCE package:</div>' + string + '</div>';
var dataStringHistory = '<div class=\"packageTitle\">Recieved PRESENCE package:</div>' + string;
var dataStringJQ = '<div id="presenceFade" class="ui-state-disabled">' + string + '</div>';
$('#presence').append(dataString);
$('#presenceJQ').html(dataStringJQ);
$('#presenceCountDNB p').html(presenceCount);
$('#presenceFade').switchClass( "ui-state-disabled", 1500 );
$('#showPresencePackageHistory').css('display', 'block');
$('#showPresenceEventsHistory').css('display', 'block');
$('.presencePackagesJQ').append(dataStringHistory);
$('#presenceCountDNB').effect("bounce", { times:3 }, 250).css('display','block');
}
});
Oyatel.Events.subscribe('/events/queue', function(msg) {
if (msg.data.event == "fulldump") {
$('#fdQueueJQ').html(dump(msg));
}
else {
var string = dump(msg);
queueCount = queueCount+1;
//if(queueCount > 9) $('#queueCountDNB').css('font-size',7).css('top','4px');
//else if(queueCount > 99) $('#queueCountDNB').css('font-size',5);
var dataString = '<div class="wrapperTab"><div class=\"packageTitle\">Recieved QUEUE package:</div>' + string + '</div>';
var dataStringHistory = '<div class=\"packageTitle\">Recieved QUEUE package:</div>' + string;
var dataStringJQ = '<div id="queueFade" class="ui-state-disabled">' + string + '</div>';
$('#queue').append(dataString);
$('#queueJQ').html(dataStringJQ);
$('#showQueuePackageHistory').css('display', 'block');
$('#showQueueEventsHistory').css('display', 'block');
$('#queueCountDNB p').html(queueCount);
$('#queueFade').switchClass( "ui-state-disabled", 1500 );
$('.queuePackagesJQ').append(dataStringHistory);
$('#queueCountDNB').effect("bounce", { times:3 }, 300).css('display','block');
//$('#queueCountDNB').css('position','absolute');
}
});
Oyatel.Voicemail.mailbox(function(msg) {
$('#voicemailMailboxJQ').html(dump(msg));
Oyatel.Voicemail.getMessages(msg.mailboxId, function(msg) {
$('#voicemailGetMessagesJQ').html(dump(msg));
});
});
Oyatel.User.currentUser(function(msg) {
//console.log('Oyatel.User.currentUser :', msg);
$('#userCurrentUserJQ').html(dump(msg));
});
}
/*
$('#streamingAPIinfo').click(function() {
alert('Streaming API');
});
/*
$('#eventInfo').click(function() {
alert('Event');
});
*/
// setup GUI to show we are not authorized
function deauthorized() {
$('#connect .authorized').css('display', 'none');
$('#connect .not-authorized').css('display', 'block');
$('.mainContent').css('display', 'none');
}
// $.Oyatel.Login.createButton('.btn-oyatel-login', 'normal');
$('.btn-oyatel-login').click(function() {
Oyatel.authorize();
});
$('.oyatel-logout').click(function() {
Oyatel.deauthorize();
});
$('.foldCallEventsButton').click(function() {
$('#callEventsHistoryTab').css('height', '200px');
});
$('.foldCallpackageButton').click(function() {
$('#callPackageHistoryTab').css('height', '400px');
});
$('.foldPresenceEventsButton').click(function() {
$('#presenceEventsHistoryTab').css('height', '200px');
});
});
</script>
</div>
</div>
</body>
</html>