code-server/packages/server/src/node/server.ts

26 lines
688 B
TypeScript
Raw Normal View History

2019-01-12 02:33:44 +07:00
import { logger, field } from "@coder/logger";
import { ClientMessage } from "../proto";
import { evaluate } from "./evaluate";
import { ReadWriteConnection } from "../common/connection";
export class Server {
public constructor(
private readonly connection: ReadWriteConnection,
) {
connection.onMessage((data) => {
try {
this.handleMessage(ClientMessage.deserializeBinary(data));
} catch (ex) {
logger.error("Failed to handle client message", field("length", data.byteLength), field("exception", ex));
}
});
}
private handleMessage(message: ClientMessage): void {
if (message.hasNewEval()) {
evaluate(this.connection, message.getNewEval()!);
}
}
}