K
K
K. A.2017-06-06 02:27:06
Layout
K. A., 2017-06-06 02:27:06

How to send a socket the property value of all other sockets?

I'm picking Node,js, I've reached the Socket.IO library. I've run into a problem that I haven't been able to find a solution to yet.
The server has the following lines:

io.on('connection', function(socket){
    socket.session = {};
    socket.session.address = socket.handshake.address;           

    function setName(name){
        if(name != undefined && name != ''){
            socket.session.userName = name;
            socket.broadcast.emit('newUser', socket.session.userName);
            socket.emit('userName', socket.session.userName);
            logger.info('User '+socket.session.userName+' join from IP: '+socket.session.address);
        }
        else
            socket.emit('setName');
    }
    setName(null);
    socket.on('setName', function(name){
        if(name.length > 0)
            setName(name);
        else
            socket.emit('setName');
    });

...
}

I wondered how, with a successfully given login (socket.session.userName), send the names of all other sockets to the socket (socket.session.userName of all other sockets)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jupiter Max, 2018-10-03
@hoppiN

<div class="tab-links">
    <ul>
        <li>
      <a href="#tab1">Tab 1</a>
  </li>
  <li>
            <a href="#tab2">Tab 2</a>
  </li>
    </ul>
</div>
<div class="tab-item-wrapper">
    <div class="tab-item" id="tab1">Content 1</div>
    <div class="tab-item" id="tab2">Content 2</div>
</div>
<div class="tab-links">
    <ul>
        <li>
      <a href="#tab1">Tab 1</a>
  </li>
  <li>
            <a href="#tab2">Tab 2</a>
  </li>
    </ul>
</div>

var tabContainers = $('.tab-item-wrapper .tab-item');

tabContainers.hide().filter(':first').show();
  
$('.tab-links a').click(function () {
  tabContainers.hide();
  tabContainers.filter(this.hash).fadeIn("slow");
  $('.tab-links a').removeClass('selected');
  $(this).addClass('selected');
  return false;
}).filter(':first').click();

Well, you’ll probably add the styles yourself, right? :-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question