1
0
mirror of https://github.com/whippyshou/mastodon synced 2024-12-25 20:18:24 +09:00
whippy-edition/app/javascript/mastodon/stream.js
2017-05-04 15:55:13 +02:00

13 lines
465 B
JavaScript

import WebSocketClient from 'websocket.js';
export default function getStream(streamingAPIBaseURL, accessToken, stream, { connected, received, disconnected, reconnected }) {
const ws = new WebSocketClient(`${streamingAPIBaseURL}/api/v1/streaming/?access_token=${accessToken}&stream=${stream}`);
ws.onopen = connected;
ws.onmessage = e => received(JSON.parse(e.data));
ws.onclose = disconnected;
ws.onreconnect = reconnected;
return ws;
};