added reference/test javascript api to websocket plugin
authorKevron Rees <kevron_m_rees@linux.intel.com>
Mon, 20 Aug 2012 18:07:42 +0000 (11:07 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Mon, 20 Aug 2012 18:07:42 +0000 (11:07 -0700)
plugins/tcpsink/test/api.js [new file with mode: 0644]
plugins/tcpsink/test/index.html [new file with mode: 0644]
plugins/tcpsink/test/style.css [new file with mode: 0644]

diff --git a/plugins/tcpsink/test/api.js b/plugins/tcpsink/test/api.js
new file mode 100644 (file)
index 0000000..fbc1151
--- /dev/null
@@ -0,0 +1,91 @@
+/*\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
diff --git a/plugins/tcpsink/test/index.html b/plugins/tcpsink/test/index.html
new file mode 100644 (file)
index 0000000..c02273e
--- /dev/null
@@ -0,0 +1,13 @@
+<!doctype html>\r
+<html lang="en">\r
+<head>\r
+    <title>IVI API Tester</title>\r
+    <meta charset="utf-8">\r
+    <link rel="stylesheet" href="style.css"/>\r
+</head>\r
+<body onload="init()">\r
+    <div id="result">\r
+    </div>\r
+    <script src="api.js"></script>\r
+</body>\r
+</html>\r
diff --git a/plugins/tcpsink/test/style.css b/plugins/tcpsink/test/style.css
new file mode 100644 (file)
index 0000000..fd7ef72
--- /dev/null
@@ -0,0 +1,8 @@
+\r
+.PassClass {\r
+    color: green;\r
+}\r
+\r
+.FailClass {\r
+    color: red;\r
+}\r