becvert / cordova-plugin-websocket-server

Cordova WebSocket Server Plugin
MIT License
84 stars 35 forks source link

Android Webview can't open connection to ws://localhost #71

Open bcjat opened 4 years ago

bcjat commented 4 years ago

I have googled and found that chrome webview can't open connection to WebSocket server that is unsecure. So please describe how to run WebSocketServer using secure context with TLS?

becvert commented 4 years ago

Do you connect from a secure url https://localhost ? It won't work in that case. This plugin does not support TLS. As is, it's meant to be run into a local network between trusted devices. Unless you can PR a solution.

bcjat commented 4 years ago

I setup server in one device with port 8888. Now I make connection from another device using var webClient = new WebSocket( "ws://localhost:8888"); but it gives ERR_CONNECTION_REFUSED. So I googled about this error and found that chrome webview does not allow non secure ws:// connection to localhost it should be wss://. What will be solution for this case.

becvert commented 4 years ago

Mixed content is not allowed. But unsecure websocket from an unsecure origin is allowed. Did you remove the origins and protocols options from the WebSocketServer config?

bcjat commented 4 years ago

Yes I had removed that both options from config. Is it needed for unsecure context? If yes then what will be values for those both options?