Commit 0a8be1c5 authored by 神楽坂玲奈's avatar 神楽坂玲奈

network

parent 58a77ca9
...@@ -526,7 +526,7 @@ export class AppsService { ...@@ -526,7 +526,7 @@ export class AppsService {
maotama; maotama;
network(app: App, server) { network(app: App, server) {
if(!this.maotama){ if (!this.maotama) {
this.maotama = sudo.fork('maotama') this.maotama = sudo.fork('maotama')
} }
...@@ -535,22 +535,23 @@ export class AppsService { ...@@ -535,22 +535,23 @@ export class AppsService {
let connection = new WebSocket(server.url); let connection = new WebSocket(server.url);
let id; let id;
connection.onmessage = (event)=> { connection.onmessage = (event)=> {
let message = <{action: string;arguments: any[]}>JSON.parse(event.data); console.log(event.data);
console.log(message); let [action, args] = event.data.split(' ', 2);
switch (message.action) { let [address, port] = args.split(':');
case 'listen': switch (action) {
this.connections.set(app, `${message.arguments[0]}:${message.arguments[1]}`); case 'LISTEN':
this.connections.set(app, args);
this.ref.tick(); this.ref.tick();
break; break;
case 'connect': case 'CONNECT':
id = setInterval(()=> { id = setInterval(()=> {
child.send({ child.send({
action: 'connect', action: 'connect',
arguments: [app.network.port, message.arguments[1], message.arguments[0]] arguments: [app.network.port, port, address]
}) })
}, 200); }, 200);
break; break;
case 'connected': case 'CONNECTED':
clearInterval(id); clearInterval(id);
break; break;
} }
......
...@@ -1394,7 +1394,7 @@ ...@@ -1394,7 +1394,7 @@
"servers": [ "servers": [
{ {
"id": "tiramisu", "id": "tiramisu",
"url": "wss://tiramisu.mycard.moe:10800" "url": "ws://wudizhanche.mycard.moe:10800/"
} }
] ]
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment