This repository has been archived by the owner on Feb 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from leapfrogtechnology/CHILL-13
CHILL-13 Integrate websocket
- Loading branch information
Showing
11 changed files
with
104 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
# APP | ||
APP_LOGO={APP_LOGO} | ||
APP_LOGO_HEIGHT={LOGO_HEIGHT} | ||
APP_TITLE={APP_TITLE} | ||
|
||
# API | ||
API_ENDPOINT={API_ENDPOINT} | ||
|
||
#WEBSOCKET | ||
WEBSOCKET_ENDPOINT={WEBSOCKET_ENDPOINT} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
export default { | ||
app: { | ||
logoUrl: process.env.APP_LOGO, | ||
title: process.env.APP_TITLE || 'Chill Dashboard', | ||
logoUrl: process.env.APP_LOGO || require('../public/images/chill.png'), | ||
logoHeight: process.env.APP_LOGO_HEIGHT || '80px' | ||
}, | ||
api: { | ||
baseUrl: process.env.API_ENDPOINT || 'http://localhost:8000', | ||
endpoints: { | ||
status: '/api/status' | ||
} | ||
}, | ||
websocket: { | ||
endpoint: process.env.WEBSOCKET_ENDPOINT || 'ws://localhost:8080', | ||
reconnectTimeout: 5000 | ||
} | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import config from '../config'; | ||
|
||
const CONNECTION_ESTABLISHED_EVENT = 'ws-connection-establish'; | ||
|
||
let ws; | ||
let handlers = {}; | ||
|
||
/** | ||
* Initialize websocket client. | ||
* | ||
* @param {Object} handlers | ||
*/ | ||
export function initialize(handlers) { | ||
if (!ws) { | ||
connect(handlers); | ||
} | ||
} | ||
|
||
/** | ||
* Connect to the websocket endpoint. | ||
* | ||
* @param {Object} eventHandlers | ||
*/ | ||
function connect(eventHandlers) { | ||
ws = new WebSocket(config.websocket.endpoint); | ||
handlers = eventHandlers || {}; | ||
|
||
ws.onclose = handleClose; | ||
ws.onmessage = handleMessage; | ||
} | ||
|
||
/** | ||
* Handle websocket incoming message. | ||
* | ||
* @param {Object} e | ||
*/ | ||
function handleMessage(e) { | ||
let data = JSON.parse(e.data); | ||
|
||
// Do not call callback function for connection established event | ||
if (data.event !== CONNECTION_ESTABLISHED_EVENT) { | ||
handlers.onMessage(e, data); | ||
} | ||
} | ||
|
||
/** | ||
* Handle websocket connection closed. | ||
* | ||
*/ | ||
function handleClose() { | ||
setTimeout(() => { | ||
connect(handlers); | ||
}, config.websocket.reconnectTimeout); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters