Handle authentication in the same cmds packet.
This commit is contained in:
parent
1d674046d3
commit
5d7ba1f88b
@ -188,6 +188,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements WebSocke
|
||||
sessionRef.setSecurityCtx(securityCtx);
|
||||
pendingSessions.invalidate(sessionMd.session.getId());
|
||||
establishSession(sessionMd.session, sessionRef, sessionMd);
|
||||
webSocketService.handleCommands(sessionRef, cmdsWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,6 @@ import { NgZone } from '@angular/core';
|
||||
import { selectIsAuthenticated } from '@core/auth/auth.selectors';
|
||||
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
|
||||
import {
|
||||
AuthCmd,
|
||||
AuthWsCmd,
|
||||
CmdUpdateMsg,
|
||||
NotificationSubscriber,
|
||||
@ -196,7 +195,7 @@ export abstract class WebsocketService<T extends WsSubscriber> implements WsServ
|
||||
private onOpen(token: string) {
|
||||
this.isOpening = false;
|
||||
this.isOpened = true;
|
||||
this.dataStream.next(this.createdAuthMsg(token));
|
||||
this.cmdWrapper.setAuth(token);
|
||||
if (this.reconnectTimer) {
|
||||
clearTimeout(this.reconnectTimer);
|
||||
this.reconnectTimer = null;
|
||||
@ -266,10 +265,4 @@ export abstract class WebsocketService<T extends WsSubscriber> implements WsServ
|
||||
message, type: 'error'
|
||||
}));
|
||||
}
|
||||
|
||||
private createdAuthMsg(token: string): AuthWsCmd {
|
||||
return {
|
||||
authCmd: new AuthCmd(token)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,6 +348,7 @@ export class TelemetryPluginCmdsWrapper implements CmdWrapper {
|
||||
}
|
||||
|
||||
cmds: Array<WebsocketCmd>;
|
||||
authCmd: AuthCmd;
|
||||
|
||||
private static popCmds<T>(cmds: Array<T>, leftCount: number): Array<T> {
|
||||
const toPublish = Math.min(cmds.length, leftCount);
|
||||
@ -358,6 +359,10 @@ export class TelemetryPluginCmdsWrapper implements CmdWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public setAuth(token: string) {
|
||||
this.authCmd = new AuthCmd(token);
|
||||
}
|
||||
|
||||
public hasCommands(): boolean {
|
||||
return this.cmds.length > 0;
|
||||
}
|
||||
@ -368,6 +373,10 @@ export class TelemetryPluginCmdsWrapper implements CmdWrapper {
|
||||
|
||||
public preparePublishCommands(maxCommands: number): TelemetryPluginCmdsWrapper {
|
||||
const preparedWrapper = new TelemetryPluginCmdsWrapper();
|
||||
if (this.authCmd) {
|
||||
preparedWrapper.authCmd = this.authCmd;
|
||||
this.authCmd = null;
|
||||
}
|
||||
preparedWrapper.cmds = TelemetryPluginCmdsWrapper.popCmds(this.cmds, maxCommands);
|
||||
return preparedWrapper;
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ export interface WsService<T extends WsSubscriber> {
|
||||
}
|
||||
|
||||
export abstract class CmdWrapper {
|
||||
abstract setAuth(token: string);
|
||||
abstract hasCommands(): boolean;
|
||||
abstract clear(): void;
|
||||
abstract preparePublishCommands(maxCommands: number): CmdWrapper;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user