|
|
|
@ -327,60 +327,73 @@ export class LeftPaneChannelSection extends React.Component<Props, State> {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Make this not hard coded
|
|
|
|
|
const channelId = 1;
|
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
const connectionResult = window.attemptConnection(
|
|
|
|
|
channelUrlPasted,
|
|
|
|
|
channelId
|
|
|
|
|
);
|
|
|
|
|
joinChannelStateManager(this, channelUrlPasted, this.handleToggleOverlay);
|
|
|
|
|
|
|
|
|
|
// Give 5s maximum for promise to revole. Else, throw error.
|
|
|
|
|
const connectionTimeout = setTimeout(() => {
|
|
|
|
|
if (!this.state.connectSuccess) {
|
|
|
|
|
this.setState({ loading: false });
|
|
|
|
|
window.pushToast({
|
|
|
|
|
title: window.i18n('connectToServerFail'),
|
|
|
|
|
type: 'error',
|
|
|
|
|
id: 'connectToServerFail',
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}, window.CONSTANTS.MAX_CONNECTION_DURATION);
|
|
|
|
|
|
|
|
|
|
connectionResult
|
|
|
|
|
.then(() => {
|
|
|
|
|
clearTimeout(connectionTimeout);
|
|
|
|
|
|
|
|
|
|
if (this.state.loading) {
|
|
|
|
|
this.setState({
|
|
|
|
|
connectSuccess: true,
|
|
|
|
|
loading: false,
|
|
|
|
|
});
|
|
|
|
|
window.pushToast({
|
|
|
|
|
title: window.i18n('connectToServerSuccess'),
|
|
|
|
|
id: 'connectToServerSuccess',
|
|
|
|
|
type: 'success',
|
|
|
|
|
});
|
|
|
|
|
this.handleToggleOverlay();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((connectionError: string) => {
|
|
|
|
|
clearTimeout(connectionTimeout);
|
|
|
|
|
this.setState({
|
|
|
|
|
export function joinChannelStateManager(
|
|
|
|
|
thisRef: any,
|
|
|
|
|
serverURL: string,
|
|
|
|
|
onSuccess?: any
|
|
|
|
|
) {
|
|
|
|
|
// Any component that uses this function MUST have the keys [loading, connectSuccess]
|
|
|
|
|
// in their State
|
|
|
|
|
|
|
|
|
|
// TODO: Make this not hard coded
|
|
|
|
|
const channelId = 1;
|
|
|
|
|
thisRef.setState({ loading: true });
|
|
|
|
|
const connectionResult = window.attemptConnection(serverURL, channelId);
|
|
|
|
|
|
|
|
|
|
// Give 5s maximum for promise to revole. Else, throw error.
|
|
|
|
|
const connectionTimeout = setTimeout(() => {
|
|
|
|
|
if (!thisRef.state.connectSuccess) {
|
|
|
|
|
thisRef.setState({ loading: false });
|
|
|
|
|
window.pushToast({
|
|
|
|
|
title: window.i18n('connectToServerFail'),
|
|
|
|
|
type: 'error',
|
|
|
|
|
id: 'connectToServerFail',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}, window.CONSTANTS.MAX_CONNECTION_DURATION);
|
|
|
|
|
|
|
|
|
|
connectionResult
|
|
|
|
|
.then(() => {
|
|
|
|
|
clearTimeout(connectionTimeout);
|
|
|
|
|
|
|
|
|
|
if (thisRef.state.loading) {
|
|
|
|
|
thisRef.setState({
|
|
|
|
|
connectSuccess: true,
|
|
|
|
|
loading: false,
|
|
|
|
|
});
|
|
|
|
|
window.pushToast({
|
|
|
|
|
title: connectionError,
|
|
|
|
|
id: 'connectToServerFail',
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: window.i18n('connectToServerSuccess'),
|
|
|
|
|
id: 'connectToServerSuccess',
|
|
|
|
|
type: 'success',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
if (onSuccess) {
|
|
|
|
|
onSuccess();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((connectionError: string) => {
|
|
|
|
|
clearTimeout(connectionTimeout);
|
|
|
|
|
thisRef.setState({
|
|
|
|
|
connectSuccess: true,
|
|
|
|
|
loading: false,
|
|
|
|
|
});
|
|
|
|
|
window.pushToast({
|
|
|
|
|
title: connectionError,
|
|
|
|
|
id: 'connectToServerFail',
|
|
|
|
|
type: 'error',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|