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);
86 this.isCallInProgress = function() {
87 return activeCall != null;
89 this.addCallHandler = function(handler, callServiceType, serviceName) {
90 callHandlers.push(handler);
92 this.removeCallHandler = function(handler) {
93 var tmp = new Array();
94 for (var item in callHandlers)
100 this.getCallSevice = function(service) {
105 var __callservice = function (wsi) {
108 this.launchDialer = function(remotePartyId) {
109 socket.send(JSON.stringify({ "cmd": "launchDialer" }));
112 var voicemailNumbers = new Array();
113 this.__defineGetter__("voiceNumbers", function() {
114 return voicemailNumbers;
117 this.makeCall = function(remotePartyId, handler, extension, localVideoOn) {
120 "remotePartyId": remotePartyId.toString(),
121 "extension": extension,
122 "localVideoOn": localVideoOn
124 socket.send(JSON.stringify(c));
128 var __call = function(manager, callService, wsi, data) {
132 this.__defineGetter__("callData", function() {
136 var streamList = new Array();
137 this.__defineGetter__("streamList", function() {
141 var manager = manager;
142 this.__defineGetter__("manager", function() {
146 var callService = callService;
147 this.getCallService = function(serviceName) {
151 this.accept = function() {
152 socket.send(JSON.stringify({"cmd": "accept"}));
154 this.reject = function() {
155 socket.send(JSON.stringify({"cmd": "reject"}));
157 this.wait = function() {
158 socket.send(JSON.stringify({"cmd": "wait"}));
160 this.redirect = function(rid) {
161 socket.send(JSON.stringify({"cmd": "redirect"}));
163 this.end = function() {
164 socket.send(JSON.stringify({"cmd": "end"}));
166 this.hold = function() {
167 socket.send(JSON.stringify({"cmd": "hold"}));
169 this.activate = function() {
170 socket.send(JSON.stringify({"cmd": "activate"}));
172 this.migrate = function(callService, callParticipant) {
173 socket.send(JSON.stringify({"cmd": "migrate", "callService": callService, "callParticipant": callParticipant}));
175 this.merge = function(otherCall) {
176 socket.send(JSON.stringify({"cmd": "merge", "otherCall": otherCall}));
178 this.drop = function(participant) {
179 socket.send(JSON.stringify({"cmd": "drop", "participant": participant}));
181 this.split = function(participant) {
182 socket.send(JSON.stringify({"cmd": "split", "participant": participant}));
184 this.addParticipant = function(remotePartyId, successCallback, errorCallback) {
186 this.addStream = function(addStream, successCallback, errorCallback) {
188 this.removeStream = function(addStream, successCallback, errorCallback) {
190 this.setAudioVolume = function(volume, successCallback, errorCallback) {
192 this.setMicrophoneSensitivity = function(sensitivity, successCallback, errorCallback) {
194 this.setLocalVideoEnabled = function(onoff, successCallback, errorCallback) {
196 this.sendDTMF = function(tones, duration, interval, successCallback, errorCallback) {
198 this.record = function() {
200 this.pause = function() {
204 var __tizen = function() {
205 var application = null;
206 this.__defineGetter__("application", function() {
207 if (application == null)
208 application = new __application();
213 this.__defineGetter__("call", function() {
215 call = new __callmanager();
221 var tizen = new __tizen();