update structure
This commit is contained in:
parent
19a883c641
commit
cb3d7f4d7b
@ -23,7 +23,7 @@ export class Smartsocket {
|
||||
/**
|
||||
* the standard handler for new socket connections
|
||||
*/
|
||||
private _handleSocket(socketArg) {
|
||||
private _handleSocketConnection(socketArg) {
|
||||
let socketConnection: SocketConnection = new SocketConnection({
|
||||
authenticated:false,
|
||||
socket:socketArg
|
||||
@ -41,7 +41,7 @@ export class Smartsocket {
|
||||
startServer = () => {
|
||||
this.io = plugins.socketIo(this.options.port);
|
||||
this.io.on('connection', (socketArg) => {
|
||||
this._handleSocket(socketArg);
|
||||
this._handleSocketConnection(socketArg);
|
||||
});
|
||||
}
|
||||
closeServer = () => {
|
||||
@ -51,5 +51,10 @@ export class Smartsocket {
|
||||
});
|
||||
this.openSockets.wipe();
|
||||
this.io.close();
|
||||
};
|
||||
|
||||
// communication
|
||||
clientCall(){
|
||||
// TODO: target specific client and initiate response
|
||||
}
|
||||
}
|
@ -15,14 +15,45 @@ import { SocketRequest } from "./smartsocket.classes.socketrequest";
|
||||
export interface ISmartsocketClientOptions {
|
||||
port: number;
|
||||
url: string;
|
||||
alias?:string; // an alias makes ir easier to identify this client in a multo client environment
|
||||
password: string; // by setting a password access to functions can be limited
|
||||
}
|
||||
|
||||
export class SmartsocketClient {
|
||||
socketConnection:SocketConnection;
|
||||
serverUrl:string;
|
||||
serverPort:number;
|
||||
serverPassword:string;
|
||||
constructor(optionsArg:ISmartsocketClientOptions){
|
||||
// TODO: implement Socket init
|
||||
this.serverUrl = optionsArg.url
|
||||
this.serverPort = optionsArg.port;
|
||||
this.serverPassword = optionsArg.password
|
||||
};
|
||||
|
||||
// authenticates the socket against the server
|
||||
private _handleSocketConnection() {
|
||||
let done = plugins.q.defer();
|
||||
let socketUrl = `${this.serverUrl}:${this.serverPort}`;
|
||||
this.socketConnection = new SocketConnection({
|
||||
authenticated:false,
|
||||
socket: plugins.socketIoClient(this.serverUrl,{})
|
||||
});
|
||||
this.socketConnection.socket.on("requestAuth", function () {
|
||||
console.log("server requested authentication");
|
||||
this.socketConnection.socket.emit("dataAuth", {
|
||||
role: "coreflowContainer",
|
||||
password: "somePassword",
|
||||
alias: "coreflow1"
|
||||
});
|
||||
this.socketConnection.socket.on("authenticated",() => {
|
||||
console.log("client is authenticated");
|
||||
done.resolve();
|
||||
});
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
serverCall(functionNameArg:string,dataArg:ISocketFunctionCall){
|
||||
let done = plugins.q.defer();
|
||||
let socketRequest = new SocketRequest({
|
||||
side:"requesting",
|
||||
originSocketConnection:this.socketConnection,
|
||||
@ -32,7 +63,11 @@ export class SmartsocketClient {
|
||||
funcDataArg:dataArg
|
||||
}
|
||||
});
|
||||
socketRequest.dispatch();
|
||||
}
|
||||
socketRequest.dispatch()
|
||||
.then(() => {
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
}
|
@ -11,11 +11,11 @@ import { SocketRole } from "./smartsocket.classes.socketrole";
|
||||
/**
|
||||
* interface for constructor of class SocketConnection
|
||||
*/
|
||||
export interface ISocketConnectionOptions {
|
||||
export interface ISocketConnectionConstructorOptions {
|
||||
alias?: string;
|
||||
authenticated: boolean;
|
||||
role?: SocketRole;
|
||||
socket: SocketIO.Socket;
|
||||
socket?: SocketIO.Socket | SocketIOClient.Socket;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -36,8 +36,8 @@ export class SocketConnection {
|
||||
alias?: string;
|
||||
authenticated: boolean;
|
||||
role?: SocketRole;
|
||||
socket: SocketIO.Socket;
|
||||
constructor(optionsArg: ISocketConnectionOptions) {
|
||||
socket: SocketIO.Socket | SocketIOClient.Socket;
|
||||
constructor(optionsArg: ISocketConnectionConstructorOptions) {
|
||||
this.alias = optionsArg.alias;
|
||||
this.authenticated = optionsArg.authenticated;
|
||||
this.role = optionsArg.role;
|
||||
|
@ -57,16 +57,29 @@ export class SocketRequest {
|
||||
shortId:optionsArg.shortId
|
||||
}
|
||||
};
|
||||
|
||||
// requesting --------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* dispatches a socketrequest from the requesting to the receiving side
|
||||
*/
|
||||
dispatch(){
|
||||
this.originSocketConnection.socket.emit("function",this.requestData);
|
||||
return this.done.promise;
|
||||
};
|
||||
handleResponse(responseDataArg:ISocketRequestDataObject){
|
||||
|
||||
/**
|
||||
* handles the response that is received by the requesting side
|
||||
*/
|
||||
private _handleResponse(responseDataArg:ISocketRequestDataObject){
|
||||
this.done.resolve(responseDataArg);
|
||||
}
|
||||
|
||||
// responding --------------------------
|
||||
|
||||
/**
|
||||
* creates the response on the responding side
|
||||
*/
|
||||
createResponse(){
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user