Pull streaming URL from /api/v1/instance
This commit is contained in:
parent
da4f5b200c
commit
64cef8a56e
2 changed files with 28 additions and 15 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue