From 7478cbef9867257e05a3388611473f7b18cfc464 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 15 Oct 2015 17:07:18 +0200 Subject: [PATCH] Init ws connection. --- public/assets/chat/chat.coffee | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/public/assets/chat/chat.coffee b/public/assets/chat/chat.coffee index c9b5fe322..9c7ee77c3 100644 --- a/public/assets/chat/chat.coffee +++ b/public/assets/chat/chat.coffee @@ -45,6 +45,27 @@ do($ = window.jQuery, window) -> input: @onInput ).autoGrow { extraLine: false } + if !window.WebSocket + console.log('no websockets available') + return + + zammad_host = 'ws://localhost:6042' + @ws = new window.WebSocket(zammad_host) + console.log("connecting ws #{zammad_host}") + + @ws.onopen = => + console.log('ws connected') + + @ws.onmessage = (e) => + pipe = JSON.parse( e.data ) + console.log 'debug', 'ws:onmessage', pipe + + @ws.onclose = (e) => + console.log 'debug', 'close websocket connection' + + @ws.onerror = (e) => + console.log 'debug', 'ws:onerror', e + checkForEnter: (event) => if not event.shiftKey and event.keyCode is 13 event.preventDefault()