For the reason why this is archived please see: https://fluentreports.com/blog/?p=1434
The documentation for the plugin is located in the src folder.
Websockets for NativeScript
For the reason why this is archived please see: https://fluentreports.com/blog/?p=1434
The documentation for the plugin is located in the src folder.
Hi! we are using version 1.5.0 of this great plugin.
Very occasionally we are getting a org.java_websocket.exceptions.WebsocketNotConnectedException on the android runtime:
This is the full stacktrace:
System.err: com.tns.NativeScriptException:
System.err: Calling js method run failed
System.err:
System.err: Error: org.java_websocket.exceptions.WebsocketNotConnectedException
System.err: org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:608)
System.err: org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:585)
System.err: org.java_websocket.client.WebSocketClient.send(WebSocketClient.java:309)
System.err: com.tns.Runtime.callJSMethodNative(Native Method)
System.err: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
System.err: com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
System.err: com.tns.Runtime.callJSMethod(Runtime.java:970)
System.err: com.tns.Runtime.callJSMethod(Runtime.java:954)
System.err: com.tns.Runtime.callJSMethod(Runtime.java:946)
System.err: com.tns.gen.java.lang.Runnable.run(Runnable.java:15)
System.err: android.os.Handler.handleCallback(Handler.java:751)
System.err: android.os.Handler.dispatchMessage(Handler.java:95)
System.err: android.os.Looper.loop(Looper.java:154)
System.err: android.app.ActivityThread.main(ActivityThread.java:6077)
System.err: java.lang.reflect.Method.invoke(Native Method)
System.err: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
System.err: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
System.err: File: "file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/nativescript-websockets/websockets.js, line: 529, column: 19
System.err:
System.err: StackTrace:
System.err: Frame: function:'NativeWebSockets._send', file:'file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/nativescript-websockets/websockets.js', line: 529, column: 20
System.err: Frame: function:'NativeWebSockets.send', file:'file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/nativescript-websockets/websockets.js', line: 490, column: 10
System.err: Frame: function:'', file:'file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/stanza-io/stanza-io.js', line: 3692, column: 27
System.err: Frame: function:'', file:'file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/stanza-io/stanza-io.js', line: 8061, column: 9
System.err: Frame: function:'process', file:'file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/stanza-io/stanza-io.js', line: 6309, column: 17
System.err: Frame: function:'', file:'file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/stanza-io/stanza-io.js', line: 6217, column: 19
System.err: Frame: function:'', file:'file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/stanza-io/stanza-io.js', line: 4098, column: 16
System.err: Frame: function:'Item.run', file:'file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/stanza-io/stanza-io.js', line: 9881, column: 14
System.err: Frame: function:'drainQueue', file:'file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/stanza-io/stanza-io.js', line: 9851, column: 42
System.err: Frame: function:'invoke', file:'file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/tns-core-modules/timer/timer.js', line: 19, column: 48
System.err: Frame: function:'run', file:'file:///data/data/com.nospoonlab.neodev/files/app/tns_modules/tns-core-modules/timer/timer.js', line: 23, column: 13
System.err:
System.err: at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:970)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:954)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:946)
System.err: at com.tns.gen.java.lang.Runnable.run(Runnable.java:15)
System.err: at android.os.Handler.handleCallback(Handler.java:751)
System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
System.err: at android.os.Looper.loop(Looper.java:154)
System.err: at android.app.ActivityThread.main(ActivityThread.java:6077)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
System.err: Caused by: org.java_websocket.exceptions.WebsocketNotConnectedException
System.err: at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:608)
System.err: at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:585)
System.err: at org.java_websocket.client.WebSocketClient.send(WebSocketClient.java:309)
System.err: ... 14 more
When I use a wss url, it fails.
It gives me the following error:
JS: Socket had an error javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
JS: Socket was closed because: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. code: -1
Any information on the status of this?
MySocket.on('error', function(socket, error) { console.log("Socket had an error", error);});
to
mySocket.on('error', function(socket, error) { console.log("Socket had an error", error);});
Your ng example: https://www.thepolyglotdeveloper.com/2017/01/communicate-with-websockets-in-a-nativescript-angular-application/
This line is wrong:
require("nativescript-websockets");
Error message:
Module not found: Error: Can't resolve 'nativescript-websockets' in '/myfolder/myfile'
We are using the nativescript-websockets 1.3.3. Everything works perfectly fine if I use the ws protocol. Once I switch to wss protocol (we have valid trusted ssl certificate), it hangs in ios after calling the socket.open. In android both ws and wss works fine.
Anybody else faced this issue on ios?
I see you use very old version of java_websocket.jar and hence this nativescript-websockets lib has some issues
hence this._protocol is just ignored
as a result, my server does not receive the Sec-WebSocket-Protocol header and returns an error
Do you actively still support the nativescript-websockets lib ? Are you able to make this change?
Do you receive PRs from other people?
I'm attempting to connect to a websocket, and the way the particular service works is that they'll issue a 301 redirect to a new URL and then establish the socket connection. This url is different every time (although it does follow a pattern).
Unfortunately this is causing an error to occur, as it appears this behavior isn't currently supported in this project. I also can't seem to find a way to extract the new location from the 'evt' object to attempt a new connection manually.
Any help would be appreciated.
This is not the same as issue #14 - the solution provided on that issue does not resolve this issue. This happens at startup, this code used to work just fine but a recent upgrade of libraries/dependencies has brought this issue up. This isn't a problem on the iOS emulator, only the android device that I've tested.
tns version:
3.4.0
package.json:
"dependencies": {
"@angular/animations": "~5.0.0",
"@angular/common": "~5.0.0",
"@angular/compiler": "~5.0.0",
"@angular/core": "~5.0.0",
"@angular/forms": "~5.0.0",
"@angular/http": "~5.0.0",
"@angular/platform-browser": "~5.0.0",
"@angular/platform-browser-dynamic": "~5.0.0",
"@angular/router": "~5.0.0",
"@suna/quickride-ts-libcore": "^0.210.0",
"allow-publish": "^1.0.4",
"nativescript-angular": "~5.0.0",
"nativescript-appversion": "~1.4.1",
"nativescript-geolocation": "~4.2.2",
"nativescript-google-maps-sdk": "~2.4.3",
"nativescript-insomnia": "~1.2.1",
"nativescript-ios-uuid": "~1.0.0",
"nativescript-phone": "~1.3.1",
"nativescript-plugin-firebase": "^5.0.5",
"nativescript-texttospeech": "~2.0.2",
"nativescript-theme-core": "~1.0.4",
"nativescript-toast": "^1.4.6",
"nativescript-websockets": "^1.3.4",
"reflect-metadata": "~0.1.8",
"rxjs": "~5.5.2",
"tns-core-modules": "~3.4.0",
"zone.js": "~0.8.2"
},
"devDependencies": {
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"lazy": "1.0.11",
"nativescript-dev-typescript": "~0.6.0",
"tns-platform-declarations": "^3.1.0",
"typescript": "~2.4.2"
}
Here's the error output
ActivityManager: Launch timeout has expired, giving up wake lock!
System.err: java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException:
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: Error calling module function
System.err:
System.err: TypeError: Cannot read property 'client' of undefined
System.err: File: "file:///data/data/com.gosuna.quickride.DriverApp/files/app/tns_modules/nativescript-websockets/websockets.js, line: 78, column: 35
System.err:
System.err: StackTrace:
System.err: Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/tns_modules/nativescript-websockets/websockets.js', line: 78, column: 36
System.err: Frame: function:'require', file:'', line: 1, column: 266
System.err: Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/quickride/driver/pages/ride-list/ride.list.page.js', line: 17, column: 10
System.err: Frame: function:'require', file:'', line: 1, column: 266
System.err: Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/quickride/driver/pages/index.js', line: 8, column: 10
System.err: Frame: function:'require', file:'', line: 1, column: 266
System.err: Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/quickride/driver/index.js', line: 6, column: 10
System.err: Frame: function:'require', file:'', line: 1, column: 266
System.err: Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/quickride/index.js', line: 7, column: 10
System.err: Frame: function:'require', file:'', line: 1, column: 266
System.err: Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/app.module.js', line: 8, column: 19
System.err: Frame: function:'require', file:'', line: 1, column: 266
System.err: Frame: function:'', file:'file:///data/data/com.gosuna.quickride.DriverApp/files/app/main.js', line: 8, column: 20
System.err: Frame: function:'require', file:'', line: 1, column: 266
I cannot find the file libSystem.dylib when i try to add it to the Linked Frameworks and Libraries for iOS build. Is there a replacing file for this?
Using iOS 9.2, XCode 7.2.
I have the simple browser based interface code as suggested by your Readme.md, in my app.component.ts file and I get the following error. Can you please help?
TypeError: Cannot read property 'client' of undefined
File ", line 1, column 265
StackTrace:
Frame: function:',file:'/data/.../tns/modules/nativescript-websockets/websockets.js', line: 77, column:36
Frame: function: 'require', file', line:1, column:266
.....
Hi,
When i try to remove a specific callback from an event, eg:
socket.off("message", callback), the callback can not be removed actually.
I did a little investigation to the source code, i guess the issue is caused by a typo in the code.
for (var i=eventCallbacks.length-1;i>=0;i--) {
if (eventCallbacks[i].c === callback) {
eventCallbacks.slice(i, 1);
}
}
I believe the "slice" in the NativeWebSockets.prototype.removeEventListener function should be "splice".
Let me know if i am wrong, thanks!
Hi @NathanaelA,
great work with the library.
I have this issue:
CONSOLE LOG We got a message: "Message.."
CONSOLE LOG The Socket was Closed: 1006
Connecting to "wss://stream.binance.com:9443/ws/!ticker@arr"
just to receive the stream.
Any thoughts on this?
JS: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'client' of undefined
JS: TypeError: Cannot read property 'client' of undefined
JS: at Object. (file:///data/data/org.nativescript.xyz/files/app/tns_modules/nativescript-websockets/websockets.js:78:36)
Hi NathanaelA ! Thanks for implement this module for community.
Is there any way to send parameters on header in the moment of connection?
Hi,
do you plan to add a support for the ping message?
I've done some work on it, however it works only for the iOS part as the Android code seems to lack the proper support for ping.
Please take a look master...PetrPrazak:master and advise.
Thanks.
Hello! when I try to import the module in app.module.ts I get the following error:
java.lang.ClassNotFoundException: technology.master.nativescript.WebSocket
What could it be? Thank you!
PD: I'm using webpack and web code sharing.
Hi, How to reconnect the server after the connection closes itself?
facing this issue with nativescript-websockets where the pingreq times out or I get a socked closed error after 2 minutes of normal working of socket. I made the same project in react-native and it works without any issues. The socket works for a while and I get any data in that time but then stops working without any attempt to reconnect. I am using nativescript-websockets with aws appsync.
I'm using an Actioncable js file to connect to an Actioncable rails server. This actioncable js file uses this nativescript-websockets plugin.
I have been doing connection testing on Android and it works properly, the connection works properly on the web browser as well but when I run it on iOS I get an error like this:
Socket was closed because: code: 1006
This link explains that the connection gets closed abnormally because some incompatibility between the server and the client. I don't really know can can be the issue.
I did post in Stackoverflow since I thought the issue was happening because of the protocols used (actioncable-v1-json, actioncable-unsupported), but even if I don't provide these protocols on the browser test, the connection still works.
Any ideas on what is causing this issue?
Thanks
Good Day,
Thank you for this module. While this module works perfectly fine in my android code, on IOS I am getting constant disconnections, my web socket traffic is reasonably frequent.
Socket closed. Reconnecting in 6 seconds Failed to inflate bytes code: 1002
As I understand this comes from the pocket socket library and its documented in a related library here martijnwalraven/meteor-ios#67
Any quick fix for getting around this?
Cheers!
Hi There!
I have attempted to install "nativescript-websockets" into my application as per your instructions however since doing that I am no longer able to build my project.
Here is the output when I attempt to build...
=== BUILD TARGET PocketSocket OF PROJECT Pods WITH CONFIGURATION Debug ===
Check dependencies
Write auxiliary files
write-file /Users/ben.paul/Library/Developer/Xcode/DerivedData/jegroupordering-aqqlxkvizbcvkwfnosywwqxrtbby/Build/Intermediates/Pods.build/all-product-headers.yaml
=== BUILD TARGET Pods OF PROJECT Pods WITH CONFIGURATION Debug ===
Check dependencies
=== BUILD TARGET jegroupordering OF PROJECT jegroupordering WITH CONFIGURATION Debug ===
Check dependencies
CodeSign error: entitlements are required for product type 'Application' in SDK 'Simulator - iOS 9.2'. Your Xcode installation may be damaged.
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
Command xcodebuild failed with exit code 65
┌─────────┬────────────────────────────────────────────────────────────────────┐
│ Usage │ Synopsis │
│ General │ $ tns build ios [--for-device] [--release] [--copy-to ] │
└─────────┴────────────────────────────────────────────────────────────────────┘
Builds the project for iOS and produces an APP or IPA that you can manually deploy in the iOS Simulator or on device, respectively.
IMPORTANT: Before building for iOS device, verify that you have configured a valid pair of certificate and provisioning profile on your OS X system.
* --release - If set, produces a release build. Otherwise, produces a debug build.
* --for-device - If set, produces an application package that you can deploy on device. Otherwise, produces a build that you can run only in the native iOS Simulator.
* --copy-to - Specifies the file path where the built .ipa will be copied. If it points to a non-existent directory, it will be created. If the specified value is directory, the original file name will be used.
Any idea what may be causing this?
I'm trying to enable WebSocket client on a NativeScript+Vue project. I got require('nativescript-websockets');
on the main file of the project (main.js) but it doesn't seem to work, i can't get ride of this error:
file:///app/app.js:1:197110: JS ERROR Error: Could not find module 'nativescript-websockets/websockets-common'. Computed path '/Users/fabien/Library/Developer/CoreSimulator/Devices/50013167-A53B-4682-9E95-77A95281E43E/data/Containers/Bundle/Application/D717CE39-6818-4866-A50C-65D27C7F589A/dist.app/app/tns_modules/nativescript-websockets/websockets-common'.
Any idea on how to make nativescript-websockets
working on NativeScript+Vue?
i have tried to use this plugin to connect to a 3rd party websocket service , tried both , the browser based and advanced ones , the browser based one works on Android and iOS platforms , but it truncates received json string on iOS platform(simulator), android (device) seems working fine ; the advanced one does not work at all on both platforms~
in my test,the same code of 'new WebSocket("ws://test.xxxxxx.cc:52184/mqtt", ["mqtt"]);',that can be opened on brower,but failed in "nativescript-websockets";
and code of 'new WebSocket("ws://xxxxxx") is ok
I notice ""The sending of Protocols support is not fully implemented on both platforms. Do not depend on this; it only partially works..""
I want to make sure if ["mqtt"] is suppored,thank you
Please help
Connection is lost when another device client connects to the same broker different topic
error i am getting
"Connection lost: AMQJS0008I Socket closed"
Thanks
I know that the tutorial mentions the problem with UI updates with Angular, but I accidentally skipped this while reading the insane amount of docs required to start a nativescript project.
I think something in bold, red and blinking about the usage of NgZone in the doc file would attract more attention and prevent people to lose so much time with non-working UI updates.
Hi there!
Thanks for this great plugin. I just tested it with your basic example and set up a little echo server with node on my local machine. On iOS it works great, but on Android the connection can't be established because of connection refuse.
JS: The socket had an error java.net.ConnectException: failed to connect to /127.0.0.1 (port 8181) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
JS: The Socket was Closed: -1 failed to connect to /127.0.0.1 (port 8181) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
Do I have to consider some special treatment for the android platform?
error TS2346: Supplied parameters do not match any signature of call target.
See issue: NativeScript/ios-jsc#259 for the reason. This is fixed in v1.2.2 of the iOS runtime (which should be released soooooon....).
To work around this issue;
I made it in my app.module:
if (global.TNS_WEBPACK) {
require("globals");
global.registerModule("nativescript-websockets", () => require("../node_modules/nativescript-websockets/websockets-common"));
}
And in my component:
if (global.TNS_WEBPACK) {
global.loadModule("nativescript-websockets");
} else {
require('nativescript-websockets');
}
And I received this error in runtime:
JS: Uncaught Error: com.tns.NativeScriptException: Failed to find module: "nativescript-websockets", relative to: app/tns_modules/
JS: com.tns.Module.resolvePathHelper(Module.java:146)
JS: com.tns.Module.resolvePath(Module.java:55)
JS: com.tns.Runtime.runWorker(Native Method)
JS: com.tns.Runtime.access$1600(Runtime.java:34)
JS: com.tns.Runtime$WorkerThread$1.run(Runtime.java:330)
JS: android.os.Handler.handleCallback(Handler.java:751)
JS: android.os.Handler.dispatchMessage(Handler.java:95)
JS: android.os.Looper.loop(Looper.java:154)
JS: android.os.HandlerThread.run(HandlerThread.java:61)
There's a console.log call every time the onMessage event is fired.
https://github.com/NathanaelA/nativescript-websockets/blob/master/src/websockets.android.js#L102
When I'm running:
tns prepare ios
I get the following error:
nativescript-websockets has Podfile and you don't have Cocoapods installed or it is not configured correctly. Please verify Cocoapods can work on your machine.
Mac OS Sierra v10.12.5
v1.3.1
v3.0.3
v4.1.0
v8.3
Also I'm using Angular 4 with TypeScript for my NativeScript project. The plugin works fine with the emulator but I can't get it to work for production.
Any suggestions?
I am using plugin version 1.4.0 of nativescript-websockets. Connection establishes fine, but when it comes to "send" method, app does not throw any errors and nothing happens, websocket on server does not receive any messages. "Message" event does not work too. "Close" and "Error" events work fine. I have tried both "ws" and "wss" protocols. In Android everything works perfectly. I have tried both advanced and browser based interface.
Can you give me any insight how to solve this issue?
Details:
Machine: Mac OS High Sierra v10.13.2
Cocoapods: v1.3.1
NativeScript (tns --version): v3.3.0
Angular: v4.4.1
Xcode: v9.2
import { Component, OnInit, OnDestroy, NgZone } from "@angular/core";
require("nativescript-websockets");
@component({
selector: "my-app",
templateUrl: "app.component.html",
})
export class AppComponent implements OnInit, OnDestroy {
private socket: any;
public messages: Array<any>;
public chatBox: string;
public constructor(private zone: NgZone) {
this.socket = new WebSocket("http://192.168.3.41:2018/", []);
this.messages = [];
this.chatBox = "";
}
public ngOnInit() {
this.socket.addEventListener('open', event => {
this.zone.run(() => {
this.messages.push({content: "Welcome to the chat!"});
});
});
this.socket.addEventListener('message', event => {
this.zone.run(() => {
this.messages.push(JSON.parse(event.data));
});
});
this.socket.addEventListener('close', event => {
this.zone.run(() => {
this.messages.push({content: "You have been disconnected"});
});
});
this.socket.addEventListener('error', event => {
console.log("The socket had an error", event.error);
});
}
public ngOnDestroy() {
this.socket.close();
}
public send() {
if(this.chatBox) {
this.socket.send(this.chatBox);
this.chatBox = "";
}
}
}
I am using node.js at server side.
After running i get error->
The socket had an error java.net.ConnectException: Connection refused.
I don't have any idea regarding socket connection. I am trying first time.Any idea why i getting these error?
Thanks.
On old android devices, I get the error below because TLS 1.2 can't be used:
JS: Error: Failed to start the transport 'WebSockets': javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb944f950: Failure in SSL library, usually a protocol error
JS: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x8d985990:0x00000000)
JS: Error: Failed to start the connection: Error: Unable to initialize any of the available transports.
chromium: [ERROR:ssl_client_socket_openssl.cc(197)] OpenSSL SYSCALL error, earliest error code in error queue: 0, errno: 0
chromium: [ERROR:ssl_client_socket_openssl.cc(870)] handshake failed; returned 0, SSL error code 5, net_error -107
This could be done by allowing to set a default SSLSocketFactory, so we can pass the usual factory with no trustmanager, or even with an explicit support, which would avoid people to manage this kind of thing.
The former is probably better because is allows more control, and you have to go through hoops anyway if you want this support for https (not possible with the android client, so you have to use okhttp directly).
My quick hack:
In the constructor:
this._sslSocketFactory = options.sslSocketFactory;
In _reCreate:
if (isWSS) {
var socketFactory;
if (this._sslSocketFactory) {
socketFactory = this._sslSocketFactory;
} else {
//noinspection JSUnresolvedFunction,JSUnresolvedVariable
var sslContext = javax.net.ssl.SSLContext.getInstance( "TLS" );
sslContext.init( null, null, null );
//noinspection JSUnresolvedFunction
socketFactory = sslContext.getSocketFactory();
//noinspection JSUnresolvedFunction
}
this._socket.setSocket( socketFactory.createSocket() );
}
I have a websocket connection from nativescript app to a backend server which sends byte array through the socket, when message is received, the type it shows is java.nio.HeapByteBuffer, how to convert them to corresponding javascript type (ArrayBuffer) ? Thanks.
Hi All,
I am new to websocket. I need to connect to a websocket in an android device via wss://. However, I cannot do so, exception is shown as below:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
I saw that I may need to supply the sslSocketFactory. However, I have no idea how to set the parameter. Is there any genius can help or any other approach can solve my problem? Thank you in advance.
I'm trying to play with the recent version of the plugin (1.3.0) and can not make it work. The connection never establishes. I'm using the example snippet from the github:
var WS = require('nativescript-websockets');
var mySocket = new WS("ws://echo.websocket.org",{protocols: [/* 'chat', 'video' */], timeout: 6000, allowCellular: true, headers: { 'Authorization': 'Basic ...' }});
mySocket.on('open', function(socket) { console.log("Hey I'm open"); socket.send("Hello"); });
mySocket.on('message', function(socket, message) { console.log("Got a message", message); });
mySocket.on('close', function(socket, code, reason) { console.log("Socket was closed because: ", reason, " code: ", code); });
mySocket.on('error', function(socket, error) { console.log("Socket had an error", error);});
iOS simulator system log shows this error, I'm not sure whether this causes the issue or not:
websockets[43182]: assertion failed: 15F34 13E230: libxpc.dylib + 57882 [66C28065-C9DB-3C8E-926F-5A40210A6D1B]: 0x7d
It also doesn't work on Android emulator.
My config:
nativescript cli 2.3.0
tns-core-modules 2.3.0
tns-ios 2.3.0
tns-android 2.3.0
xCode 7.3.1
iOS 9.3 simulator
Android 5.1.0 emulator - genymotion galaxy s6
Internet connection works fine
Hi,
Are there any examples on how to use this project with NativeScript 2.0 and Angular2?
Thanks
Hi,
I am trying to connect to Pusher using
let mySocket = new WebSocket("ws://ws.pusherapp.com:80/app/<key>");
Socket is getting closed with the following exception as soon as it opens
org.java_websocket.exceptions.InvalidFrameException: more than 125 octets
What could be the possible reason?
@NathanaelA when you say "The sending of Protocols support is not fully implemented on both platforms. Do not depend on this; it only partially works.", does that mean WS.send(message) isn't reliable and shouldn't be used? I'm currently working on Meteor ddp client using your plugin and need to reliably send messages to the server.
I still have many issues using this library in iOS. I'm using it to talk to a remote go-websocket sending and receiving protobuf-messages, and I have timeouts, messages sent badly (I opened #54 for that) and sometimes a 1002
websocket error.
I'm using the latest nativescript (4.2.3) and nativescript-websockets 1.5.2. I tried both the 'browser' websocket and the advanced interface.
Before I loose my mind, is iOS tested and supported? From my point of view it looks as not... Android works great, by the way, with exactly the same code!
The behaviour can be seen on Android and iOS. With below code, I am unable see any logs, and that means the activity to open connection remain dormant / passive. If I add this.websocket.open()
after the line new WS(address, {timeout: 6000});
, I see that all the registered callbacks are triggered.
const address: string = `ws://${hostIpAddress}:${GuestModeComponent.PORT}`;
this.websocket = new WS(address, {timeout: 6000});
this.websocket.on("open", socket => {
this.ngZone.run(() => this.onConnectionOpened(socket));
});
this.websocket.on("close", (socket, code, reason) => {
console.log("Close");
this.ngZone.run(() => this.onConnectionClosed(socket, code, reason));
});
this.websocket.on("error", (socket, error) => {
console.log("ERROR");
this.ngZone.run(() => this.onConnectionError(socket, error));
});
this.websocket.on("message", (socket, message) => {
this.ngZone.run(() => this.onMessageReceived(socket, message));
});
Additional details:
- "nativescript-websockets": "^1.5.0",
- "tns-android version": "4.0.1"
- "tns-ios version": "4.0.1"
Hello,
I'm trying to use this to connect to Firebase, which uses wss://, and for some reason it's getting stuck at the socketFactory.createSocket() call. I've separated line 166 of websockets.android.js to:
var s = socketFactory.createSocket();
this._socket.setSocket( s );
When I debug it, I can't step past that first call. Any idea what might be happening?
I'm going to try to reproduce this in Java and if that works it must be a Nativescript issue.
One possible cause I've thought of is the use of the parameterless createSocket() call - in some situations that throws a "Unconnected sockets not implemented" (see here) so maybe that's what's happening?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.