Skip to content

Commit 296ba94

Browse files
committed
update
1 parent 714eab1 commit 296ba94

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

server/agent-control-service/agent.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
import { EncodingUtils } from "@/shared/encoding";
2-
import WebSocket from "crossws/websocket";
32
import { AgentCMDRegistry } from "./commands/registry";
43
import { AgentCommand } from "./commands/message";
54
import { AgentControlService } from ".";
65

76
export type AgentID = number;
87
export type AgentsDB = Map<AgentID, ControllableAgent>;
98

9+
type Socket = {
10+
websocket: {
11+
readyState?: number | undefined;
12+
}
13+
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
14+
close(): void;
15+
}
16+
1017
type ControllableOnlineAgent = ControllableAgent & {
1118
peerID: string;
12-
socket: WebSocket;
19+
socket: Socket;
1320
}
1421

1522

1623
export class ControllableAgent implements ControllableAgent.IConfig {
1724

1825
public peerID: string | null = null;
19-
public socket: WebSocket | null = null;
26+
public socket: Socket | null = null;
2027

2128
public onMessage: ((data: string) => void) | null = null;
2229

@@ -33,7 +40,7 @@ export class ControllableAgent implements ControllableAgent.IConfig {
3340
}
3441

3542
public isOnline(): this is ControllableOnlineAgent {
36-
return this.socket !== null && this.peerID !== null && this.socket.readyState === WebSocket.OPEN;
43+
return this.socket !== null && this.peerID !== null && this.socket.websocket.readyState === WebSocket.OPEN;
3744
}
3845

3946
async sendCommand<C extends AgentCMDRegistry.Commands>(command: C, payload: AgentCMDRegistry.Payload<C>, withResponse?: true): Promise<AgentCMDRegistry.Response<C> | null>;

server/agent-control-service/server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ function ControlServiceServerHandlerFactory(clients: Map<string, ControllableAge
5858
}
5959

6060
agent.peerID = peer.id;
61-
agent.socket = peer.websocket as WebSocket;
62-
console.log(peer.send("Welcome Agent"));
61+
agent.socket = peer;
6362
clients.set(peer.id, agent);
6463
Logger.log(`Agent '${agent.id}' connected`);
6564
},

0 commit comments

Comments
 (0)