knowledgecode / websocket-for-android Goto Github PK
View Code? Open in Web Editor NEWCordova/PhoneGap plugin that makes WebSocket available on Android
License: Apache License 2.0
Cordova/PhoneGap plugin that makes WebSocket available on Android
License: Apache License 2.0
The current library does not support the WebSocket "origin" field as per the RFC, any way this can be added?
Hello, my team is developing a mobile application using Cordova and your plugin. I just received a report from my team this morning, she said she successfully tested a WebSocket connection in the application on her own development server. But, when she tried to test it on the company development server via VPN, she received an error that returns a connection error from a WebSocket, and she said it is quite hard to debug. Is there any way to detect the type of error and has anyone faced this issue via VPN before?
Hey,
could you please submit your plugin to the phonegap-build team on https://build.phonegap.com/plugins
Thank you very much
On close Web socket receives a 1002 event code. Any help would be appreciated.
Looks like the onerror method is missing from the java code.
When we use this plugin we have a problem.
Socket closed with error code 1008 and message Text frame aggregation disabled.
Can you describe how can be fix or resolve it.
Yes, we can crop data but we want get it without cropping.
Does the plugin still work if the index.html file has an iframe in it that connects to a website that uses websockets (via SockJS)?
I'm testing out Meteor apps with Cordova using an Android 4.2.1. I'm curious if this can work with it.
I was tryin gto release my application and websockets stoped working when I switched from
<application android:debuggable="true"
to
<application android:debuggable="false"
as I was going to release the aplpication
When I switched back to true websockets worked again
Any help appreciated.
Still unable to send and receive messages when there are multiple instances.
hi,
i have a problem: the app in some android device is running normal,but "in some devices"(android 4.0.3) i can conenct normally,receive infomation from other people using web normarlly , but
Failed to send message with "some devices"!
please help me ! thanks!
my cordova version 5.1.1 ,with cordova ceate android project target android 4.0.2.
if you find the probleam ,send email for me .email:[email protected]
I've test your plugin in two android devices, one tablet with a 4.1.1 version number, and a phone (S3) with a 4.3 version. In the first case, the sample (ws://echo.websocket.org) is runing ok, but in the second not (it seems that makes the create call, but no open event is called). Maybe there are any dependency on the android version? I think no, but i want to be sure.
Other thing is related to the loading of websocket.js file. In the Web Console (logcat) is shown one error:
E/Web Console(17298): Uncaught ReferenceError: require is not defined at file:///android_asset/www/js/websocket.js:29
The error is presented in both case (tablet and phone)
Thank you for your support. You're doing a great job!!!
Excuse me, I hope can use it without phonegap , does it can do webview java injection?
It's like this :
https://github.com/anismiles/websocket-android-phonegap
but it is not support RFC6455,I try to fix but not success,
Can you help me ?
Thank you & Appreciate .
I'm trying:
if("WebSocket" in window){
//code here
}else{
//erro here
}
Getting error. WebSocket not present in window.
-Cordova version 7.0,1
-Platform: android 6.2.3
-Android 4.1.1 (My device)
If the server sends JSON that has newlines in it, Cordova Javascript will barf with a syntax error. The createJsonForMessage() function should correctly escape newlines before sending.
Thanks for making this, by the way! Exactly what I needed!
Once installed with 'cordova plugin add com.knowledgecode.cordova.websocket', you get following classes placed in directory that doesn't match its package 'org.eclipse.jetty.util.thread'
classes affected: QueuedThreadPool, ThreadPool, Timeout.
The project compiles from CLI and there are correct classes complied under platforms ▸ android ▸ ant-build ▸ classes ▸ org ▸ eclipse ▸ jetty. But the problem is visible under ▸ platforms ▸ android ▸ src ▸ org ▸ eclipse ▸ jetty ▸ util where mentioned classes are placed and thread folder is missing.
It causes eclipse project errors.
I am using Mac environment for development.
I am Developing a hybrid app using phonegap. I developed whole app using browser and run it using apache. I also implemented websocket using html5. Socket works well in browser. For using it native with cordova i used your plugin. But when i try to work with websocket, i get error "Websocket is not defined" on line
var socket = new WebSocket("ws://localhost:9000/");
What i am doing wrong??? please help me
Hi,
When we pass a ws.close() to the plugin, it closes correctly (we see a disconnection on our server with code:1000 normal disconnection).
When we try and re-establish a connection (ws.create) nothing hits the server and the plugin appears to hang. We think this was not the case prior to the last update adding the origin when it looks like you also refactored some of the code.
Cheers
Rob
Thanks for your awesome plugin.
I trying to use it with express.io, https://github.com/techpines/express.io
But it fail and say handshake error.
I debug and find that android client seems forget to send cookie data.
How can I do that ?
Getting 'Uncaught ReferenceError: require is not defined'
Using Cordova 3.4.0. On android and on browser.
Hi,
When trying to run the plugin on wss, the wesocket goes right to on error.
I found in the logcat this message:
Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Couldn't find any solution to this issue.
Any idea ?
Thanks,
Tomer
Hi,
I use this plugin in cordova,and found the websocket close itself with 1005,I search the RFC doc it means CLOSE_NO_STATUS, I have realy no means, any help would be appreciated?
This is the event from onclose:
{"reason":"","code":1005,"wasClean":true,"path":{"length":0},"cancelBubble":false,"returnValue":true,"srcElement":{"binaryType":"blob","protocol":"","extensions":"","bufferedAmount":0,"readyState":3,"url":"ws://192.168.188.20:7001/ws","URL":"ws://192.168.188.20:7001/ws"},"defaultPrevented":false,"timeStamp":1487753895945,"cancelable":false,"bubbles":false,"eventPhase":2,"currentTarget":{"binaryType":"blob","protocol":"","extensions":"","bufferedAmount":0,"readyState":3,"url":"ws://192.168.188.20:7001/ws","URL":"ws://192.168.188.20:7001/ws"},"target":{"binaryType":"blob","protocol":"","extensions":"","bufferedAmount":0,"readyState":3,"url":"ws://192.168.188.20:7001/ws","URL":"ws://192.168.188.20:7001/ws"},"type":"close"}
I sniffer it and find the cordova app close it first:
Hello!
By using this plugin, is there any possibility to send/receive messages to/from a specific topic after making a connection and subscribing to that topic?
Thanks in advance!
When cookie-value contains "=" character(in my case, session-cookies like that are generated by the Play framework, which generates session-cookies like that:
PLAY_SESSION=<<session_id>>-connected=<>&websockid=<<socket_id>>;), this code fails:
private static void setCookie(Map<String, String> cookies, String host, String path, boolean secure) {
String url = String.format("%s://%s%s", secure ? "https" : "http", host, path);
String cookie = CookieManager.getInstance().getCookie(url);
if (cookie != null) {
for (String c : cookie.split(";")) {
String[] pair = c.split("=");
if (pair.length == 2) {
cookies.put(pair[0].trim(), pair[1].trim());
}
}
}
}
Since pair.length won't be 2. Suggested PR:
#35
fixes it.
I use CLI and add the plugin. When I add it I get two log lines telling it is added both to android and ios. For IOS there is a built in function for web socket already. Will this plugin be used instead of the build in web socket?
When I have built both IOS and Android it is working on the both plattforms.
Is there a way to ignore ca issues when using SSL/wss.
I have an issue with wss, though only with one server. I suspect it's to do with the CA. It would be nice if I could ignore the CA instead of not using SSL/wss
Hi, we are developing a cordova app which has to use a Websocket Service deployed by a 3rd part on cloud, this service for security reason is checking the origin header.
Using native WebSockets on Android 4.4 in WebView is setting always the origin header "file://".
We didn't found until now any solution to remove this header on android.
But we found your cordova plugin where we can set the header and remove them, this is working because you are using jettys WebsocketClient instead of native Websockts, but as you write on your readme from 4.4 this plugin is not used anymore.
So I would like to aks you two things:
Thx a lot for your help and time
Hi, the websocket is rebutting connection every 10 seconds and restarting the handshake.
I'm having a really weird behaviour, where sometimes onOpen is fired and sometimes it isn't.
Nothing appears on LogCat nor on Cordova log.
Tried on a Samsung Mega running Android 4.2.2, the compiled app has the right permissions, as it sometimes connects to the server.
[Question] I am new to github and I do not know where to ask questions, So I am asking here, help me out on this issue,
I added WebSocket plugin to my android project and made changes on js file on cordova 3.6.3 and android 4.3, but I am not able to create WebSocket connection.Is there anything I need to add on native side to initiate WebSocket connection.
Thanks in Advance.
@SuryaAdabala
Thank you for using this plugin. Your post was moved here.
Now I can't answer your question because of too few clues. Could you paste the code snippet here? What error message are you getting?
Do you know if it's possible to use the SockJS protocol over your websocket plugin? SockJS provides transparent fallbacks (XHR, etc) in cases were we can't use websockets (e.g. old Android versions). I want the fallback, but I'd like to use websockets wherever possible. So I guess I need for SockJS to use your Websocket object, but before I dig in, do you know already if it's possible? Tried Socket.IO?
This consts defined in prototype only, and it break capability for some WebSocket librarys..
Hi,
I'm encountering the following error:
W/System.err( 5875): 2014-10-08 10:35:19.388:WARN:oejw.WebSocketConnectionRFC645 5:Text message too large > 32768 chars for …
.
Is this expected? The same messages work when using the native websocket in Chrome.
Hi,
I have followed your example as described to establish a connection to websocket. Here is the setup, that I have:
Server Side (development):
Tomcat Websocket (javax.websocket v1.1).
Client Side (development):
Ionic v2.0.0
Cordova v6.3.1
When application is tested on web browser (on desktop), it works well with no issues/errors. However, after the application is built and installed on device. It shows error as following:
Android 6.0.1
Immediately on lauch of the app, it hits onerror and shows "isTrusted":true followed by error code 1006.
Looked up logcat, I notice this
[INFO:CONSOLE(162)] "WebSocket connection to 'ws://xx.xx.xx.xx:9090/ondemand/retail-orders/11' failed: Error during WebSocket handshake: Unexpected response code: 403", source: file:///android_asset/www/plugins/cordova-plugin-websocket/www/websocket.js (162)
Appreciate if you could please provide pointer/suggestion to overcome this issue faced.
Thanks in advance,
Vijay
It was tested on acer A500 Android 4.0.3-(failed to connect)
After installing plugin and deployment on device with android 4.4 I am getting following error.
"WebSocket connection to 'ws://xxxxxxxxxxxxx/' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received", source: file:///android_asset/www/plugins/com.knowledgecode.cordova.websocket/www/websocket.js (169)
To resolve it I need to set override plugin option to true although I would prepare platform implementation.
Hi!
I tried to use this plugin since last 2 days with cordova version 3.3.0. But, unfortunately
websocket.open method is not calling somehow. I tested on Android device Samsung Galaxy SDUOS of android version 4.0.4.
Let me to write the code which I have implemented as under where init method is called ondeviceready:
var wsUri = "ws://echo.websocket.org/";
var output;
function init() {
console.log('init');
output = document.getElementById("output");
testWebSocket();
}
function testWebSocket() {
console.log('testWebSocket');
websocket = new WebSocket(wsUri);
websocket.onopen = function(evt) {
console.log('in onopen');
onOpen(evt)
};
websocket.onmessage = function(evt) {
onMessage(evt)
};
websocket.onerror = function(evt) {
onError(evt)
};
}
function onOpen(evt) {
writeToScreen("CONNECTED");
doSend("WebSocket rocks");
}
function onMessage(evt) {
console.log('RESPONSE: ' + evt.data);
websocket.close();
}
function onError(evt) {
console.log('ERROR:' + evt.data);
}
function doSend(message) {
websocket.send(message);
}
Hope this will help you to identify if any mistake is found.
Thanks in advance..!
At installation of this plugin the permission (s. below) is written into AndroidManifest.xml, removing the plugin it removes it. So far so good.
This is a problem in the situation where the permission was already in AndroidManifest.xml BEFORE this plugin was installed. In this case I expect that the permission is NOT removed removing the plugin, because there can be other plugins which needs this permission.
But maybe this is the problem of cordova/phonegap plugin add/rm mechanism...in this case this issue is here to remind people about this.
AndroidManifest.xml:
SendingTask.java line 58
conn.sendMessage(rawArgs.substring(11, rawArgs.length() - 2));
rawArgs contains JSON.stringify
ed string, which escapes some symbols (specifically double quotes)
You should unescape them before sending it to server.
Something like
JSONArray json = new JSONArray(rawArgs);
String str = (String)json.get(0);
conn.sendMessage(str.substring(9, str.length()));
How can I use your code on Cordova 3.3.0. It seems that the plugin method is totally different on Cordova 3.0+.
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.