diff --git a/app/gabsocial/containers/gabsocial.js b/app/gabsocial/containers/gabsocial.js index 9029f4dd6..34f33c578 100644 --- a/app/gabsocial/containers/gabsocial.js +++ b/app/gabsocial/containers/gabsocial.js @@ -40,6 +40,9 @@ const mapStateToProps = (state) => { return { showIntroduction, me, + // accessToken: state.getIn(['auth', 'user', 'access_token']), + accessToken: JSON.parse(localStorage.getItem('user')).access_token, + streamingUrl: state.getIn(['instance', 'urls', 'streaming_api']), } } @@ -50,9 +53,29 @@ class GabSocialMount extends React.PureComponent { showIntroduction: PropTypes.bool, }; + componentDidMount() { + this.componentDidUpdate(); + } + + componentDidUpdate(prevProps) { + const keys = ['accessToken', 'streamingUrl']; + const credsSet = keys.every(p => this.props[p]); + if (!this.disconnect && credsSet) { + this.disconnect = store.dispatch(connectUserStream()); + } + } + + componentWillUnmount () { + if (this.disconnect) { + this.disconnect(); + this.disconnect = null; + } + } + render () { - const { me } = this.props; - if (me == null) return null; + const { me, streamingUrl } = this.props; + if (me == null || !streamingUrl) return null; + // Disabling introduction for launch // const { showIntroduction } = this.props; // @@ -77,17 +100,6 @@ export default class GabSocial extends React.PureComponent { locale: PropTypes.string.isRequired, }; - componentDidMount() { - this.disconnect = store.dispatch(connectUserStream()); - } - - componentWillUnmount () { - if (this.disconnect) { - this.disconnect(); - this.disconnect = null; - } - } - render () { const { locale } = this.props; diff --git a/app/gabsocial/stream.js b/app/gabsocial/stream.js index 99427f71c..698f4a285 100644 --- a/app/gabsocial/stream.js +++ b/app/gabsocial/stream.js @@ -6,8 +6,9 @@ const randomIntUpTo = max => Math.floor(Math.random() * Math.floor(max)); 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 streamingAPIBaseURL = getState().getIn(['instance', 'urls', 'streaming_api']); + // const accessToken: state.getIn(['auth', 'user', 'access_token']); + const accessToken = JSON.parse(localStorage.getItem('user')).access_token; const { onConnect, onDisconnect, onReceive } = callbacks(dispatch, getState); let polling = null;