diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Server.tsx | 14 | ||||
-rw-r--r-- | src/server/Client.ts | 15 | ||||
-rw-r--r-- | src/server/Message.ts | 27 | ||||
-rw-r--r-- | src/server/server.ts | 31 |
4 files changed, 87 insertions, 0 deletions
diff --git a/src/Server.tsx b/src/Server.tsx index 04473424a..729dfa873 100644 --- a/src/Server.tsx +++ b/src/Server.tsx @@ -2,10 +2,16 @@ import { Field, FieldWaiting, FIELD_ID, DOC_ID, FIELD_WAITING } from "./fields/F import { Key, KeyStore } from "./fields/Key" import { ObservableMap, computed, action, observable } from "mobx"; import { Document } from "./fields/Document" +import * as OpenSocket from 'socket.io-client'; +import { Utils } from "./Utils"; +import { MessageStore } from "./server/Message"; export class Server { static FieldStore: ObservableMap<FIELD_ID, Field> = new ObservableMap(); static DocumentStore: ObservableMap<DOC_ID, ObservableMap<Key, FIELD_ID>> = new ObservableMap(); + static Socket: SocketIOClient.Socket = OpenSocket("http://localhost:8080") + static GUID: string = Utils.GenerateGuid() + public static ClientFieldsCached: ObservableMap<DOC_ID, Field | FIELD_WAITING> = new ObservableMap(); // 'hack' is here temoporarily for simplicity when debugging things. @@ -87,6 +93,12 @@ export class Server { } @action + static connected(message: string) { + console.log(message) + Server.Socket.emit("id", Server.GUID) + } + + @action static receivedDocument(docid: DOC_ID, fieldlist: ObservableMap<Key, FIELD_ID>) { var cachedDoc = this.cacheField(new Document(docid)); fieldlist!.forEach((field: FIELD_ID, key: Key) => (cachedDoc as Document)._proxies.set(key, field)); @@ -104,3 +116,5 @@ export class Server { doc.fields.set(key, cachedField); } } + +Server.Socket.on(MessageStore.Handshake.Message, Server.connected);
\ No newline at end of file diff --git a/src/server/Client.ts b/src/server/Client.ts new file mode 100644 index 000000000..6b8841658 --- /dev/null +++ b/src/server/Client.ts @@ -0,0 +1,15 @@ +import { computed } from "mobx"; + +export class Client { + constructor(guid: string) { + this.guid = guid + } + + private guid: string; + + @computed + public get GUID(): string { + return this.guid + } + +}
\ No newline at end of file diff --git a/src/server/Message.ts b/src/server/Message.ts new file mode 100644 index 000000000..d5b9b4612 --- /dev/null +++ b/src/server/Message.ts @@ -0,0 +1,27 @@ +import { Utils } from "../Utils"; + +export class Message { + private name: string; + private guid: string; + + get Name(): string { + return this.name; + } + + get Message(): string { + return this.guid + } + + constructor(name: string) { + this.name = name; + this.guid = Utils.GenerateDeterministicGuid(name) + } + + GetValue() { + return this.Name; + } +} + +export namespace MessageStore { + export const Handshake = new Message("Handshake"); +}
\ No newline at end of file diff --git a/src/server/server.ts b/src/server/server.ts new file mode 100644 index 000000000..db58ed662 --- /dev/null +++ b/src/server/server.ts @@ -0,0 +1,31 @@ +import { MessageStore } from "./Message"; + +// const express = require("express") +// const path = require("path") + +// const app = express(); +// app.set("port", process.env.PORT || 3000); + +// var http = require('http').Server(app); + +// app.get('/', function (req: any, res: any) { +// res.sendFile(path.resolve("./deploy/index.html")) +// }) + +// const server = http.listen(3000, function () { +// console.log("Listening on *:3000") +// }) + +const server = require("socket.io")(); +var clients = []; + +server.on("connection", function (socket: any) { + console.log("a user has connected") + + socket.emit(MessageStore.Handshake.Message, "handshake received") + + clients.push(socket) +}) + +server.listen(8080); +console.log("listening on port 8080")
\ No newline at end of file |