1 ///////////////////////////////////////////////////////////////////////////////
2 // This is a partial implementation of the tizen.application web specification
3 // which using a websocket server for implementing the native backend
5 var __application = function () {
9 var socket = new WebSocket("ws://" + document.URL.substring(7), "app-list-protocol");
10 socket.onmessage = function(msg) {
11 appList = JSON.parse(msg.data);
16 this.launch = function (id, successCallback, errorCallback, argument) {
17 var cmd = {"cmd": "launch", "index": id};
18 socket.send(JSON.stringify(cmd));
20 this.getAppInfo = function(id) {
23 this.addAppInfoEventListener = function(eventCallback, errorCallback) {
24 callback = eventCallback;
28 var __callmanager = function () {
29 var activeCall = null;
30 var callHandlers = new Array();
31 var socket = new WebSocket("ws://" + document.URL.substring(7), "dialer-protocol");
32 var callService = new __callservice(socket);
34 socket.onmessage = function(msg) {
35 var ev = JSON.parse(msg.data);
37 if (activeCall == null) {
38 activeCall = new __call(this, callService, socket, ev);
41 if (ev.type && ev.type == "CallRemoved") {
46 if (ev.State == "incoming")
47 for (var index in callHandlers)
48 callHandlers[index].onIncoming(activeCall);
49 if (ev.State == "dialing")
50 for (var index in callHandlers)
51 callHandlers[index].onDialing(activeCall);
52 else if (ev.State == "alerting")
53 for (var index in callHandlers)
54 callHandlers[index].onAlerting(activeCall);
55 else if (ev.State == "hold")
56 for (var index in callHandlers)
57 callHandlers[index].onHold(activeCall);
58 else if (ev.State == "waiting")
59 for (var index in callHandlers)
60 callHandlers[index].onWaiting(activeCall);
61 else if (ev.State == "disconnected")
62 for (var index in callHandlers)
63 callHandlers[index].onDisconnected(activeCall);
64 else if (ev.State == "disconnecting")
65 for (var index in callHandlers)
66 callHandlers[index].onDisconnecting(activeCall);
67 else if (ev.State == "accepted")
68 for (var index in callHandlers)
69 callHandlers[index].onAccepted(activeCall);
70 else if (ev.State == "remotelyheld")
71 for (var index in callHandlers)
72 callHandlers[index].onRemotelyHeld(activeCall);
73 else if (ev.State == "active")
74 for (var index in callHandlers)
75 callHandlers[index].onActivated(activeCall);
76 else if (ev.State == "initializing")
77 for (var index in callHandlers)
78 callHandlers[index].onInitializing(activeCall);
79 else if (ev.State == "initialized")
80 for (var index in callHandlers)
81 callHandlers[index].onInitialized(activeCall);
82 } else if (ev.ModemAdded) {
83 tizen.account.addAccount(new tizen.Account(ev.ModemAdded, ev));
84 } else if (ev.ModemRemoved) {
85 tizen.account.deleteAccount(ev.ModemRemoved);
90 this.isCallInProgress = function() {
91 return activeCall != null;
93 this.addCallHandler = function(handler, callServiceType, serviceName) {
94 callHandlers.push(handler);
96 this.removeCallHandler = function(handler) {
97 var tmp = new Array();
98 for (var item in callHandlers)
104 this.getCallSevice = function(service) {
109 var __callservice = function (wsi) {
112 this.launchDialer = function(remotePartyId) {
113 socket.send(JSON.stringify({ "cmd": "launchDialer" }));
116 var voicemailNumbers = new Array();
117 this.__defineGetter__("voiceNumbers", function() {
118 return voicemailNumbers;
121 this.makeCall = function(remotePartyId, handler, extension, localVideoOn) {
124 "remotePartyId": remotePartyId.toString(),
125 "extension": extension,
126 "localVideoOn": localVideoOn
128 socket.send(JSON.stringify(c));
132 var __call = function(manager, callService, wsi, data) {
136 this.__defineGetter__("callData", function() {
140 var streamList = new Array();
141 this.__defineGetter__("streamList", function() {
145 var manager = manager;
146 this.__defineGetter__("manager", function() {
150 var callService = callService;
151 this.getCallService = function(serviceName) {
155 this.accept = function() {
156 socket.send(JSON.stringify({"cmd": "accept"}));
158 this.reject = function() {
159 socket.send(JSON.stringify({"cmd": "reject"}));
161 this.wait = function() {
162 socket.send(JSON.stringify({"cmd": "wait"}));
164 this.redirect = function(rid) {
165 socket.send(JSON.stringify({"cmd": "redirect"}));
167 this.end = function() {
168 socket.send(JSON.stringify({"cmd": "end"}));
170 this.hold = function() {
171 socket.send(JSON.stringify({"cmd": "hold"}));
173 this.activate = function() {
174 socket.send(JSON.stringify({"cmd": "activate"}));
176 this.migrate = function(callService, callParticipant) {
177 socket.send(JSON.stringify({"cmd": "migrate", "callService": callService, "callParticipant": callParticipant}));
179 this.merge = function(otherCall) {
180 socket.send(JSON.stringify({"cmd": "merge", "otherCall": otherCall}));
182 this.drop = function(participant) {
183 socket.send(JSON.stringify({"cmd": "drop", "participant": participant}));
185 this.split = function(participant) {
186 socket.send(JSON.stringify({"cmd": "split", "participant": participant}));
188 this.addParticipant = function(remotePartyId, successCallback, errorCallback) {
190 this.addStream = function(addStream, successCallback, errorCallback) {
192 this.removeStream = function(addStream, successCallback, errorCallback) {
194 this.setAudioVolume = function(volume, successCallback, errorCallback) {
196 this.setMicrophoneSensitivity = function(sensitivity, successCallback, errorCallback) {
198 this.setLocalVideoEnabled = function(onoff, successCallback, errorCallback) {
200 this.sendDTMF = function(tones, duration, interval, successCallback, errorCallback) {
202 this.record = function() {
204 this.pause = function() {
208 var __accountmanager = function() {
209 var listeners = new Array();
210 var accounts = new Array();
212 this.findServices = function(filter) {
213 /* brain dead matching, patches accepted */
214 var result = new Array();
215 if (accounts.length == 0)
218 for (var i in accounts) {
220 for (var f in filter)
221 if (a[f] && a[f] == filter[f]) {
230 if (result.length == 0)
231 result.push(accounts[0]);
235 this.getAccountById = function(accountid) {
236 for (var i in accounts)
237 if (accounts[i].id == accountid)
241 this.deleteAccount = function(accountid) {
243 for (var i in accounts)
244 if (accountid != accounts[i].id)
248 for (var i in listeners)
249 listeners[i].onAccountRemoved(accountid);
251 this.addAccount = function(account) {
252 accounts.push(account);
253 for (var i in listeners)
254 listeners[i].onAccountAdded(account);
256 this.addAccountListener = function(observer, errorCallback) {
257 listeners.push(observer);
258 return listeners.length;
260 this.removeAccountListener = function(handle) {
262 for (var i in listeners)
264 l.push(listeners[i]);
269 var __tizen = function() {
270 var application = null;
271 this.__defineGetter__("application", function() {
272 if (application == null)
273 application = new __application();
278 this.__defineGetter__("call", function() {
280 call = new __callmanager();
284 this.Account = function (accountId, accountProperties) {
286 var properties = accountProperties;
287 this.__defineGetter__("id", function() {
290 for (var p in properties) {
291 this.__defineGetter__(p, function() {
292 return properties[p];
297 this.__defineGetter__("account", function() {
299 account = new __accountmanager();
304 var tizen = new __tizen();