MCPcopy Index your code
hub / github.com/witheve/Eve / MessageHandler

Function MessageHandler

src/runtime/server.ts:233–252  ·  view source on GitHub ↗
(client:SocketRuntimeClient, message)

Source from the content-addressed store, hash-verified

231}
232
233function MessageHandler(client:SocketRuntimeClient, message) {
234 let ws = client.socket;
235 let data = JSON.parse(message);
236 if(data.type === "init") {
237 let {editor, runtimeOwner, controlOwner, path:filepath} = config;
238 // we do nothing here since the server is in charge of handling init.
239 let content = fs.readFileSync(filepath).toString();
240 ws.send(JSON.stringify({type: "initProgram", path: filepath, code: content, config, workspaces: eveSource.workspaces}));
241 if(runtimeOwner === Owner.server) {
242 client.load(content, "user");
243 }
244 } else if(data.type === "event") {
245 client.handleEvent(message);
246 } else if(data.type === "ping") {
247 // we don't need to do anything with pings, they're just to make sure hosts like
248 // Heroku don't shutdown our server.
249 } else {
250 console.error("Invalid message sent: " + message);
251 }
252}
253
254function initWebsocket(wss, withIDE:boolean) {
255 wss.on('connection', function connection(ws) {

Callers

nothing calls this directly

Calls 3

errorMethod · 0.80
sendMethod · 0.65
loadMethod · 0.45

Tested by

no test coverage detected