Add websocket client example

Add an example client html/js to denote subscription to BMC events via
websockets.

Change-Id: I9d07c7f720965de0272af31fc1a84faa49e901f5
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/module/obmc/wsgi/examples/websockets/client_simple.html b/module/obmc/wsgi/examples/websockets/client_simple.html
new file mode 100644
index 0000000..7d75035
--- /dev/null
+++ b/module/obmc/wsgi/examples/websockets/client_simple.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <script type="text/javascript">
+    // This simple example subscribes, via websocket, to certain events occuring
+    // on the BMC. Specfically, it's interested in an d-bus events (object
+    // creations, property changes), occuring in the d-bus namespaces
+    // /xyz/openbmc_project/logging and /xyz/openbmc_project/sensors. It's also
+    // interested in the interfaces xyz.openbmc_project.Logging.Entry and
+    // xyz.openbmc_project.Sensor.Value being added, or property changes to
+    // these interfaces.
+
+
+    // Insert code here to log-on to the BMC. At the moment of writing this
+    // example, I don't know how to do that in javascript (I had disabled the
+    // the authorization plug-in in rest_dbus.py to test this example). See
+    // https://github.com/openbmc/docs/blob/master/rest-api.md for the log-on
+    // API.
+
+    // Open a new secure websocket. The rest server on the BMC
+    // only supports the /subscribe route with websockets as of now.
+    var ws = new WebSocket("wss://<BMC IP>/subscribe");
+    // Send in array of d-bus paths and interfaces of interest over the
+    // websocket. Either/both of them can be an empty array. The arrays
+    // need to be sent in a JSON dictionary.
+    // Client will be notified of events occuring on these paths and/or
+    // interfaces.
+    var data = JSON.stringify(
+        {
+            "paths": ["/xyz/openbmc_project/logging",
+                      "/xyz/openbmc_project/sensors"],
+            "interfaces": ["xyz.openbmc_project.Logging.Entry",
+                           "xyz.openbmc_project.Sensor.Value"]
+        });
+    ws.onopen = function() {
+        // Send the JSON dictionary
+        ws.send(data);
+    };
+    ws.onmessage = function (evt) {
+        // Received a message on the websocket, the response is a JSON dict.
+        var response = JSON.parse(evt.data);
+        for (var key in response) {
+            if (response.hasOwnProperty(key)) {
+                var value = response[key];
+                if ("path" == key) {
+                    // If the d-bus path is in the response, let's do a GET on
+                    // that path.
+                    var xhr = new XMLHttpRequest();
+                    var url = "https://<BMC IP>" + value;
+                    xhr.open("GET", url, true);
+                    xhr.setRequestHeader("Content-type", "application/json");
+                    xhr.send();
+                }
+            }
+        }
+    };
+  </script>
+</head>
+</html>