From 351024b6807096d797657aef5f7003cae91d5c53 Mon Sep 17 00:00:00 2001 From: Mathew Henson Date: Fri, 19 Aug 2016 15:49:50 +0100 Subject: [PATCH] Renamed SocketEvents module to SocketTokens --- src/bucket-manager.ts | 6 +++--- src/controllers/bucket-controller.ts | 2 +- src/definitions/custom/definitions.d.ts | 2 +- src/socket-api/client-connection.ts | 2 +- src/socket-api/client-instruction.ts | 2 +- src/socket-api/comms-controller.ts | 6 +++--- src/socket-api/server-instruction.ts | 2 +- src/socket-api/socket-api.ts | 10 +++++----- src/users.ts | 10 +++++----- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/bucket-manager.ts b/src/bucket-manager.ts index cef76f1..206165f 100644 --- a/src/bucket-manager.ts +++ b/src/bucket-manager.ts @@ -271,7 +271,7 @@ export class BucketManager var updateResult = await stats.updateOne({ user: user }, { $inc: { apiCallsUsed: 1 } }); // Send bucket added events to sockets - var token: def.SocketEvents.IBucketToken = { type: ClientInstructionType[ClientInstructionType.BucketUploaded], bucket: bucketEntry, username: user }; + var token: def.SocketTokens.IBucketToken = { type: ClientInstructionType[ClientInstructionType.BucketUploaded], bucket: bucketEntry, username: user }; await CommsController.singleton.processClientInstruction( new ClientInstruction(token, null, user)); return gBucket; } @@ -380,7 +380,7 @@ export class BucketManager var result = await stats.updateOne({ user: bucketEntry.user }, { $inc: { apiCallsUsed : 1 } }); // Send events to sockets - var token: def.SocketEvents.IBucketToken = { type: ClientInstructionType[ClientInstructionType.BucketRemoved], bucket: bucketEntry, username : bucketEntry.user }; + var token: def.SocketTokens.IBucketToken = { type: ClientInstructionType[ClientInstructionType.BucketRemoved], bucket: bucketEntry, username : bucketEntry.user }; await CommsController.singleton.processClientInstruction(new ClientInstruction(token, null, bucketEntry.user )); return bucketEntry; @@ -434,7 +434,7 @@ export class BucketManager await stats.updateOne({ user: bucketEntry.user }, { $inc: { memoryUsed: -fileEntry.size, apiCallsUsed: 1 } }); // Update any listeners on the sockets - var token: def.SocketEvents.IFileToken = { type: ClientInstructionType[ClientInstructionType.FileRemoved], file: fileEntry, username : fileEntry.user }; + var token: def.SocketTokens.IFileToken = { type: ClientInstructionType[ClientInstructionType.FileRemoved], file: fileEntry, username : fileEntry.user }; await CommsController.singleton.processClientInstruction(new ClientInstruction(token, null, fileEntry.user)); return fileEntry; diff --git a/src/controllers/bucket-controller.ts b/src/controllers/bucket-controller.ts index a0cabe3..e66f773 100644 --- a/src/controllers/bucket-controller.ts +++ b/src/controllers/bucket-controller.ts @@ -811,7 +811,7 @@ export class BucketController extends Controller for (var i = 0, l = files.length; i < l; i++) { // Send file added events to sockets - var token: def.SocketEvents.IFileToken = { username: user, type: ClientInstructionType[ClientInstructionType.FileUploaded], file: files[i] }; + var token: def.SocketTokens.IFileToken = { username: user, type: ClientInstructionType[ClientInstructionType.FileUploaded], file: files[i] }; await CommsController.singleton.processClientInstruction(new ClientInstruction(token, null, user)) } diff --git a/src/definitions/custom/definitions.d.ts b/src/definitions/custom/definitions.d.ts index c57e546..f76bb85 100644 --- a/src/definitions/custom/definitions.d.ts +++ b/src/definitions/custom/definitions.d.ts @@ -8,7 +8,7 @@ /* * Describes the different types of event interfaces we can use to interact with the system via web sockets */ - export module SocketEvents + export module SocketTokens { export type ClientInstructionType = ( 'Login' | diff --git a/src/socket-api/client-connection.ts b/src/socket-api/client-connection.ts index e0247fc..e7bad11 100644 --- a/src/socket-api/client-connection.ts +++ b/src/socket-api/client-connection.ts @@ -51,7 +51,7 @@ export class ClientConnection { winston.info(`Received message from client: '${message}'`, { process: process.pid } ); try { - var token : def.SocketEvents.IToken = JSON.parse(message); + var token : def.SocketTokens.IToken = JSON.parse(message); this._controller.processServerInstruction(new ServerInstruction(token, this)); } catch(err) { diff --git a/src/socket-api/client-instruction.ts b/src/socket-api/client-instruction.ts index b4d4a4a..0730e7a 100644 --- a/src/socket-api/client-instruction.ts +++ b/src/socket-api/client-instruction.ts @@ -6,7 +6,7 @@ import {ClientConnection} from "./client-connection"; /** * An instruction that is generated by the server and sent to relevant clients. */ -export class ClientInstruction +export class ClientInstruction { /** * Specify a username that if set, will only send this instruction to authorized clients diff --git a/src/socket-api/comms-controller.ts b/src/socket-api/comms-controller.ts index 7c1aa08..b0494f8 100644 --- a/src/socket-api/comms-controller.ts +++ b/src/socket-api/comms-controller.ts @@ -62,7 +62,7 @@ export class CommsController extends events.EventEmitter * Sends an instruction to the relevant client connections * @param {ClientInstruction} instruction The instruction from the server */ - processClientInstruction( instruction: ClientInstruction ) + processClientInstruction( instruction: ClientInstruction ) { let recipients: ClientConnection[]; @@ -89,7 +89,7 @@ export class CommsController extends events.EventEmitter * instruction - and in some cases might resond to the client with a ClientInstruction. * @param {ServerInstruction} instruction The instruction from the client */ - processServerInstruction( instruction: ServerInstruction ) + processServerInstruction( instruction: ServerInstruction ) { if (!instruction.token) return winston.error(`Websocket error: An instruction was sent from '${instruction.from.domain}' without a token`, { process: process.pid } ); @@ -104,7 +104,7 @@ export class CommsController extends events.EventEmitter /** * Attempts to send a token to a specific client */ - private sendToken(connection : ClientConnection, token : def.SocketEvents.IToken) : Promise + private sendToken(connection : ClientConnection, token : def.SocketTokens.IToken) : Promise { return new Promise(function(resolve, reject) { let serializedData: string; diff --git a/src/socket-api/server-instruction.ts b/src/socket-api/server-instruction.ts index 3545f70..ba5c6c7 100644 --- a/src/socket-api/server-instruction.ts +++ b/src/socket-api/server-instruction.ts @@ -6,7 +6,7 @@ import {ClientConnection} from "./client-connection"; /** * An instruction that is generated by clients and sent to the server to react to */ -export class ServerInstruction +export class ServerInstruction { /** * The client connection who initiated the request diff --git a/src/socket-api/socket-api.ts b/src/socket-api/socket-api.ts index 700371a..fb1e774 100644 --- a/src/socket-api/socket-api.ts +++ b/src/socket-api/socket-api.ts @@ -27,7 +27,7 @@ export class SocketAPI * Responds to a meta request from a client * @param {SocketEvents.IMetaEvent} e */ - private onMeta( e: ServerInstruction ) + private onMeta( e: ServerInstruction ) { var comms = this._comms; @@ -54,23 +54,23 @@ export class SocketAPI }).then(function( metaVal ) { - let responseToken : def.SocketEvents.IMetaToken = { + let responseToken : def.SocketTokens.IMetaToken = { type : ClientInstructionType[ClientInstructionType.MetaRequest], val: metaVal, property: e.token.property, username: e.token.username }; - comms.processClientInstruction(new ClientInstruction( responseToken, [e.from] )); + comms.processClientInstruction(new ClientInstruction( responseToken, [e.from] )); }).catch(function( err: Error ) { - let responseToken : def.SocketEvents.IMetaToken = { + let responseToken : def.SocketTokens.IMetaToken = { type : ClientInstructionType[ClientInstructionType.MetaRequest], error: err.message }; - comms.processClientInstruction(new ClientInstruction( responseToken, [e.from] )); + comms.processClientInstruction(new ClientInstruction( responseToken, [e.from] )); }); } } \ No newline at end of file diff --git a/src/users.ts b/src/users.ts index 5a32d3a..3a0c44f 100644 --- a/src/users.ts +++ b/src/users.ts @@ -167,7 +167,7 @@ export class UserManager if (useEntry) { // Send logged out event to socket - var token: def.SocketEvents.IUserToken = { username: useEntry.username, type: ClientInstructionType[ClientInstructionType.Logout] }; + var token: def.SocketTokens.IUserToken = { username: useEntry.username, type: ClientInstructionType[ClientInstructionType.Logout] }; await CommsController.singleton.processClientInstruction( new ClientInstruction(token, null, useEntry.username)); winston.info(`User '${useEntry.username}' has logged out`, { process: process.pid }); } @@ -326,7 +326,7 @@ export class UserManager var result = await this._userCollection.updateOne({ _id: user.dbEntry._id }, { $set: { registerKey: "" } }); // Send activated event - var token: def.SocketEvents.IUserToken = { username: username, type: ClientInstructionType[ClientInstructionType.Activated] }; + var token: def.SocketTokens.IUserToken = { username: username, type: ClientInstructionType[ClientInstructionType.Activated] }; await CommsController.singleton.processClientInstruction(new ClientInstruction(token, null, username)); winston.info(`User '${username}' has been activated`, { process: process.pid }); @@ -539,7 +539,7 @@ export class UserManager await this._userCollection.updateOne({ _id: user.dbEntry._id }, { $set: { registerKey: "" } }); // Send activated event - var token: def.SocketEvents.IUserToken = { username: username, type: ClientInstructionType[ClientInstructionType.Activated] }; + var token: def.SocketTokens.IUserToken = { username: username, type: ClientInstructionType[ClientInstructionType.Activated] }; await CommsController.singleton.processClientInstruction(new ClientInstruction(token, null, username)); winston.info(`User '${username}' has been activated`, { process: process.pid }); @@ -682,7 +682,7 @@ export class UserManager throw new Error("Could not remove the user from the database"); // Send event to sockets - var token: def.SocketEvents.IUserToken = { username: username, type: ClientInstructionType[ClientInstructionType.Removed] }; + var token: def.SocketTokens.IUserToken = { username: username, type: ClientInstructionType[ClientInstructionType.Removed] }; CommsController.singleton.processClientInstruction(new ClientInstruction(token, null, username)); winston.info(`User '${username}' has been removed`, { process: process.pid }); @@ -766,7 +766,7 @@ export class UserManager throw new Error("Could not find the user in the database, please make sure its setup correctly"); // Send logged in event to socket - var token: def.SocketEvents.IUserToken = { username: username, type: ClientInstructionType[ClientInstructionType.Login] }; + var token: def.SocketTokens.IUserToken = { username: username, type: ClientInstructionType[ClientInstructionType.Login] }; await CommsController.singleton.processClientInstruction(new ClientInstruction(token, null, username)); return user; }