Pull streaming URL from /api/v1/instance

stable/1.0.x
Alex Gleason 2020-04-05 16:28:08 -05:00
rodzic da4f5b200c
commit 64cef8a56e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 28 dodań i 15 usunięć

Wyświetl plik

@ -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;

Wyświetl plik

@ -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;