|
|
|
@ -132,27 +132,29 @@ export class WebSocketRpcClient extends s.SprinklersRPC {
@@ -132,27 +132,29 @@ export class WebSocketRpcClient extends s.SprinklersRPC {
|
|
|
|
|
() => |
|
|
|
|
this.connectionState.clientToServer === true && |
|
|
|
|
this.tokenStore.accessToken.isValid, |
|
|
|
|
async () => { |
|
|
|
|
try { |
|
|
|
|
const res = await this.authenticate( |
|
|
|
|
this.tokenStore.accessToken.token! |
|
|
|
|
); |
|
|
|
|
runInAction("authenticateSuccess", () => { |
|
|
|
|
this.authenticated = res.authenticated; |
|
|
|
|
}); |
|
|
|
|
logger.info({ user: res.user }, "authenticated websocket connection"); |
|
|
|
|
this.emit("newUserData", res.user); |
|
|
|
|
} catch (err) { |
|
|
|
|
logger.error({ err }, "error authenticating websocket connection"); |
|
|
|
|
// TODO message?
|
|
|
|
|
runInAction("authenticateError", () => { |
|
|
|
|
this.authenticated = false; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
async () => { this.doAuthenticate() } |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async doAuthenticate() { |
|
|
|
|
try { |
|
|
|
|
const res = await this.authenticate( |
|
|
|
|
this.tokenStore.accessToken.token! |
|
|
|
|
); |
|
|
|
|
runInAction("authenticateSuccess", () => { |
|
|
|
|
this.authenticated = res.authenticated; |
|
|
|
|
}); |
|
|
|
|
logger.info({ user: res.user }, "authenticated websocket connection"); |
|
|
|
|
this.emit("newUserData", res.user); |
|
|
|
|
} catch (err) { |
|
|
|
|
logger.error({ err }, "error authenticating websocket connection"); |
|
|
|
|
// TODO message?
|
|
|
|
|
runInAction("authenticateError", () => { |
|
|
|
|
this.authenticated = false; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// args must all be JSON serializable
|
|
|
|
|
async makeDeviceCall( |
|
|
|
|
deviceId: string, |
|
|
|
|