You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using nginx on linux to put my nodejs and socket.io signaler server online, I don't know why but only users who are on the same network can communicate on socket.io, how can i configure nginx and socket.io server to allow communication between users outside the network ?
Here is my nginx and socket.io server configuration:
var channels = {};
var users = [];
io.sockets.on('connection', function (socket) {
var initiatorChannel = '';
if (!io.isConnected) {
io.isConnected = true;
}
socket.on('new-channel', function (data) {
if (!channels[data.channel]) {
initiatorChannel = data.channel;
}
channels[data.channel] = data.channel;
onNewNamespace(data.channel, data.sender);
});
socket.on('presence', function (channel) {
var isChannelPresent = !! channels[channel];
socket.emit('presence', isChannelPresent);
});
socket.on('disconnect', function (channel) {
if (initiatorChannel) {
delete channels[initiatorChannel];
}
});
});
function onNewNamespace(channel, sender) {
io.of('/' + channel).on('connection', function (socket) {
var username;
if (io.isConnected) {
io.isConnected = false;
socket.emit('connect', true);
socket.emit('user-video-stream', JSON.stringify(users));
}
I'm using nginx on linux to put my nodejs and socket.io signaler server online, I don't know why but only users who are on the same network can communicate on socket.io, how can i configure nginx and socket.io server to allow communication between users outside the network ?
Here is my nginx and socket.io server configuration:
server {
listen 80;
listen [::]:80;
server_name 5902483.lovecames.com;
root /usr/share/nginx/html;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name 5902483.lovecames.com;
root /usr/share/nginx/html;
location ~* .io {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy false;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location ~* / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
}
var fs = require('fs');
var _static = require('node-static');
var file = new _static.Server('./static', {
cache: false
});
var app = require('http').createServer(serverCallback);
function serverCallback(request, response) {
request.addListener('end', function () {
response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
response.setHeader('Access-Control-Allow-Headers', 'Content-Type');
}
var io = require('socket.io').listen(app, {
// log: true,
origins: ':'
});
io.set('transports', [
//'websocket',
'xhr-polling',
'jsonp-polling'
]);
var channels = {};
var users = [];
io.sockets.on('connection', function (socket) {
var initiatorChannel = '';
if (!io.isConnected) {
io.isConnected = true;
}
});
function onNewNamespace(channel, sender) {
io.of('/' + channel).on('connection', function (socket) {
var username;
if (io.isConnected) {
io.isConnected = false;
socket.emit('connect', true);
socket.emit('user-video-stream', JSON.stringify(users));
}
}
function isInArray(users,newUser) {
found = false;
users.forEach(function(element) {
if(element.videoId == newUser.videoId) found = true;
}, this);
return found;
}
app.listen(8080, '0.0.0.0', function(){
console.log('listening on *:8080');
});
var SIGNALING_SERVER = 'https://5902483.lovecames.com/';
The text was updated successfully, but these errors were encountered: