update structure

This commit is contained in:
2016-08-07 14:58:20 +02:00
parent 8b419711fc
commit 309284ab68
21 changed files with 286 additions and 9 deletions

View File

@ -0,0 +1,4 @@
import * as plugins from "./smartsocket.plugins";
export * from "./smartsocket.classes.smartsocket";
export * from "./smartsocket.classes.smartsocketclient";

View File

@ -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");

View 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();
}
}

View 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(){
}
}

View 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
View 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;
};

View 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");