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 {
|
return {
|
||||||
showIntroduction,
|
showIntroduction,
|
||||||
me,
|
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,
|
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 () {
|
render () {
|
||||||
const { me } = this.props;
|
const { me, streamingUrl } = this.props;
|
||||||
if (me == null) return null;
|
if (me == null || !streamingUrl) return null;
|
||||||
|
|
||||||
// Disabling introduction for launch
|
// Disabling introduction for launch
|
||||||
// const { showIntroduction } = this.props;
|
// const { showIntroduction } = this.props;
|
||||||
//
|
//
|
||||||
|
@ -77,17 +100,6 @@ export default class GabSocial extends React.PureComponent {
|
||||||
locale: PropTypes.string.isRequired,
|
locale: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this.disconnect = store.dispatch(connectUserStream());
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount () {
|
|
||||||
if (this.disconnect) {
|
|
||||||
this.disconnect();
|
|
||||||
this.disconnect = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { locale } = this.props;
|
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() {} })) {
|
export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onConnect() {}, onDisconnect() {}, onReceive() {} })) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const streamingAPIBaseURL = getState().getIn(['meta', 'streaming_api_base_url']);
|
const streamingAPIBaseURL = getState().getIn(['instance', 'urls', 'streaming_api']);
|
||||||
const accessToken = getState().getIn(['meta', 'access_token']);
|
// const accessToken: state.getIn(['auth', 'user', 'access_token']);
|
||||||
|
const accessToken = JSON.parse(localStorage.getItem('user')).access_token;
|
||||||
const { onConnect, onDisconnect, onReceive } = callbacks(dispatch, getState);
|
const { onConnect, onDisconnect, onReceive } = callbacks(dispatch, getState);
|
||||||
|
|
||||||
let polling = null;
|
let polling = null;
|
||||||
|
|
Loading…
Reference in a new issue