2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 var app = tizen.application.getCurrentApplication();
18 var gServiceAppId = "r9vrpxzuyp.HybridServiceApp";
19 var gWsUri = "ws://127.0.0.1:8080/ipc?src=" + app.appInfo.id + ".HybridWebApp&dest=r9vrpxzuyp.HybridServiceApp";
21 var isStarting = false;
23 $(document).delegate("#main", "pageinit", function() {
24 $("#main .ui-btn-back").bind("vclick", function() {
25 tizen.application.getCurrentApplication().exit();
29 $("#btn-start").bind("vclick", function(){
32 alert("Already Started");
33 } else if(isStarting){
34 alert("Now starting...");
41 $("#btn-stop").bind("vclick", function(){
49 $("#btn-clear").bind("vclick", function(){
50 $("#logs").empty().listview("refresh");
55 function startWebSocket() {
56 gWebSocket = new WebSocket(gWsUri);
59 gWebSocket.onopen = function(evt) {
62 gWebSocket.onclose = function(evt) {
65 gWebSocket.onmessage = function(evt) {
68 gWebSocket.onerror = function(evt) {
73 function sendCommand(command){
74 var jsondata = '{"command" : "' + command + '"}';
76 gWebSocket.send(JSON.stringify(jsondata));
77 writeToScreen("Sending: " + command);
80 function onOpen(evt) {
81 writeToScreen("Ready");
82 sendCommand("connect");
85 function onClose(evt) {
86 writeToScreen("Disconnected");
90 function onMessage(evt) {
91 var message = JSON.parse(evt.data).server;
93 writeToScreen("Received : " + message);
95 if(message == "WELCOME"){
97 }else if(message == "stopped"){
100 }else if(message == "exit"){
105 function onError(evt) {
106 writeToScreen("ERROR:" + evt.data);
109 function writeToScreen(message) {
110 var today = new Date(),
111 time = today.getFullYear() + "-" + today.getMonth() + "-" + today.getDate() + " "
112 + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds() + "." + today.getMilliseconds(),
113 str = '<li class="ui-li-has-multiline ui-li-text-ellipsis">'
115 + '<span class="ui-li-text-sub">'
119 $("#logs").append(str).listview("refresh");
124 tizen.application.getAppsContext(onGetAppsContextSuccess, onGetAppsContextError);
126 writeToScreen("Get AppContext Error");
130 function onGetAppsContextSuccess(contexts) {
131 for (var i = 0; i < contexts.length; i++) {
132 var appInfo = tizen.application.getAppInfo(contexts[i].appId);
133 console.log(appInfo.id);
134 if(appInfo.id == gServiceAppId){
135 console.log("Running Service App found");
139 if (i >= contexts.length) {
140 console.log("Running Service App not found. Trying to launch it");
147 function onGetAppsContextError(err) {
148 console.log("getAppsContext exc");
151 function listInstalledApps() {
153 tizen.application.getAppsInfo(getAppsInfoSuccessCB, getAppsInfoErrorCB);
155 writeToScreen("Get Installed App Info Error");
159 function getAppsInfoSuccessCB(apps) {
160 for (var i = 0; i < apps.length; i++) {
161 if(apps[i].id == gServiceAppId){
162 console.log("Found installed Service App")
166 if(i >= apps.length){
167 writeToScreen("Service App not installed");
173 function getAppsInfoErrorCB(err) {
174 console.log("getAppsInfo failed");
177 function launchServiceApp(){
178 function onSuccess() {
179 console.log("Service App launched successfully!");
180 console.log("Restart...");
184 function onError(err) {
185 console.log("Service Applaunch failed");
189 tizen.application.launch(gServiceAppId, onSuccess, onError);
191 alert("launch exc:" + exc.message);