Comments (9)
Ah. interesting. Of course I have not used this lib with credentials, so there we have our discrepancies. Let me look into this tonight and I'll get back to you.
from react-native-signalr.
Hmm.. weird. And I guess it's not the same as #11 ? Must be something wrong in the setup/rn-version or something. Hard to guess without repro. Websockets works in iOS on my end of course. Can you somehow debug on the server and see if the connection is received?
from react-native-signalr.
@somoso Did you have any success in tracking down this issue? Let me know if I can help in any way. But I will need more info/better debug-scenario to be able to help efficiently.
Will close in a couple of days if I do not hear from you.
from react-native-signalr.
Thanks for checking this out - I'll give #11 a go and if that fails, I'll see if I can have access to the actual server and debug it from there.
from react-native-signalr.
Just a quick update, I've added NSAllowsArbitraryLoads in my Info.plists file and I couldn't get it to behave. For now I'm going to close this issue, but I'll reopen if I have any questions or issues with react-native-signalr.
Thanks for the help though!
from react-native-signalr.
OK, so I've managed to understand what is going on with a little help with Wireshark.
Before we interact with signalr, I go through a login process (mocked for now) which sets the cookie on our end. With Android, it passed those cookies in the header when doing a GET /signalr/negotiate
call and when doing a GET /signalr/connect
call. With the iOS app, it passes the cookies in the header in the GET /signalr/negotiate
call, but doesn't pass the cookies when doing a GET /signalr/connect
call!
Looking around on the internet, I though adding withCredentials: true
would fix things as below:
connection.start({withCredentials:true, transport: ['webSockets']}).done(() => {
console.log('Now connected, connection ID=' + connection.id);
exampleProxy.invoke("SomeMethod").done((r) => {
console.log("SomeMethod result",r);
});
}).fail(() => {
console.log('Failed');
});
but that still doesn't fix things. Using react-native-cookies
, I've found that all my cookies have the path parameter set to "/", so that's not the issue (plus, Android works fine).
I'm still using the same trick as addressed in #11 on the XCode project.
Is there a way to add a custom header on the connection so that I can pretty much just attempt to stuff the cookie in the header in the iOS version? Is there another trick that I'm missing?
from react-native-signalr.
I've just noticed while browsing your source code that in ajax.js there is an XMLHttpRequest() object which is used to help signalr communicate - I'm wondering if that XMLHttpRequest could do with having withCredentials: true
being passed in as well as setting it at the signalr level.
I'll give this a shot on my end and see if it fixes things tomorrow morning.
from react-native-signalr.
So just as a follow up, I've tried adding withCredentials: true
to the XMLHttpRequest and I saw no improvements. As I was unsure if it was being sent properly, after the line request.open('GET', options.url);
, I added the line request.setRequestHeader('x-react-native-header', 'soheb');
to see if my weird header would get passed along the chain - but it didn't!
Using Wireshark, I saw the header on the GET /signalr/negotiate
call, but it completely vanishes on the GET /signalr/connect
call.
I'm going to have to dig into ms-signalr-client and see what's going on
from react-native-signalr.
Right. Got it in the end.
Turns out that react's WebSocket implementation has an undocumented API that passes in headers: http://stackoverflow.com/questions/37246446/sending-cookies-with-react-native-websockets
So after much meddling with the source code, I decided to do a cheeky thing and just monkey patched in my own WebSockets, passing in my own cookies:
var oldws = window.WebSocket;
window.WebSocket = function(url) {
return new oldws(url, '', {Cookie: cookie_string});
}
That way, I don't need to keep patching your code nor Microsoft's SignalR code to pass in the cookies. It might be worth exposing the hidden 3rd parameter in WebSockets in your own APIs to allow people to set custom headers.
As for why it is even doing that in the first place, I've done some digging and found it's down to React Native source - in the Android side, the cookies get pulled in and passed in the header here: https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/modules/websocket/WebSocketModule.java#L94
While in iOS the connect call in RCTWebSocketModule uses initWithURLRequest (https://github.com/facebook/react-native/blob/master/Libraries/WebSocket/RCTWebSocketModule.m#L60) but looking at the RCTSRWebSocket class there is initWithURL which handles cookies and calls initWithURLRequest (https://github.com/facebook/react-native/blob/master/Libraries/WebSocket/RCTSRWebSocket.m#L292) that gets completely bypassed.
I'll close this ticket, but you can re-open if you want. I'll try to keep an eye on this for a while for any extra feedback & comments.
EDIT: There is a pull request for the iOS version on React Native: facebook/react-native#10575 (comment) - it seems like it is waiting on some testing
from react-native-signalr.
Related Issues (20)
- how can change state from on(event) HOT 1
- .NET core 2.0 support
- How is reconnection handled? HOT 3
- IOS - SignalR Connection break when app move in background. HOT 4
- Does it support Net Core 2.1 or later?
- get 'undefined' from server in invoke
- cannot receive message HOT 1
- Timer Error HOT 1
- Try specifying a different transport or none at all for auto initialization.
- How to send token or other data HOT 3
- Signal R not working with ANDROID STORE VERSION
- Unable to call signalR method
- Replace deprecated dependency ms-signalr-client HOT 1
- Failed - Error: Error during negotiation request. HOT 3
- Autoreconnect feature HOT 1
- TypeError: Cannot set property userAgent of #<Navigator> which has only a getter HOT 1
- hello
- Forgotten Package
- On Screen Change, Event Is Still fired HOT 7
- is this lib dead? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-signalr.