update structure
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user