'nativescript-websocket how to create "Advanced Interface" in Angular Nativescript
I'm not able to create the "Advanced Interface" of nativescript-websocket in Angular/Typescript, I need it to use a custom sslFactory to trust all certs.
The problem is that nothing happens and I can't see any error messagge when I'm trying to connect to the server. The server is alive and responsive and I can communicate with it using the "Browser based Interface"
constructor(private zone: NgZone,
private _http: HttpWrapperService) {
var WS = require('nativescript-websockets');
this.mySocket = new WS(AppGlobals.WS_HINT_ADDRESS,{
protocols:[AppGlobals.WS_HINT_PROTOCOL],
timeout: 6000, allowCellular: true,
sslSocketFactory: this._http.sslSocketFactory
});
this.mySocket.on('open', function(socket) {
this.zone.run(() => {
console.log("---------Hey I'm open");
});
});
this.mySocket.on('message', function(socket, message) {
this.zone.run(() => {
console.log("---------Got a message", message);
});
});
this.mySocket.on('close', function(socket, code, reason) {
this.zone.run(() => {
console.log("---------Socket was closed because: ", reason, " code: ", code);
});
});
this.mySocket.on('error', function(socket, error) {
this.zone.run(() => {
console.log("---------Socket had an error", error);
});
});
}
Solution 1:[1]
I faced a similar issue where the OpenSSL server was alive and responsive and even the handshake was completed successfully but the OPEN event would not trigger. Seems like OpenSSL server does not support websocket. Try using a secured server(https) developed using nodejs. It worked for me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Gayatri Kadam |