aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Client.ts15
-rw-r--r--src/server/Message.ts56
-rw-r--r--src/server/index.js13
-rw-r--r--src/server/index.ts76
4 files changed, 160 insertions, 0 deletions
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..15329249d
--- /dev/null
+++ b/src/server/Message.ts
@@ -0,0 +1,56 @@
+import { Utils } from "../Utils";
+import { FIELD_ID, Field } from "../fields/Field";
+
+export class Message<T> {
+ private name: string;
+ private guid: string;
+ readonly ArgsCtor: new (...args: any) => T;
+
+ get Name(): string {
+ return this.name;
+ }
+
+ get Message(): string {
+ return this.guid
+ }
+
+ constructor(name: string, ctor: new (...args: any) => T) {
+ this.name = name;
+ this.guid = Utils.GenerateDeterministicGuid(name)
+ this.ArgsCtor = ctor;
+ }
+
+ GetValue() {
+ return this.Name;
+ }
+}
+
+class TestMessageArgs {
+ hello: string = "";
+}
+
+export class SetFieldArgs {
+ field: string;
+ value: any;
+
+ constructor(f: string, v: any) {
+ this.field = f
+ this.value = v
+ }
+}
+
+export class GetFieldArgs {
+ field: string;
+
+ constructor(f: string) {
+ this.field = f
+ }
+}
+
+export namespace MessageStore {
+ export const Foo = new Message("Foo", String);
+ export const Bar = new Message("Bar", String);
+ export const AddDocument = new Message("Add Document", TestMessageArgs);
+ export const SetField = new Message("Set Field", SetFieldArgs)
+ export const GetField = new Message("Get Field", GetFieldArgs)
+} \ No newline at end of file
diff --git a/src/server/index.js b/src/server/index.js
new file mode 100644
index 000000000..15e763f9d
--- /dev/null
+++ b/src/server/index.js
@@ -0,0 +1,13 @@
+"use strict";
+exports.__esModule = true;
+var express = require("express");
+var app = express();
+var port = 8080; // default port to listen
+// define a route handler for the default home page
+app.get("/", function (req, res) {
+ res.send("Hello world!");
+});
+// start the Express server
+app.listen(port, function () {
+ console.log("server started at http://localhost:" + port);
+});
diff --git a/src/server/index.ts b/src/server/index.ts
new file mode 100644
index 000000000..0f2409fbb
--- /dev/null
+++ b/src/server/index.ts
@@ -0,0 +1,76 @@
+import * as express from 'express'
+const app = express()
+import * as webpack from 'webpack'
+import * as wdm from 'webpack-dev-middleware';
+import * as whm from 'webpack-hot-middleware';
+import * as path from 'path'
+import { MessageStore, Message, SetFieldArgs, GetFieldArgs } from "./Message";
+import { Client } from './Client';
+import { Socket } from 'socket.io';
+import { Utils } from '../Utils';
+import { ObservableMap } from 'mobx';
+import { FIELD_ID, Field } from '../fields/Field';
+const config = require('../../webpack.config')
+const compiler = webpack(config)
+const port = 1050; // default port to listen
+const serverPort = 1234;
+
+let FieldStore: ObservableMap<FIELD_ID, Field> = new ObservableMap();
+
+// define a route handler for the default home page
+app.get("/", (req, res) => {
+ res.sendFile(path.join(__dirname, '../../deploy/index.html'));
+});
+
+app.get("/hello", (req, res) => {
+ res.send("<p>Hello</p>");
+})
+
+app.use(wdm(compiler, {
+ publicPath: config.output.publicPath
+}))
+
+app.use(whm(compiler))
+
+// start the Express server
+app.listen(port, () => {
+ console.log(`server started at http://localhost:${port}`);
+})
+
+const server = require("socket.io")();
+interface Map {
+ [key: string]: Client;
+}
+let clients: Map = {}
+
+server.on("connection", function (socket: Socket) {
+ console.log("a user has connected")
+
+ Utils.Emit(socket, MessageStore.Foo, "handshooken")
+
+ Utils.AddServerHandler(socket, MessageStore.Bar, barReceived)
+ Utils.AddServerHandler(socket, MessageStore.SetField, setField)
+ Utils.AddServerHandlerCallback(socket, MessageStore.GetField, getField)
+})
+
+function barReceived(guid: String) {
+ clients[guid.toString()] = new Client(guid.toString());
+}
+
+function addDocument(document: Document) {
+
+}
+
+function setField(newValue: SetFieldArgs) {
+ if (FieldStore.get(newValue.field)) {
+ FieldStore.get(newValue.field)!.TrySetValue(newValue.value);
+ }
+}
+
+function getField([fieldRequest, callback]: [GetFieldArgs, (field: Field) => void]) {
+ let fieldid: string = fieldRequest.field
+ callback(FieldStore.get(fieldid) as Field)
+}
+
+server.listen(serverPort);
+console.log(`listening on port ${serverPort}`); \ No newline at end of file