Landing a partial implementation of the proposed tizen.call web interface, focusing
authorRusty Lynch <rusty.lynch@intel.com>
Thu, 16 Aug 2012 00:57:42 +0000 (17:57 -0700)
committerRusty Lynch <rusty.lynch@intel.com>
Thu, 16 Aug 2012 00:57:42 +0000 (17:57 -0700)
on the callhandler portion of the API

Tizen.Device.js
homescreen.js
index.html
main.c

index f2aecdb..22018c1 100644 (file)
@@ -25,24 +25,191 @@ var __application = function () {
     }
 }
 
-var __dialer = function () {
-    var callback;
-
+var __callmanager = function () {
+    var activeCall = null;
+    var callHandlers = new Array();
     var socket = new WebSocket("ws://" + document.URL.substring(7), "dialer-protocol");
+    var callService = new __callservice(socket);
+
     socket.onmessage = function(msg) {
-        appList = JSON.parse(msg.data);
-       if (callback)
-           callback(JSON.parse(msg.data));
+        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")
+                for (var index in callHandlers)
+                    callHandlers[index].onIncoming(activeCall);
+            if (ev.State == "dialing")
+                for (var index in callHandlers)
+                    callHandlers[index].onDialing(activeCall);
+            else if (ev.State == "alerting")
+                for (var index in callHandlers)
+                    callHandlers[index].onAlerting(activeCall);
+            else if (ev.State == "hold")
+                for (var index in callHandlers)
+                    callHandlers[index].onHold(activeCall);
+            else if (ev.State == "waiting")
+                for (var index in callHandlers)
+                    callHandlers[index].onWaiting(activeCall);
+            else if (ev.State == "disconnected")
+                for (var index in callHandlers)
+                    callHandlers[index].onDisconnected(activeCall);
+            else if (ev.State == "disconnecting")
+                for (var index in callHandlers)
+                    callHandlers[index].onDisconnecting(activeCall);
+            else if (ev.State == "accepted")
+                for (var index in callHandlers)
+                    callHandlers[index].onAccepted(activeCall);
+            else if (ev.State == "remotelyheld")
+                for (var index in callHandlers)
+                    callHandlers[index].onRemotelyHeld(activeCall);
+            else if (ev.State == "active")
+                for (var index in callHandlers)
+                    callHandlers[index].onActivated(activeCall);
+            else if (ev.State == "initializing")
+                for (var index in callHandlers)
+                    callHandlers[index].onInitializing(activeCall);
+            else if (ev.State == "initialized")
+                for (var index in callHandlers)
+                    callHandlers[index].onInitialized(activeCall);
+        }
     }
 
-    this.addDialerEventListener = function(eventCallback, errorCallback) {
-       callback = eventCallback;
+    this.history = null;
+    this.isCallInProgress = function() { 
+        return activeCall != null; 
+    }
+    this.addCallHandler = function(handler, callServiceType, serviceName) { 
+        callHandlers.push(handler);
+    }
+    this.removeCallHandler = function(handler) { 
+        var tmp = new Array();
+        for (var item in callHandlers)
+            if (item != handler)
+                tmp.push(item);
+        callHandlers = tmp;
+        
+    }
+    this.getCallSevice = function(service) { 
+        return callService;
+    }
+}
+
+var __callservice = function (wsi) {
+    var socket = wsi;
+
+    this.launchDialer = function(remotePartyId) {
+        socket.send(JSON.stringify({ "cmd": "launchDialer" }));
+    }
+
+    var voicemailNumbers = new Array();
+    this.__defineGetter__("voiceNumbers", function() {
+        return voicemailNumbers;
+    });
+    
+    this.makeCall = function(remotePartyId, handler, extension, localVideoOn) {
+        socket.send(JSON.stringify({"cmd": "makeCall", "remotePartyId": remotePartyId, "extension": extension, "localVideoOn": localVideoOn}));
+    }
+}
+
+var __call = function(manager, callService, wsi, data) {
+    var socket = wsi;
+
+    var callData = data;
+    this.__defineGetter__("callData", function() {
+        return callData;
+    });
+    
+    var streamList = new Array();
+    this.__defineGetter__("streamList", function() {
+        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"}));
+    }
+    this.reject = function() {
+        socket.send(JSON.stringify({"cmd": "reject"}));
+    }
+    this.wait = function() {
+        socket.send(JSON.stringify({"cmd": "wait"}));
+    }
+    this.redirect = function(rid) {
+        socket.send(JSON.stringify({"cmd": "redirect"}));
+    }
+    this.end = function() {
+        socket.send(JSON.stringify({"cmd": "end"}));
+    }
+    this.hold = function() {
+        socket.send(JSON.stringify({"cmd": "hold"}));
+    }
+    this.activate = function() {
+        socket.send(JSON.stringify({"cmd": "activate"}));
+    }
+    this.migrate = function(callService, callParticipant) {
+        socket.send(JSON.stringify({"cmd": "migrate", "callService": callService, "callParticipant": callParticipant}));
+    }
+    this.merge = function(otherCall) {
+        socket.send(JSON.stringify({"cmd": "merge", "otherCall": otherCall}));
+    }
+    this.drop = function(participant) {
+        socket.send(JSON.stringify({"cmd": "drop", "participant": participant}));
+    }
+    this.split = function(participant) {
+        socket.send(JSON.stringify({"cmd": "split", "participant": participant}));
+    }
+    this.addParticipant = function(remotePartyId, successCallback, errorCallback) {
+    }
+    this.addStream = function(addStream, successCallback, errorCallback) {
+    }
+    this.removeStream = function(addStream, successCallback, errorCallback) {
+    }
+    this.setAudioVolume = function(volume, successCallback, errorCallback) {
+    }
+    this.setMicrophoneSensitivity = function(sensitivity, successCallback, errorCallback) {
+    }
+    this.setLocalVideoEnabled = function(onoff, successCallback, errorCallback) {
+    }
+    this.sendDTMF = function(tones, duration, interval, successCallback, errorCallback) {
+    }
+    this.record = function() {
+    }
+    this.pause = function() {
     }
 }
 
 var __tizen = function() {
-    this.application = new __application();
-    this.dialer = new __dialer();
+    var application = null;
+    this.__defineGetter__("application", function() {
+        if (application == null)
+            application = new __application();
+        return application;
+    });
+
+    var call = null;
+    this.__defineGetter__("call", function() {
+        if (call == null)
+            call = new __callmanager();
+        return call;
+    });
+
 }
 
 var tizen = new __tizen();
index d4c5728..305fb9b 100644 (file)
@@ -17,9 +17,73 @@ function createAppEntry(index) {
 }
 
 document.body.onload = function() {
-    tizen.dialer.addDialerEventListener(function (ev) {
-        console.log(ev);
-    });
+    var handler = {
+        onCallList: function (callList) {
+            console.log("onCallList: " + callList);
+        },
+        onIncoming: function(call) {
+            console.log("Incoming call from " + call.callData.LineIdentification);
+        },
+        onDialing: function(call) {
+            console.log("onDialing: "); console.log(call);
+        },
+        onAlerting: function(call) {
+            console.log("onAlerting: "); console.log(call);
+        },
+        onHold: function(call) {
+            console.log("onHold: "); console.log(call);
+        },
+        onWaiting: function(call) {
+            console.log("onWaiting: "); console.log(call);
+        },
+        onDisconnected: function(call, disconnectReason) {
+            console.log("onDisconnected: " + call + " " + disconnectReason);
+        },
+        onDisconnecting: function(call) {
+            console.log("onDisconnecting: "); console.log(call);
+        },
+        onAccepted: function(call) {
+            console.log("onAccepted: "); console.log(call);
+        },
+        onRemotelyHeld: function(call) {
+            console.log("onRemotelyHeld: "); console.log(call);
+        },
+        onActivated: function(call) {
+            console.log("onActivated: "); console.log(call);
+        },
+        onInitializing: function(call) {
+            console.log("onInitializing: "); console.log(call);
+        },
+        onInitialized: function(call) {
+            console.log("onInitialized: "); console.log(call);
+        },
+        onCapabilitiesChanged: function(call) {
+            console.log("onCapabilitiesChanged: "); console.log(call);
+        },
+        onParticipantsChanged: function (call, addedP, removedP) {
+            console.log("onParticipantsChanged: " + call + " " + addedP + " " + removedP);
+        },
+        onStreamsChanged: function(call, addedS, removedS){
+            console.log("onStreamsChanged: " + call + " " + addedP + " " + removedP);
+        },
+        onCallSplit: function(confCall, splitCall) {
+            console.log("onCallSplit: " + confCall + " " + splitCall);
+        },
+        onRecordingStarted: function (call) {
+            console.log("onRecordingStarted: "); console.log(call);
+        },
+        onRecordingStopped: function(call) {
+            console.log("onRecordingStopped: "); console.log(call);
+        },
+        onCallChanged: function(call) {
+            console.log("onCallChanged: "); console.log(call);
+        },
+        onError: function(call){
+            console.log("onError: "); console.log(call);
+        }
+    };
+    tizen.call.addCallHandler(handler);
+
     tizen.application.addAppInfoEventListener(function (list) {
        var content = document.getElementById('content');
        while (content.hasChildNodes())
index a04c798..c2fade9 100644 (file)
@@ -7,7 +7,7 @@
 .appEntry {
   display: inline-block;
   font-size: 12pt;
-  background-color: lightgray;
+  background-color: yellow;
   border-style: solid;
   border-width: 20px;
   border-color: white;
diff --git a/main.c b/main.c
index 0f5c40c..49ebf55 100644 (file)
--- a/main.c
+++ b/main.c
@@ -429,6 +429,8 @@ void call_added_cb(void *data, DBusMessage *msg)
     DBusMessageIter iter, properties;
     const char *path;
 
+    json_t *object = json_object();
+
     dbus_message_iter_init(msg, &iter);
     dbus_message_iter_get_basic(&iter, &path);
 
@@ -449,6 +451,7 @@ void call_added_cb(void *data, DBusMessage *msg)
         dbus_message_iter_get_basic(&value, &v);
 
         printf(" %s=%s ", key, v);
+        json_object_set(object, key, json_string(v));
 
         dbus_message_iter_next(&properties);
     }
@@ -461,11 +464,19 @@ void call_added_cb(void *data, DBusMessage *msg)
                               "PropertyChanged", 
                               call_properties_changed_cb, 
                               NULL);
+
+    char *dump = json_dumps(object, 0);
+    libwebsockets_broadcast(&protocols[PROTOCOL_DIALER], dump, strlen(dump));
+    free(dump);
 }
 
 void call_removed_cb(void *data, DBusMessage *msg)
 {
-    printf("Call removed\n");
+    json_t *object = json_object();
+    json_object_set(object, "type", json_string("CallRemoved"));
+    char *dump = json_dumps(object, 0);
+    libwebsockets_broadcast(&protocols[PROTOCOL_DIALER], dump, strlen(dump));
+    free(dump);
 }
 
 void