diff options
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/Server.ts | 11 | ||||
| -rw-r--r-- | src/client/SocketStub.ts | 30 |
2 files changed, 19 insertions, 22 deletions
diff --git a/src/client/Server.ts b/src/client/Server.ts index 66ba92497..db6bf992c 100644 --- a/src/client/Server.ts +++ b/src/client/Server.ts @@ -9,7 +9,7 @@ import { MessageStore } from "./../server/Message"; export class Server { private static ClientFieldsCached: ObservableMap<FIELD_ID, Field | FIELD_WAITING> = new ObservableMap(); - static Socket: SocketIOClient.Socket = OpenSocket("http://localhost:8080") + static Socket: SocketIOClient.Socket = OpenSocket("http://localhost:1234") static GUID: string = Utils.GenerateGuid() // Retrieves the cached value of the field and sends a request to the server for the real value (if it's not cached). @@ -20,8 +20,7 @@ export class Server { this.ClientFieldsCached.set(fieldid, FieldWaiting); //simulating a server call with a registered callback action SocketStub.SEND_FIELD_REQUEST(fieldid, - action((field: Field) => callback(Server.cacheField(field))), - hackTimeout); + action((field: Field) => callback(Server.cacheField(field)))); } else if (this.ClientFieldsCached.get(fieldid) != FieldWaiting) { callback(this.ClientFieldsCached.get(fieldid) as Field); } @@ -53,6 +52,10 @@ export class Server { SocketStub.SEND_SET_FIELD(field, value); } + static connected(message: string) { + Server.Socket.emit(MessageStore.Bar.Message, Server.GUID); + } + @action private static cacheField(clientField: Field) { var cached = this.ClientFieldsCached.get(clientField.Id); @@ -64,3 +67,5 @@ export class Server { return this.ClientFieldsCached.get(clientField.Id) as Field; } } + +Server.Socket.on(MessageStore.Foo.Message, Server.connected);
\ No newline at end of file diff --git a/src/client/SocketStub.ts b/src/client/SocketStub.ts index 58dedbf82..3b1401632 100644 --- a/src/client/SocketStub.ts +++ b/src/client/SocketStub.ts @@ -2,6 +2,9 @@ import { Field, FIELD_ID } from "../fields/Field" import { Key, KeyStore } from "../fields/Key" import { ObservableMap, action } from "mobx"; import { Document } from "../fields/Document" +import { MessageStore, SetFieldArgs, GetFieldArgs } from "../server/Message"; +import { Utils } from "../Utils"; +import { Server } from "./Server"; export class SocketStub { @@ -17,25 +20,14 @@ export class SocketStub { // server stores stripped down document (w/ only field id proxies) in the field store this.FieldStore.set(document.Id, new Document(document.Id)); document.fields.forEach((f, key) => (this.FieldStore.get(document.Id) as Document)._proxies.set(key, (f as Field).Id)); - } - - public static SEND_FIELD_REQUEST(fieldid: FIELD_ID, callback: (field: Field) => void, timeout: number) { - - if (timeout < 0)// this is a hack to make things easier to setup until we have a server... won't be neededa fter that. - callback(this.FieldStore.get(fieldid) as Field); - else { // actual logic here... - - // Send a request for fieldid to the server - // ...SOCKET(RETRIEVE_FIELD, fieldid) - - // server responds (simulated with a timeout) and the callback is invoked - setTimeout(() => - - // when the field data comes back, call the callback() function - callback(this.FieldStore.get(fieldid) as Field), + // Server.Socket.emit(MessageStore.AddDocument.Message, document) + } - timeout); + public static SEND_FIELD_REQUEST(fieldid: FIELD_ID, callback: (field: Field) => void) { + if (fieldid) { + let args: GetFieldArgs = new GetFieldArgs(fieldid) + Utils.EmitCallback(Server.Socket, MessageStore.GetField, args, (field: Field) => callback(field)) } } @@ -72,7 +64,7 @@ export class SocketStub { // ...SOCKET(SET_FIELD, field id, serialized field value) // Server updates the value of the field in its fieldstore - if (this.FieldStore.get(field.Id)) - this.FieldStore.get(field.Id)!.TrySetValue(value); + let msg: SetFieldArgs = new SetFieldArgs(field.Id as string, value) + Utils.Emit(Server.Socket, MessageStore.SetField, msg) } } |
