| 231 | } |
| 232 | |
| 233 | function 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 | |
| 254 | function initWebsocket(wss, withIDE:boolean) { |
| 255 | wss.on('connection', function connection(ws) { |