I have an issue related to socket.io on its nodejs server. Issue is something related to socket.io is not working on IOS mobile browser in IOS8+. I have searched for it and went through some solutions but nothing worked.
Here are the issue links:
https://github.com/Automattic/socket.io/issues/976
http://www.codedisqus.com/7yzSqUgqge/socketio-working-on-desktop-safari-chrome-but-not-mobile.html
Here is the code
io.sockets.on('connection', function(socket) {
process.emit('client-connection', socket.id);
socket.on('authenticate', function(message) {
console.log('Authenticating client with key "' + message.authToken + '"');
authenticateClient(socket, message);
});
socket.on('message', function(message) {
if (io.sockets.sockets[socket.id] && message.hasOwnProperty('type')) {
if (message.hasOwnProperty('channel')) {
if (settings.clientsCanWriteToChannels || ChannelIsClientWritable(message.channel)) {
process.emit('client-message', socket.id, message);
}
}
return;
}
});
socket.on('disconnect', function () {
console.log("in disconnect");
process.emit('client-disconnect', socket.id);
cleanupSocket(socket);
});
})
Please let me know.
The basic issue is that when I try to open a session on browser it works fine and if I try to do the same on iPhone device browser it fails to work.
As per requirement the issue was IOS socket was not opening over SSL in mobile browsers. I have reinstalled the SSL certificate with complete code packet and it worked for me.
There might be some issue with SSL code packet due to which configuration was not complete.
Related
So i'm posting a formdata object with axios to a node.js server. On iOS everything works perfectly, the data get posted and the image uploaded. But on android i'm getting this error
[AxiosError: Network Error]
here's my axios call
const handleSubmit = async (listing, { resetForm }) => {
const data = new FormData();
listing.images.forEach((image, index) =>
data.append("images", {
name: `product${Math.floor(Math.random() * 1000)}.`,
uri: image,
})
);
const res = await axios
.post("http://192.168.43.8:5000/products/addProduct", data, {
headers: {
"Content-Type": "multipart/form-data",
},
//tried adding this but didn't work out
transformRequest: (data) => data,
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
// handle error
});
}
}
Please note that on iOS it works without a problem.
here's a screenshot of the error when i used the react native debugger
if you use android emulator you need to change your ip to 10.0.2.2
change this:
http://192.168.43.8:5000/products/addProduct
to this:
http://10.0.2.2:5000/products/addProduct
By default http calls are blocked from android 9 version onwards, you either need to make your api calls HTTPS or you need to explicitly allow connection to this IP in your manifest file. Please refer this SO thread. How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?
For me i am getting axios error for my emulator and did not getting any error for ios simulator. The problem with my emulator is that it is not able to connect to Internet.
So I added google DNS server 8.8.8.8 (you can add any DNS server) for my mac and it worked.
i'm using Firebase API to anonymously login and get data from Tampermonkey extension. Works as charm in Chrome but doesn't work in Firefox at all.
firebase.auth().signInAnonymously().catch(function(error) {
console.log("login error: "+ error);
});
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
firebase.database().ref().once("value").then(function(snapshot) {
debugger; // never gets here
GM_setValue("lastUpdate", new Date());
GM_setValue("lastState", snapshot.val());
}).catch(function(error) {
debugger; // never gets here
console.log("error reading DB: " + error);
});
}
});
it never comes to debugger in Firefox. No errors in console at all. what could be a reason? GM_xmlhttprequest instead works more or less in both, but i need auth as well so wanted to use official API.
thank you
UPDATE: after recent Chrome update it doesn't work there as well. Silently dies somewhere...
it turns that there is a value in localStorage that preventing everything from working. code below at application init solves issue.
if (localStorage) { // fix for API
localStorage.removeItem("firebase:previous_websocket_failure");
}
something sets it to true and nobody is cleaning it. there are issues about it since 2017 on github about this, seems not resolved yet.
I cannot access REST API. CORS problem on ionic 3 iOS build
Below is a screenshot of the problem. I use Safari to check the console messages of the iOS ionic app
https://imgur.com/a/WO3M5
Here is how I made the api call
var url = this.baseurl.baseurl();
var data = "username=" + this.username + "&password=" + this.password + "&device_uuid=ionic";
this.http.post(url + 'parent/parent_login_with_companyname', encodeURI(data), { headers: new __WEBPACK_IMPORTED_MODULE_4__angular_common_http__["c" /* HttpHeaders */]().set('Content-type', 'application/x-www-form-urlencoded') })
.subscribe(function (res) {
loading_1.dismiss();
window.localStorage.setItem('parent_info', JSON.stringify(res));
_this.navCtrl.setRoot(__WEBPACK_IMPORTED_MODULE_2__tabs_tabs__["a" /* TabsPage */]);
}, function (err) {
SOLUTION
After a very long search I found this holy grail! Hope this works for you as it did for me:
http://uncaughterror.com/programming/ionic3/preflight-response-issue-with-ionic3-app-on-ios-build-only-resolved/
You can disable the same-origin policy on Safari , in order to disable it you only need to enable the developer menu, and select "Disable Cross-Origin Restrictions" from the develop menu.
This you can do when you are in development phase. You will not get this issue when you will move application to live server and can access it without disabling cross -origin restrictions.
I just started building me server using socket.io for both my client and Node.js server side.
I'm writing an Objective-c project so i walk through the process of adjusting my project to use Swift alongside with Objective-c which was a pain but it seems to be ok now.
The thing is, when i try to do a simple connect to my server, which prints to log on each connection, nothing happens.
This is the code for the server (Taken from here):
var fs = require('fs')
, http = require('http')
, socketio = require('socket.io');
var server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-type': 'text/html'});
}).listen(8080, function() {
console.log('Listening at: http://localhost:8080');
});
socketio.listen(server).on('connection', function (socket) {
console.log('Connected');
socket.on('message', function (msg) {
console.log('Message Received: ', msg);
socket.broadcast.emit('message', msg);
});
});
Super simple, really nothing to it.
And the Objective-c code for my client which is even more simple:
- (void) connect
{
SocketIOClient* client = [[SocketIOClient alloc]initWithSocketURL:#"http://127.0.0.1:8080/" options:nil];
[client connect];
}
But i can't see nothing on my console except the Listening at: http://localhost:8080 message.
I can't seem to find what i'm doing wrong here, and the fact that the swift debugging is horrible in this combined project, i can't really fully go through the socket.io debugging myself (but i'm pretty sure nothing's wrong with their code)
Any help would be much appreciated.
plz confirm, if you are using the simulator for iOS testing. For device, you need to assign public address to your NodeJS server, and then need to use it's ip in iOS Codebase.
I had used https://github.com/pkyeck/socket.IO-objc during my last project and it worked like a charm.
For simulator, your code should ideally work.
I have an app written in HTML5, Javascript, css3 using PhoneGap to compile for iOS and Android. It collects survey information and uploads this via Ajax call to online host. It has been working really well until recently the upload code appeared to stop working. WELL NOT QUITE! On the iPad it says successful but in fact nothing ever makes it to the host. This is VERY strange. I've tried re-writing the Ajax call based on articles on here but no luck.
iOS - 6.1.3, PhoneGAP 2.7.0, PhoneGap/Adobe Build used.
This is the upload piece...
function sendToWeb(){
var errorflag = false;
db.transaction(function (tx) {
tx.executeSql("SELECT weburl FROM settings", [], function(tx, results){
var webURL = results.rows.item(0).weburl;
tx.executeSql("SELECT * FROM surveypretransfer WHERE uploaded = '0'",[], function(tx, results){
if (results.rows.length == 0) {
alert("You have no surveys waiting to upload");
} else {
alert("You have " + results.rows.length + " surveys waiting to upload");
for (var i=0; i < results.rows.length; i++) {
var responseURL = webURL + "/feeds/saveinfo.php";
var responseString = results.rows.item(i).responsestring;
var localid = results.rows.item(i).id;
//alert(localid);
$.ajax({
type: 'POST',
data: responseString,
url: responseURL,
timeout: 30000,
success: function(data) {
alert('Success!' + data.join('\n'));
},
error: function(data) {
alert(data.join('\n'));
console.log("Results: " + localid);
alert("Error during Upload. Error is: "+ data.statusText);
}
}); //ajax
}; //for loop
alert("You have successfully uploaded "+ results.rows.length + " survey results");
tx.executeSql("UPDATE surveypretransfer SET uploaded = '1' WHERE uploaded = '0'");
}; //if statement
}); //tx.execute
});
}, errorCB);
}
Neither of the two alerts fire when loaded on iPad. Works fine on Android and has previously worked on iPad so I can't find what has changed.
UPDATE: Appears that this only applies to WiFi only iPads. All the 3G ones I tested were fine. Figure that!
Config.XML contains app id = "com.mydomain.myapp" (as an example)
URL for upload is "http://customer.mydomain.com/feeds/saveinfo.php?..."
Also added line 'access origin="http://mydomain.com" subdomains="true" '
Still no results. Is anyone seeing/having similar issues? Anyone see my mistake?
For iOS you might want to try <access origin="http://*.mydomain.com" />, as iOS is not documented in the PhoneGap API to support the subdomain property.
If that doesn't solve your issues, you will probably want to look into CORS (Cross Origin Resource Sharing). I had issues trying to do a POST request from my app to a local port on iOS. The W3C has a great article on how to enable CORS that will probably help. I know in my case, the system would attempt to do an OPTIONS request first, and if it didn't work, the whole thing would fail.
Another tool that you will probably find useful (if not now, in the future) is Fiddler. You can set up an iPad to proxy through your desktop, and then you will be able to observe all of the requests going to and from the device. This is how I found the OPTIONS request noted above.