Cross Domain Connection Doesnt work from browser
slidenerd opened this issue · 0 comments
I am trying to connect to an external domain and tested the same in both socketio and socketcluster, for some reason the socketio connection works while the socket cluster one doesnt connect
Perhaps I am overlooking something but here is a wss url that I attempted to connect with and still getting errors on it
function connectWithSocketIO() {
var subscriptionUrl = 'wss://stream.binance.com:9443/ws/!miniTicker@arr'
var ws = new WebSocket(subscriptionUrl)
// var socket = io.connect(subscriptionUrl)
ws.onmessage = function (data) {
console.log(data)
}
}
function connectWithSocketCluster() {
var options = {
host: 'stream.binance.com:9443/ws/!miniTicker@arr',
secure: true,
rejectUnauthorized: false
}
// Initiate the connection to the server
var socket = socketCluster.create(options);
socket.on('connect', function () {
console.log('connected')
});
socket.on('message', function(data){
console.log(data)
})
socket.on('error', function (e) {
console.log(e);
});
}
The socket io approach gives no errors but the second one is giving me a
{
"name": "SocketProtocolError",
"message": "Encountered a policy violation",
"code": 1008,
"stack": "p@https://cdnjs.cloudflare.com/ajax/libs/socketcluster-client/13.0.0/socketcluster.min.js:5:28854\n[5]</</w.prototype._onSCClose@https://cdnjs.cloudflare.com/ajax/libs/socketcluster-client/13.0.0/socketcluster.min.js:4:14946\n[5]</</w.prototype.open/<@https://cdnjs.cloudflare.com/ajax/libs/socketcluster-client/13.0.0/socketcluster.min.js:4:9876\n[12]</r.prototype.emit@https://cdnjs.cloudflare.com/ajax/libs/socketcluster-client/13.0.0/socketcluster.min.js:5:21047\n[6]</</p.prototype._onClose@https://cdnjs.cloudflare.com/ajax/libs/socketcluster-client/13.0.0/socketcluster.min.js:4:23704\np/s.onclose@https://cdnjs.cloudflare.com/ajax/libs/socketcluster-client/13.0.0/socketcluster.min.js:4:21492\n"
}
Direction is appreciated
Update 3
This is the generated URL i found under network tab
Socket IO
https://stream.binance.com:9443/ws/!miniTicker@arr
Socket Cluster
https://stream.binance.com:9443/ws/!miniTicker@arr/socketcluster/ That doesnt look correct at all. It seems there is some issue with the way urls are generated, perhaps a better option is to let the user control urls fully instead of building it
I see that you have an option called path here https://socketcluster.io/#!/docs/api-socketcluster-client which adds the /socketcluster/ , setting the path to an empty string still hasnt fixed this issue
I think I understand that socketcluster client is very different from socketio client and doesnt do the same things :)