diff --git a/README.md b/README.md index 74cfc34..4884e6c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ We recommend the use of typescript. ### Serverside ```typescript - import * as smartsocket from "smartsocket"; let mySmartsocket = new smartsocket.Smartsocket({ diff --git a/ts/smartsocket.classes.smartsocket.ts b/ts/smartsocket.classes.smartsocket.ts index 04adf75..a6949a2 100644 --- a/ts/smartsocket.classes.smartsocket.ts +++ b/ts/smartsocket.classes.smartsocket.ts @@ -3,6 +3,9 @@ import * as helpers from "./smartsocket.helpers"; // classes import { Objectmap } from "lik"; +import {SocketRole} from "./smartsocket.classes.socketrole"; +import {SocketFunction} from "./smartsocket.classes.socketfunction"; + export interface ISocketObject { group?:string, @@ -13,11 +16,12 @@ export interface ISocketObject { export interface ISmartsocketConstructorOptions { port: number; -} +}; export class Smartsocket { io: SocketIO.Server; openSockets = new Objectmap(); + registeredRoles = new Objectmap(); constructor(options: ISmartsocketConstructorOptions) { this.io = plugins.socketIo(options.port); this.io.on('connection', this._handleSocket); @@ -36,9 +40,11 @@ export class Smartsocket { .then(); } - registerGroup(string){ - - } + registerRole(socketRoleArg:SocketRole){ + this.registeredRoles.add(socketRoleArg); + }; + + closeServer = () => { this.io.close(); diff --git a/ts/smartsocket.classes.socketfunction.ts b/ts/smartsocket.classes.socketfunction.ts new file mode 100644 index 0000000..0271117 --- /dev/null +++ b/ts/smartsocket.classes.socketfunction.ts @@ -0,0 +1,23 @@ +import * as plugins from "./smartsocket.plugins"; + +// import classes +import { SocketRole } from "./smartsocket.classes.socketrole"; + + + +export interface SocketFunctionOptions { + name: string; + func: any; + roles: SocketRole[]; // all roles that are allowed to execute a SocketFunction +}; + +export class SocketFunction { + name: string; + func: any; + roles: SocketRole[]; + constructor(optionsArg: SocketFunctionOptions) { + this.name = optionsArg.name; + this.func = optionsArg.func; + this.roles = optionsArg.roles; + }; +} \ No newline at end of file diff --git a/ts/smartsocket.classes.socketrole.ts b/ts/smartsocket.classes.socketrole.ts index d52c83a..7ab3bf9 100644 --- a/ts/smartsocket.classes.socketrole.ts +++ b/ts/smartsocket.classes.socketrole.ts @@ -1,10 +1,22 @@ import * as plugins from "./smartsocket.plugins"; +/** + * interface for class SocketRole + */ +export interface SocketRoleOptions { + name:string; + passwordHash:string; +} + + /** * A socketrole defines access to certain routines. */ -class Role { - constructor(){ - +export class SocketRole { + name:string; + passwordHash:string; + constructor(optionsArg:SocketRoleOptions){ + this.name = optionsArg.name; + this.passwordHash = optionsArg.passwordHash; } } \ No newline at end of file