Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channels not private.. #1238

Closed
acegilz opened this issue Oct 8, 2018 · 2 comments
Closed

Channels not private.. #1238

acegilz opened this issue Oct 8, 2018 · 2 comments

Comments

@acegilz
Copy link

acegilz commented Oct 8, 2018

I want to make a uni-direccional private channel from where server can communicate with the individual clients, each client is subscribing to a specific channel to get updates of sensible information from the server (eg balance).

The issue with this approach is that anyone on the namespace can see them. Although the client is not directly subscribing to that channel, anyone can see all the messages / channels from the Socket / Resources on safari for example.

Backend:

var io = require('socket.io').listen(process.env.PORT || 3001);

var redis = require('redis').createClient();
redis.subscribe('balance');

io.on('connection', function(socket) {

	console.log('connected socket')

	socket.on('disconnect', function(){
	 console.log('client disconnected')
	 socket.disconnect();
	});
	
});


redis.on('message', function(channel, message){

	//I get the info from a redis subscription
	data = {balance: info.balance, locked: info.locked}
	let room = 'balance_'+info.uid;
	io.emit(room, data);
}

Frontend:

import * as io from 'socket.io-client';

export class SocketioService {

   getBalance(uid) {
     
    let observable = new Observable(observer => {
      this.socket = io.connect(this.url, {secure: true});

      let room = 'balance_'+uid;

      this.socket.on(room, (data) => {

        var datax = JSON.stringify(data);
        observer.next(datax);   
      });

      return () => {
        this.socket.disconnect();
      };

    });
    return observable;
  }
}

screenshot 2018-10-08 02 00 20

@cetindogu
Copy link

i think you need to you
"io.in(room).emit(room, data);" instead of "io.emit(room, data);"

@acegilz
Copy link
Author

acegilz commented Oct 15, 2018

i think you need to you
"io.in(room).emit(room, data);" instead of "io.emit(room, data);"

That was the problem..
Thanks @cetindogu !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants