update structure
This commit is contained in:
@ -0,0 +1,4 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
|
||||
export * from "./smartsocket.classes.smartsocket";
|
||||
export * from "./smartsocket.classes.smartsocketclient";
|
||||
|
@ -1,6 +0,0 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import lik = require("lik");
|
||||
export import q = require("q");
|
||||
export import socketIo = require("socket.io");
|
||||
export import taskbuffer = require("taskbuffer");
|
50
ts/smartsocket.classes.smartsocket.ts
Normal file
50
ts/smartsocket.classes.smartsocket.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
import * as helpers from "./smartsocket.helpers";
|
||||
|
||||
// classes
|
||||
import { Objectmap } from "lik";
|
||||
|
||||
export interface ISocketObject {
|
||||
group?:string,
|
||||
socket: SocketIO.Socket,
|
||||
authenticated: boolean
|
||||
};
|
||||
|
||||
export interface ISmartsocketConstructorOptions {
|
||||
port: number;
|
||||
|
||||
}
|
||||
|
||||
export class Smartsocket {
|
||||
io: SocketIO.Server;
|
||||
openSockets = new Objectmap();
|
||||
constructor(options: ISmartsocketConstructorOptions) {
|
||||
this.io = plugins.socketIo(options.port);
|
||||
this.io.on('connection', this._handleSocket);
|
||||
};
|
||||
|
||||
/**
|
||||
* the standard handler for new socket connections
|
||||
*/
|
||||
private _handleSocket(socket) {
|
||||
let socketObject: ISocketObject = {
|
||||
socket: socket,
|
||||
authenticated: false
|
||||
};
|
||||
this.openSockets.add(socketObject);
|
||||
helpers.authenticateSocket(socketObject)
|
||||
.then();
|
||||
}
|
||||
|
||||
registerGroup(string){
|
||||
|
||||
}
|
||||
|
||||
closeServer = () => {
|
||||
this.io.close();
|
||||
this.openSockets.forEach((socketObjectArg: ISocketObject) => {
|
||||
socketObjectArg.socket.disconnect();
|
||||
});
|
||||
this.openSockets.wipe();
|
||||
}
|
||||
}
|
15
ts/smartsocket.classes.smartsocketclient.ts
Normal file
15
ts/smartsocket.classes.smartsocketclient.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import * as plugins from "./smartsocket.plugins"
|
||||
|
||||
/**
|
||||
* interface for class SmartsocketClient
|
||||
*/
|
||||
export interface ISmartsocketClientOptions {
|
||||
port:number;
|
||||
url:string;
|
||||
}
|
||||
|
||||
export class SmartsocketClient {
|
||||
constructor(){
|
||||
|
||||
}
|
||||
}
|
10
ts/smartsocket.classes.socketrole.ts
Normal file
10
ts/smartsocket.classes.socketrole.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
|
||||
/**
|
||||
* A socketrole defines access to certain routines.
|
||||
*/
|
||||
class Role {
|
||||
constructor(){
|
||||
|
||||
}
|
||||
}
|
20
ts/smartsocket.helpers.ts
Normal file
20
ts/smartsocket.helpers.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import * as plugins from "./smartsocket.plugins";
|
||||
|
||||
// interfaces
|
||||
import {ISocketObject} from "./smartsocket.classes.smartsocket";
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* authenticate a socket
|
||||
*/
|
||||
export let authenticateSocket = (socketObjectArg: ISocketObject) => {
|
||||
let done = plugins.q.defer();
|
||||
socketObjectArg.socket.on("dataAuth", data => {
|
||||
socketObjectArg.socket.removeListener("dataAuth", () => { });
|
||||
done.resolve();
|
||||
});
|
||||
socketObjectArg.socket.emit("requestAuth");
|
||||
return done.promise;
|
||||
};
|
7
ts/smartsocket.plugins.ts
Normal file
7
ts/smartsocket.plugins.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import lik = require("lik");
|
||||
export import q = require("q");
|
||||
export import socketIo = require("socket.io");
|
||||
export import socketIoClient = require("socket.io-client");
|
||||
export import taskbuffer = require("taskbuffer");
|
Reference in New Issue
Block a user