Skip to content

Commit

Permalink
Renamed SocketEvents module to SocketTokens
Browse files Browse the repository at this point in the history
  • Loading branch information
MKHenson committed Aug 19, 2016
1 parent 508cc8e commit 351024b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/bucket-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export class BucketManager
var updateResult = await stats.updateOne(<users.IStorageStats>{ user: user }, { $inc: <users.IStorageStats>{ 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;
}
Expand Down Expand Up @@ -380,7 +380,7 @@ export class BucketManager
var result = await stats.updateOne(<users.IStorageStats>{ user: bucketEntry.user }, { $inc: <users.IStorageStats>{ 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;
Expand Down Expand Up @@ -434,7 +434,7 @@ export class BucketManager
await stats.updateOne(<users.IStorageStats>{ user: bucketEntry.user }, { $inc: <users.IStorageStats>{ 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;
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/bucket-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion src/definitions/custom/definitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' |
Expand Down
2 changes: 1 addition & 1 deletion src/socket-api/client-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/socket-api/client-instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends def.SocketEvents.IToken>
export class ClientInstruction<T extends def.SocketTokens.IToken>
{
/**
* Specify a username that if set, will only send this instruction to authorized clients
Expand Down
6 changes: 3 additions & 3 deletions src/socket-api/comms-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class CommsController extends events.EventEmitter
* Sends an instruction to the relevant client connections
* @param {ClientInstruction<def.SocketEvents.IToken>} instruction The instruction from the server
*/
processClientInstruction( instruction: ClientInstruction<def.SocketEvents.IToken> )
processClientInstruction( instruction: ClientInstruction<def.SocketTokens.IToken> )
{
let recipients: ClientConnection[];

Expand All @@ -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<def.SocketEvents.IToken>} instruction The instruction from the client
*/
processServerInstruction( instruction: ServerInstruction<def.SocketEvents.IToken> )
processServerInstruction( instruction: ServerInstruction<def.SocketTokens.IToken> )
{
if (!instruction.token)
return winston.error(`Websocket error: An instruction was sent from '${instruction.from.domain}' without a token`, { process: process.pid } );
Expand All @@ -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<void>
private sendToken(connection : ClientConnection, token : def.SocketTokens.IToken) : Promise<void>
{
return new Promise<void>(function(resolve, reject) {
let serializedData: string;
Expand Down
2 changes: 1 addition & 1 deletion src/socket-api/server-instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends def.SocketEvents.IToken>
export class ServerInstruction<T extends def.SocketTokens.IToken>
{
/**
* The client connection who initiated the request
Expand Down
10 changes: 5 additions & 5 deletions src/socket-api/socket-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class SocketAPI
* Responds to a meta request from a client
* @param {SocketEvents.IMetaEvent} e
*/
private onMeta( e: ServerInstruction<def.SocketEvents.IMetaToken> )
private onMeta( e: ServerInstruction<def.SocketTokens.IMetaToken> )
{
var comms = this._comms;

Expand All @@ -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<def.SocketEvents.IMetaToken>( responseToken, [e.from] ));
comms.processClientInstruction(new ClientInstruction<def.SocketTokens.IMetaToken>( 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<def.SocketEvents.IMetaToken>( responseToken, [e.from] ));
comms.processClientInstruction(new ClientInstruction<def.SocketTokens.IMetaToken>( responseToken, [e.from] ));
});
}
}
10 changes: 5 additions & 5 deletions src/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down Expand Up @@ -326,7 +326,7 @@ export class UserManager
var result = await this._userCollection.updateOne({ _id: user.dbEntry._id }, { $set: <def.IUserEntry>{ 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 });
Expand Down Expand Up @@ -539,7 +539,7 @@ export class UserManager
await this._userCollection.updateOne(<def.IUserEntry>{ _id: user.dbEntry._id }, { $set: <def.IUserEntry>{ 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 });
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 351024b

Please sign in to comment.