You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
679 B
23 lines
679 B
8 years ago
|
import WebSocketClient from 'websocket.js';
|
||
|
|
||
|
const createWebSocketURL = (url) => {
|
||
|
const a = document.createElement('a');
|
||
|
|
||
|
a.href = url;
|
||
|
a.href = a.href;
|
||
|
a.protocol = a.protocol.replace('http', 'ws');
|
||
|
|
||
|
return a.href;
|
||
|
};
|
||
|
|
||
8 years ago
|
export default function getStream(streamingAPIBaseURL, accessToken, stream, { connected, received, disconnected, reconnected }) {
|
||
|
const ws = new WebSocketClient(`${createWebSocketURL(streamingAPIBaseURL)}/api/v1/streaming/?access_token=${accessToken}&stream=${stream}`);
|
||
8 years ago
|
|
||
8 years ago
|
ws.onopen = connected;
|
||
|
ws.onmessage = e => received(JSON.parse(e.data));
|
||
|
ws.onclose = disconnected;
|
||
|
ws.onreconnect = reconnected;
|
||
8 years ago
|
|
||
|
return ws;
|
||
|
};
|