Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

fix(connection): fix connection crash when use without web browser #39

Closed
wants to merge 2 commits into from

Conversation

duyluonglc
Copy link

Hi @thetutlage
I have issue when use websocket-client with react-native. After check your code
const wsProtocol = window.location.protocol === 'https:' ? 'wss' : 'ws'
location is undefined because it's not call from web browser.
This PR will fix this issue
Please check when avaialbe

@thetutlage
Copy link
Member

thetutlage commented Apr 22, 2018

This is just a patch on a short circuit.

The fix should be to stop booting ws client when rendered server side.

I don’t do SSR much, so I am not sure, if there’s a proper way to detect the running environment and add conditionals on basis of that

@thetutlage
Copy link
Member

Okay my bad, you wrote react-native and not ssr. If you are not in a browser, I don't think it will infact work.

The websocket-client relies on the web browser implementation of sockets, so it will fail anyways

@duyluonglc
Copy link
Author

Seem the test script failed :(
But I checked with react-native and the websocket works good after remove window.location.protocol from dist file.
Can we detect window.location exists before assign?
const wsProtocol = window.location ? (window.location.protocol === 'https:' ? 'wss' : 'ws') : ''

@thetutlage
Copy link
Member

Duplicate of #42

@thetutlage thetutlage marked this as a duplicate of #42 Jun 18, 2018
@thetutlage thetutlage closed this Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants