var appList;
var callback;
- var socket = new WebSocket("ws://" + document.URL.substring(7), "app-list-protocol");
+ var socket = new WebSocket("ws://localhost:7681", "app-list-protocol");
socket.onmessage = function(msg) {
appList = JSON.parse(msg.data);
if (callback)
}
var __callmanager = function () {
- var activeCall = null;
+ var calls = new Array();
var callHandlers = new Array();
- var socket = new WebSocket("ws://" + document.URL.substring(7), "dialer-protocol");
- var callService = new __callservice(socket);
+ var socket = new WebSocket("ws://localhost:7681", "dialer-protocol");
+ var services = new Array();
+
+ var listener = {
+ "onAccountUpdated": function(account) {
+ },
+ "onAccountAdded": function(account) {
+ services.push(new __callservice(socket, account.id));
+ },
+ "onAccountRemoved": function(id) {
+ var tmp = new Array();
+ for (var i in services)
+ if (services[i].id != id)
+ tmp.push(id);
+ services = tmp;
+ }
+ }
+ tizen.__account.addAccountListener(listener);
socket.onmessage = function(msg) {
var ev = JSON.parse(msg.data);
- if (activeCall == null) {
- activeCall = new __call(this, callService, socket, ev);
- }
-
- if (ev.type && ev.type == "CallRemoved") {
- activeCall = null;
- }
-
- if (ev.State) {
- if (ev.State == "incoming")
+ if (ev.type == "ModemAdded") {
+ tizen.__account.addAccount(new tizen.Account(ev.ModemAdded, ev));
+ } else if (ev.type == "ModemRemoved") {
+ tizen.__account.deleteAccount(ev.id);
+ } else if (ev.type == "CallAdded") {
+ calls.push(new __call(this, socket, ev));
+ } else if (ev.type == "CallRemoved") {
+ var tmp = new Array();
+ for (var i in calls)
+ if (calls[i].id != ev.id)
+ tmp.push(calls[i]);
+ calls = tmp;
+ } else if (ev.type == "PropertyChanged" && ev.State) {
+ if (ev.State == "incoming") {
for (var index in callHandlers)
- callHandlers[index].onIncoming(activeCall);
- if (ev.State == "dialing")
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onIncoming(calls[i]);
+ } else if (ev.State == "dialing") {
for (var index in callHandlers)
- callHandlers[index].onDialing(activeCall);
- else if (ev.State == "alerting")
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onDialing(calls[i]);
+ } else if (ev.State == "alerting") {
for (var index in callHandlers)
- callHandlers[index].onAlerting(activeCall);
- else if (ev.State == "hold")
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onAlerting(calls[i]);
+ } else if (ev.State == "hold") {
for (var index in callHandlers)
- callHandlers[index].onHold(activeCall);
- else if (ev.State == "waiting")
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onHold(calls[i]);
+ } else if (ev.State == "waiting") {
for (var index in callHandlers)
- callHandlers[index].onWaiting(activeCall);
- else if (ev.State == "disconnected")
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onWaiting(calls[i]);
+ } else if (ev.State == "disconnected") {
for (var index in callHandlers)
- callHandlers[index].onDisconnected(activeCall);
- else if (ev.State == "disconnecting")
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onDisconnected(calls[i]);
+ } else if (ev.State == "disconnecting") {
for (var index in callHandlers)
- callHandlers[index].onDisconnecting(activeCall);
- else if (ev.State == "accepted")
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onDisconnecting(calls[i]);
+ } else if (ev.State == "accepted") {
for (var index in callHandlers)
- callHandlers[index].onAccepted(activeCall);
- else if (ev.State == "remotelyheld")
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onAccepted(calls[i]);
+ } else if (ev.State == "remotelyheld") {
for (var index in callHandlers)
- callHandlers[index].onRemotelyHeld(activeCall);
- else if (ev.State == "active")
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onRemotelyHeld(calls[i]);
+ } else if (ev.State == "active") {
for (var index in callHandlers)
- callHandlers[index].onActivated(activeCall);
- else if (ev.State == "initializing")
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onActivated(calls[i]);
+ } else if (ev.State == "initializing") {
for (var index in callHandlers)
- callHandlers[index].onInitializing(activeCall);
- else if (ev.State == "initialized")
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onInitializing(calls[i]);
+ } else if (ev.State == "initialized") {
for (var index in callHandlers)
- callHandlers[index].onInitialized(activeCall);
- } else if (ev.ModemAdded) {
- tizen.account.addAccount(new tizen.Account(ev.ModemAdded, ev));
- } else if (ev.ModemRemoved) {
- tizen.account.deleteAccount(ev.ModemRemoved);
+ for (var i in calls)
+ if (calls[i].id == ev.id)
+ callHandlers[index].onInitialized(calls[i]);
+ } else {
+ console.log("Unhandled state: " + ev.State);
+ }
+ } else {
+ console.log("Unhandled event");
+ console.log(ev);
}
}
this.history = null;
this.isCallInProgress = function() {
- return activeCall != null;
+ return calls.length > 0;
}
this.addCallHandler = function(handler, callServiceType, serviceName) {
callHandlers.push(handler);
callHandlers = tmp;
}
- this.getCallSevice = function(service) {
- return callService;
+ this.getCallService = function(account) {
+ try {
+ for (var i in services)
+ if (services[i].id == account.id)
+ return services[i];
+ } catch (ex) {}
+
+ return services[0];
}
}
-var __callservice = function (wsi) {
+var __callservice = function (wsi, serviceid) {
var socket = wsi;
+ var id = serviceid;
+ this.__defineGetter__("id", function() {
+ return id;
+ });
+
this.launchDialer = function(remotePartyId) {
socket.send(JSON.stringify({ "cmd": "launchDialer" }));
}
}
}
-var __call = function(manager, callService, wsi, data) {
+var __call = function(manager, wsi, data) {
var socket = wsi;
+ var id = data.id;
+ this.__defineGetter__("id", function() {
+ return id;
+ });
+
var callData = data;
this.__defineGetter__("callData", function() {
return callData;
return streamList;
});
- var manager = manager;
- this.__defineGetter__("manager", function() {
- return manager;
- });
-
- var callService = callService;
- this.getCallService = function(serviceName) {
- return callService;
- }
-
this.accept = function() {
socket.send(JSON.stringify({"cmd": "accept"}));
}
socket.send(JSON.stringify({"cmd": "redirect"}));
}
this.end = function() {
- socket.send(JSON.stringify({"cmd": "end"}));
+ socket.send(JSON.stringify({"cmd": "end", "path": id}));
}
this.hold = function() {
socket.send(JSON.stringify({"cmd": "hold"}));
return application;
});
- var call = null;
- this.__defineGetter__("call", function() {
- if (call == null)
- call = new __callmanager();
- return call;
- });
-
this.Account = function (accountId, accountProperties) {
var id = accountId;
var properties = accountProperties;
});
}
}
+
+ var call = null;
+ this.__defineGetter__("call", function() {
+ if (call == null) {
+ // ensure the account object is created first
+ tizen.account;
+
+ call = new __callmanager();
+ }
+ return call;
+ });
var account = null;
this.__defineGetter__("account", function() {
if (account == null)
account = new __accountmanager();
+
+ // ensure the call object is always the first listener
+ // for new accounts, which means we need a backdoor to
+ // access the acount object before the getter has finished
+ // executing for the first time
+ this.__defineGetter__("__account", function() {
+ return account;
+ });
+ if (call == null)
+ call = new __callmanager();
return account;
});
}
var tizen = new __tizen();
-