componentDidMount() {
// Subscribe to jwt changes
if (isBrowser()) {
+ this.websocketEvents();
+
this.searchTextField = createRef();
console.log(`isLoggedIn = ${this.state.isLoggedIn}`);
}
return;
} else if (msg.reconnect) {
+ toast(i18n.t("websocket_reconnected"), "success");
WebSocketService.Instance.send(
wsClient.userJoin({
auth: authField(),
}
get canCreateCommunity(): boolean {
- let adminOnly = this.props.site_res.site_view?.site
- .community_creation_admin_only;
+ let adminOnly =
+ this.props.site_res.site_view?.site.community_creation_admin_only;
return !adminOnly || this.canAdmin;
}
+ /// Listens for some websocket errors
+ websocketEvents() {
+ let msg = i18n.t("websocket_disconnected");
+ WebSocketService.Instance.closeEventListener(() => {
+ toast(msg, "danger");
+ });
+ }
+
requestNotificationPermission() {
if (UserService.Instance.localUserView) {
document.addEventListener("DOMContentLoaded", function () {
this.ws.send(data);
}
+ public closeEventListener(listener: (event: CloseEvent) => void) {
+ this.ws.addEventListener("close", listener);
+ }
+
public static get Instance() {
return this._instance || (this._instance = new this());
}