闭社主体 forked from https://github.com/tootsuite/mastodon
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.

12 lines
465 B

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