<html>
<head>
+ <script type="text/javascript" src="http://localhost:7681/Tizen.Device.js"></script>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/canvasObject.js"></script>
<script type="text/javascript" src="js/imageObject.js"></script>
clearInterval(timerInterval);
}
-function initCallPage(initState)
-{
- if (initState == "dialing" || initState == "inCall")
- var buttonWidth = screenWidth * 0.6;
+function initButtons(initState)
+{
+ var incomingBar = callPage.getObj("incomingBar");
+ if (initState == "dialing" || initState == "activeCall")
+ var buttonWidth = screenWidth * 0.6;
+ else
+ var buttonWidth = (screenWidth * 0.8) / 2;
+
+ var buttonHeight = screenHeight * 0.15;
+
+ var endCallButton;
+
+ if (initState == "dialing" || initState == "activeCall")
+ {
+ endCallButton = callPage.addObject(buttonCtx, "button", {"name" : "endCallButton", "image": images.incomingDeclineButton, "icon": images.endCallIcon, "iconWidth" : 100, "iconHeight" : 100, "xLoc" : screenWidth * 0.2,
+ "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight} );
+
+ callPage.getObj("acceptCallButton").visible = false;
+ }
else
- var buttonWidth = (screenWidth * 0.8) / 2;
+ {
+ acceptCallButton = callPage.addObject(buttonCtx, "button", {"name" : "acceptCallButton", "image": images.incomingAcceptButton, "icon": images.callIcon, "iconWidth" : 100, "iconHeight" : 100, "xLoc" : screenWidth * 0.1,
+ "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight, "visible" : true} );
+
+ endCallButton = callPage.addObject(buttonCtx, "button", {"name" : "endCallButton", "image": images.incomingDeclineButton, "icon": images.endCallIcon, "iconWidth" : 100, "iconHeight" : 100,
+ "xLoc" : acceptCallButton.xLoc + acceptCallButton.width + 20, "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight} );
+
+ acceptCallButton.onClick = function(){
+ try {
+ console.log("Accepting call")
+ activeCall.accept();
+ } catch (err) {
+ console.log("Failed to accept call");
+ }
+
+ currentState = "activeCall";
+ startTimer();
+ initButtons("activeCall");
+ drawMenu(callPage);
+ };
+
+ }
+
+ endCallButton.onClick = function(){
+ try {
+ activeCall.end();
+ } catch (err) {
+ console.log("Attempting to hangup a non-active call");
+ }
+ currentState = "idle";
+ switchMenu(mainPage);
+ stopTimer();
+ };
- var buttonHeight = screenHeight * 0.15;
+}
+function initCallPage(initState)
+{
var incomingBar = callPage.addObject(mainCtx, "shape", {"name" : "incomingBar", "xLoc" : -20, "yLoc" : screenHeight * 0.2, "width" : screenWidth + 40,
"height" : screenHeight * 0.6, "fillStyle" : "#51504F", "strokeStyle" : "#B3BF3C", "lineWidth" : 5});
var callTime = callPage.addObject(mainCtx, "text", {"name" : "callTime", "xLoc" : clockIcon.xLoc + clockIcon.width + 10, "yLoc" : clockIcon.yLoc, "width" : screenWidth * 0.2,
"height" : 100, "text" : "00:00:00", "template" : callTimeTextTemplate});
-
- var endCallButton;
-
- if (initState == "dialing" || initState == "inCall")
- {
- endCallButton = callPage.addObject(buttonCtx, "button", {"name" : "endCallButton", "image": images.incomingDeclineButton, "icon": images.endCallIcon, "iconWidth" : 100, "iconHeight" : 100, "xLoc" : screenWidth * 0.2,
- "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight} );
-
- callPage.getObj("acceptCallButton").visible = false;
- }
- else
- {
- acceptCallButton = callPage.addObject(buttonCtx, "button", {"name" : "acceptCallButton", "image": images.incomingAcceptButton, "icon": images.callIcon, "iconWidth" : 100, "iconHeight" : 100, "xLoc" : screenWidth * 0.1,
- "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight, "visible" : true} );
-
- endCallButton = callPage.addObject(buttonCtx, "button", {"name" : "endCallButton", "image": images.incomingDeclineButton, "icon": images.endCallIcon, "iconWidth" : 100, "iconHeight" : 100,
- "xLoc" : acceptCallButton.xLoc + acceptCallButton.width + 20, "yLoc" : incomingBar.yLoc + incomingBar.height - buttonHeight - 50, "width" : buttonWidth, "height" : buttonHeight} );
- }
-
- endCallButton.onClick = function(){
- send({
- "api_namespace" : "tizen.ivi.dialer",
- "type": "method",
- "command": "hangup"
- });
- currentState = "idle";
- switchMenu(mainPage);
- stopTimer();
- };
+
+ initButtons(initState);
+
}
var screenWidth;
var images = [];
var objects = [];
-var ws = null;
var mouseDrag = false, mouseDown = false;
var prevXMouse, prevYMouse;
var currentNumber = " ";
var currentState = "idle";
+var activeCall = null;
+var activeService = null;
+
function onMouseDown(event)
{
}
}
-function handleMsg(incomingMsg)
-{
- if (incomingMsg.event)
- {
- switch (incomingMsg.event)
- {
- case "incoming_call":
- currentState = "incomingCall";
- initCallPage("incomingCall");
- switchMenu("callPage");
- break;
- default:
- break;
+function init()
+{
+ var activeAccount = null;
+ var listener = {
+ "onAccountUpdated": function(account) {},
+ "onAccountAdded": function(account) {
+ if (activeService == null) {
+ activeAccount = account;
+ activeService = tizen.call.getCallService(activeAccount.id);
+ }
+
+ // TODO: Remove banner warning of no available modems
+ console.log("Modem available for account: " + activeAccount.id);
+ },
+ "onAccountRemoved": function(id) {
+ if (activeAccount && activeAccount.id == id) {
+ // grab any account available
+ activeAccount = tizen.account.findServices('')[0];
+ try {
+ activeService = tizen.call.getCallService(activeAccount.id);
+ } catch (err) {
+ // TODO: Add banner letting the user know that calls can not
+ // be made since there are no active modems
+ console.log("No available modems!");
+ }
+ }
}
}
-}
-
-function connect()
-{
- var host = window.location.hostname;
- ws = new WebSocket("ws://localhost:9999/");
-
- ws.onopen = function() {
- send({
- "type": "connect",
- });
- console.log("Attempting to connect");
- };
+ tizen.account.addAccountListener(listener);
- ws.onmessage = function (e) {
- jsonMsg = JSON.parse(e.data);
- handleMsg(jsonMsg);
- console.log(e.data);
- };
+ if (tizen.account.findServices('').length == 0) {
+ // TODO: Add banner letting the user know that calls can not
+ // be made since there are no active modems
+ console.log("No available modems!");
+ }
- ws.onclose = function(e) {
- alert("Connecition closed");
- console.log(e);
+ var handler = {
+ onIncoming: function(call) {
+ activeCall = call;
+ currentState = "incomingCall";
+ updateNumber(call.callData.LineIdentification);
+ initCallPage("incomingCall");
+ switchMenu(callPage);
+ },
+ onDialing: function(call) {
+ activeCall = call;
+ },
+ onAlerting: function(call) {
+ activeCall = call;
+ },
+ onDisconnected: function(call, disconnectReason) {
+ activeCall = null;
+ },
+ onDisconnecting: function(call) {
+ },
+ onAccepted: function(call) {
+ activeCall = call;
+ },
+ onActivated: function(call) {
+ },
+ onError: function(call){
+ console.log("onError: "); console.log(call);
+ }
};
-}
+ tizen.call.addCallHandler(handler);
-function send(msg)
-{
- jsonMsg = JSON.stringify(msg);
- ws.send(jsonMsg);
- console.log("sent message: " + jsonMsg);
-}
-
-function init()
-{
- connect();
mainCanvas = document.getElementById("mainCanvas");
bgCanvas = document.getElementById("bgCanvas");
buttonCanvas = document.getElementById("buttonCanvas");
currentPage.drawMenu();
}
-
$(document).ready(function () {
init();
});
button.onClick = function(){
var dialNumber = mainPage.getObj("textArea").textObj.text;
-
- send({
- "api_namespace" : "tizen.ivi.dialer",
- "type": "method",
- "command": "dial_number",
- "number": dialNumber
- });
-
+
+ try {
+ activeService.makeCall(dialNumber);
+ } catch (err) {
+ console.log("Attempting to make call without an available modem");
+ return;
+ }
initCallPage("dialing");
updateNumber(dialNumber);
switchMenu(callPage);
function addBackButton(menuObj, xLoc, yLoc, width, height)
{
- menuObj.addObject(buttonCtx, "button", {"name" : "back", "image": images.home, "xLoc" : xLoc, "yLoc" : yLoc, "width" : width, "height" : height, "shadowOffsetX" : 0, "shadowOffsetY" : 0,
- "shadowBlur" : 12, "shadowColor" : "black",
- "onClick" : function(){switchMenu(mainMenu); send({"type": "command","command": "app_change","key_id": "mainMenu"});}
- });
+ var obj = {
+ "name" : "back",
+ "image": images.home,
+ "xLoc" : xLoc,
+ "yLoc" : yLoc,
+ "width" : width,
+ "height" : height,
+ "shadowOffsetX" : 0,
+ "shadowOffsetY" : 0,
+ "shadowBlur" : 12,
+ "shadowColor" : "black",
+ "onClick" : function() {
+ switchMenu(mainMenu);
+ // TODO: Add call to trigger the homescreen to be raised
+ }
+ }
+ menuObj.addObject(buttonCtx, obj);
}
MenuObject.prototype.drawMenu = function()