From 316b155a42a4d00fb835438ce7e0401a64e59add Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 31 Oct 2016 08:59:23 -0400 Subject: PLT-3562 Switch websocket over to post-connect authentication (#4327) * Switch websocket over to post-connect authentication * Add ability to specify token in websocket js driver, add unit tests * Temporarily disable client websocket tests until issues are resolved * Minor refactoring and fix status test * Add isAuthenticated method to WebConn and minor status updates --- webapp/client/websocket_client.jsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'webapp/client') diff --git a/webapp/client/websocket_client.jsx b/webapp/client/websocket_client.jsx index 035e30be5..760c62b59 100644 --- a/webapp/client/websocket_client.jsx +++ b/webapp/client/websocket_client.jsx @@ -18,7 +18,7 @@ export default class WebSocketClient { this.closeCallback = null; } - initialize(connectionUrl) { + initialize(connectionUrl, token) { if (this.conn) { return; } @@ -30,6 +30,10 @@ export default class WebSocketClient { this.conn = new WebSocket(connectionUrl); this.conn.onopen = () => { + if (token) { + this.sendMessage('authentication_challenge', {token}); + } + if (this.connectFailCount > 0) { console.log('websocket re-established connection'); //eslint-disable-line no-console if (this.reconnectCallback) { @@ -68,7 +72,7 @@ export default class WebSocketClient { setTimeout( () => { - this.initialize(connectionUrl); + this.initialize(connectionUrl, token); }, retryTime ); @@ -152,12 +156,12 @@ export default class WebSocketClient { } } - userTyping(channelId, parentId) { + userTyping(channelId, parentId, callback) { const data = {}; data.channel_id = channelId; data.parent_id = parentId; - this.sendMessage('user_typing', data); + this.sendMessage('user_typing', data, callback); } getStatuses(callback) { -- cgit v1.2.3-1-g7c22