|
|
|
@ -2,11 +2,11 @@ import WebSocketClient from 'websocket.js'; |
|
|
|
|
|
|
|
|
|
const randomIntUpTo = max => Math.floor(Math.random() * Math.floor(max)); |
|
|
|
|
|
|
|
|
|
export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onDisconnect() {}, onReceive() {} })) { |
|
|
|
|
export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onConnect() {}, onDisconnect() {}, onReceive() {} })) { |
|
|
|
|
return (dispatch, getState) => { |
|
|
|
|
const streamingAPIBaseURL = getState().getIn(['meta', 'streaming_api_base_url']); |
|
|
|
|
const accessToken = getState().getIn(['meta', 'access_token']); |
|
|
|
|
const { onDisconnect, onReceive } = callbacks(dispatch, getState); |
|
|
|
|
const { onConnect, onDisconnect, onReceive } = callbacks(dispatch, getState); |
|
|
|
|
|
|
|
|
|
let polling = null; |
|
|
|
|
|
|
|
|
@ -28,6 +28,8 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({ |
|
|
|
|
if (pollingRefresh) { |
|
|
|
|
clearPolling(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onConnect(); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
disconnected () { |
|
|
|
@ -47,6 +49,8 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({ |
|
|
|
|
clearPolling(); |
|
|
|
|
pollingRefresh(dispatch); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onConnect(); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|