-/* The subscribe method takes a window element id and object id.
- Any log events for that particular object id are sent to that window element. */
-function subscribeToEventLog (elementId) {
- // if websockets are not supported by browser, do not subscribe for events
- websocketsSupported = ('WebSocket' in window);
- if (websocketsSupported == false) {
- return;
- }
-
- // grab websocket connection from window, if one exists
- event_log_disp = $(window).data("arv-websocket");
- if (event_log_disp == null) {
- // create the event log dispatcher
- websocket_url = $('meta[name=arv-websocket-url]').attr("content");
- if (websocket_url == null)
- return;
-
- event_log_disp = new WebSocket(websocket_url);
-
- event_log_disp.onopen = onEventLogDispatcherOpen;
- event_log_disp.onmessage = onEventLogDispatcherMessage;
-
- // store websocket in window to allow reuse when multiple divs subscribe for events
- $(window).data("arv-websocket", event_log_disp);
- }
+/* Subscribe to websockets event log. Do nothing if already connected. */
+function subscribeToEventLog () {
+ // if websockets are not supported by browser, do not subscribe for events
+ websocketsSupported = ('WebSocket' in window);
+ if (websocketsSupported == false) {
+ return;
+ }
+
+ // check if websocket connection is already stored on the window
+ event_log_disp = $(window).data("arv-websocket");
+ if (event_log_disp == null) {
+ // need to create new websocket and event log dispatcher
+ websocket_url = $('meta[name=arv-websocket-url]').attr("content");
+ if (websocket_url == null)
+ return;
+
+ event_log_disp = new WebSocket(websocket_url);
+
+ event_log_disp.onopen = onEventLogDispatcherOpen;
+ event_log_disp.onmessage = onEventLogDispatcherMessage;
+
+ // store websocket in window to allow reuse when multiple divs subscribe for events
+ $(window).data("arv-websocket", event_log_disp);
+ }