+/*\r
+ * Copyright (c) 2012, Intel Corporation.\r
+ *\r
+ * This program is licensed under the terms and conditions of the\r
+ * Apache License, version 2.0. The full text of the Apache License is at\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ */\r
+\r
+var vehicle;\r
+var PRINT = {\r
+ moduleName : "IVI API",\r
+ logElement : null,\r
+ init : function(log_id) {\r
+ this.logElement = document.getElementById(log_id);\r
+ },\r
+\r
+ setModule : function(moduleName) {\r
+ this.moduleName = moduleName;\r
+ },\r
+\r
+ pass : function(msg) {\r
+ this.logElement.innerHTML += "<div class='PassClass'> " + this.moduleName + " : Pass : " + msg + "</div>";\r
+ },\r
+\r
+ fail : function(msg) {\r
+ this.logElement.innerHTML += "<div class='FailClass'> " + this.moduleName + " : Fail : " + msg + "</div>";\r
+ },\r
+\r
+ log : function(msg) {\r
+ this.logElement.innerHTML += "<div class='LogClass'> " + msg + "</div>";\r
+ },\r
+}\r
+\r
+var myJSONObject = {\r
+ "type" : "method",\r
+ "name": "GetProperty",\r
+ "Arguments": [\r
+ "Velocity"\r
+ ],\r
+ "transactionid": "0f234002-95b8-48ac-aa06-cb49e372cc1c"\r
+};\r
+\r
+function Vehicle()\r
+{\r
+ var self = this;\r
+ \r
+ function init() {\r
+ if ("WebSocket" in window)\r
+ {\r
+ PRINT.pass("The browser is websocket capable");\r
+\r
+ this.socket = new WebSocket("ws://localhost:23000/echo");\r
+ this.socket.onopen = function()\r
+ {\r
+ PRINT.pass("Connection OPEN");\r
+ this.send(JSON.stringify(myJSONObject));\r
+ };\r
+ this.socket.onmessage = function (e) \r
+ {\r
+ self.receive(e.data);\r
+ };\r
+ this.socket.onclose = function()\r
+ {\r
+ PRINT.fail("Connection CLOSED");\r
+ };\r
+ }\r
+ else\r
+ {\r
+ PRINT.fail("This browser doesn't ppear to support websockets!");\r
+ }\r
+ }\r
+ init();\r
+}\r
+\r
+Vehicle.prototype.send = function(msg)\r
+{\r
+\r
+}\r
+\r
+Vehicle.prototype.receive = function(msg)\r
+{\r
+ PRINT.log("Message Received: "+msg);\r
+ var data = JSON.parse(msg);\r
+ console.log(data);\r
+}\r
+\r
+function init() {\r
+ PRINT.init("result");\r
+ vehicle = new Vehicle();\r
+}\r