update structure
This commit is contained in:
parent
0bde7ec41b
commit
d005ceff58
@ -9,7 +9,6 @@ We recommend the use of typescript.
|
|||||||
|
|
||||||
### Serverside
|
### Serverside
|
||||||
```typescript
|
```typescript
|
||||||
|
|
||||||
import * as smartsocket from "smartsocket";
|
import * as smartsocket from "smartsocket";
|
||||||
|
|
||||||
let mySmartsocket = new smartsocket.Smartsocket({
|
let mySmartsocket = new smartsocket.Smartsocket({
|
||||||
|
@ -3,6 +3,9 @@ import * as helpers from "./smartsocket.helpers";
|
|||||||
|
|
||||||
// classes
|
// classes
|
||||||
import { Objectmap } from "lik";
|
import { Objectmap } from "lik";
|
||||||
|
import {SocketRole} from "./smartsocket.classes.socketrole";
|
||||||
|
import {SocketFunction} from "./smartsocket.classes.socketfunction";
|
||||||
|
|
||||||
|
|
||||||
export interface ISocketObject {
|
export interface ISocketObject {
|
||||||
group?:string,
|
group?:string,
|
||||||
@ -13,11 +16,12 @@ export interface ISocketObject {
|
|||||||
export interface ISmartsocketConstructorOptions {
|
export interface ISmartsocketConstructorOptions {
|
||||||
port: number;
|
port: number;
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
export class Smartsocket {
|
export class Smartsocket {
|
||||||
io: SocketIO.Server;
|
io: SocketIO.Server;
|
||||||
openSockets = new Objectmap();
|
openSockets = new Objectmap();
|
||||||
|
registeredRoles = new Objectmap();
|
||||||
constructor(options: ISmartsocketConstructorOptions) {
|
constructor(options: ISmartsocketConstructorOptions) {
|
||||||
this.io = plugins.socketIo(options.port);
|
this.io = plugins.socketIo(options.port);
|
||||||
this.io.on('connection', this._handleSocket);
|
this.io.on('connection', this._handleSocket);
|
||||||
@ -36,9 +40,11 @@ export class Smartsocket {
|
|||||||
.then();
|
.then();
|
||||||
}
|
}
|
||||||
|
|
||||||
registerGroup(string){
|
registerRole(socketRoleArg:SocketRole){
|
||||||
|
this.registeredRoles.add(socketRoleArg);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
closeServer = () => {
|
closeServer = () => {
|
||||||
this.io.close();
|
this.io.close();
|
||||||
|
23
ts/smartsocket.classes.socketfunction.ts
Normal file
23
ts/smartsocket.classes.socketfunction.ts
Normal file
@ -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;
|
||||||
|
};
|
||||||
|
}
|
@ -1,10 +1,22 @@
|
|||||||
import * as plugins from "./smartsocket.plugins";
|
import * as plugins from "./smartsocket.plugins";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* interface for class SocketRole
|
||||||
|
*/
|
||||||
|
export interface SocketRoleOptions {
|
||||||
|
name:string;
|
||||||
|
passwordHash:string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A socketrole defines access to certain routines.
|
* A socketrole defines access to certain routines.
|
||||||
*/
|
*/
|
||||||
class Role {
|
export class SocketRole {
|
||||||
constructor(){
|
name:string;
|
||||||
|
passwordHash:string;
|
||||||
|
constructor(optionsArg:SocketRoleOptions){
|
||||||
|
this.name = optionsArg.name;
|
||||||
|
this.passwordHash = optionsArg.passwordHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user