-
Notifications
You must be signed in to change notification settings - Fork 48
/
event-demo.js
72 lines (60 loc) · 2.56 KB
/
event-demo.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
/****************************************************************************
JSCommunicator
http://jscommunicator.org
Copyright (C) 2014-2015 Daniel Pocock http://danielpocock.com
Copyright (C) 2014 Juliana Louback http://julianalouback.com
The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 2 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
You may distribute non-source (e.g., minimized or compacted) forms of
that code without the full copy of the GNU GPL normally required
provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
****************************************************************************/
(function($) {
$(document).ready(function() {
$("#contact-directory").change(function() {
// Get the selected value (SIP destination)
var dest = $( this ).val();
Arbiter.publish("jsc/destination/set", dest);
});
var logEvent = function(event_name, data) {
var now = new Date().toLocaleTimeString();
if(data.length > 1) {
data = "<a href=\"#\" onclick=\"JSCommManager.make_call('".concat(data,"');\">",data,"</a>");
}
$("#event-demo-log").append("<tr><td>" + now + "</td><td>" + event_name + "</td><td>" + data + "</td></tr>");
};
Arbiter.subscribe(
[ "jsc/*", "jsc/*/*" ],
{ async:true },
function(data, m) {
console.log("Got a message: " + m);
if(m == "jsc/call/incoming") {
// Somebody is calling
// This is where we may invoke some code to look up the
// caller's full profile (e.g. name, department, company)
// in an address book, a CRM system or some other database
var caller_uri = data;
console.log("Incoming call notification, caller = " + caller_uri);
logEvent(m, caller_uri);
} else if (data) {
logEvent(m, data);
} else {
logEvent(m, "-");
}
// Here we use the idle/incall events to make the pull-down menu
// accessible only when we are not in a call
if(m == "jsc/ua/idle") {
$("#contact-directory").removeProp("disabled");
} else if(m == "jsc/ua/incall" || m == "jsc/ua/notready") {
$("#contact-directory").prop("disabled", true);
}
}
);
});
})(jQuery);