Make the streaming API also handle websockets (because trying to get the browser EventSource interface to
work flawlessly was a nightmare). WARNING: This commit makes the web UI connect to the streaming API instead of ActionCable like before. This means that if you are upgrading, you should set that up beforehand.
This commit is contained in:
21
app/assets/javascripts/components/stream.jsx
Normal file
21
app/assets/javascripts/components/stream.jsx
Normal file
@ -0,0 +1,21 @@
|
||||
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;
|
||||
};
|
||||
|
||||
export default function getStream(accessToken, stream, { connected, received, disconnected }) {
|
||||
const ws = new WebSocketClient(`${createWebSocketURL(STREAMING_API_BASE_URL)}/api/v1/streaming/?access_token=${accessToken}&stream=${stream}`);
|
||||
|
||||
ws.onopen = connected;
|
||||
ws.onmessage = e => received(JSON.parse(e.data));
|
||||
ws.onclose = disconnected;
|
||||
|
||||
return ws;
|
||||
};
|
Reference in New Issue
Block a user