title: Sending and Receiving request for Private Chat using RTCMultiConnection-v3
body: <p>I am using RTCMultiConnection-v3. I need your help to develop one functionality for private chat application.
  What I want to do is I have many users in my applications. A single user can chat with multiple users at a time.
  But I want to do below scenario.</p>
  
  <blockquote>
    <p>User 1 : Send request for Private Chat to User 2<br/> User 2 : Will
    get Popup notification for accepting/Rejecting User 1's Request.<br/>
    User 2 : If Accepts Private Chat Request then One session will start
    for Private Chat, later new user can be invited.<br/></p>
  </blockquote>
  
  <p>In a single page, single user can start Private chat with multiple users
  I don't understand How can I do Sending Chat Request and Receiving Request from another users and then Accept another user request then start chat session.</p>
  
  <p>I have tried with Custom+Socket+Event using RTCMultiConnection, but it worked for one user not for other users</p>
  
  <pre><code>&lt;article&gt;
      &lt;section class="experiment"&gt;
          &lt;div class="make-center"&gt;
              &lt;input type="text" id="room-id" value="abcdef"&gt;
              &lt;button id="open-room"&gt;Open Room&lt;/button&gt;
              &lt;button id="join-room"&gt;Join Room&lt;/button&gt;
              &lt;button id="open-or-join-room"&gt;Auto Open Or Join Room&lt;/button&gt;
  
              &lt;br&gt;&lt;br&gt;
              &lt;p&gt;
                  Use this button to share custom messages (strings, numbers, objects, whatever) among all the users on this page. Remember, all the users MUST be using same URL.
                  &lt;br&gt;
                  &lt;button id="send-custom-message" disabled&gt;Send Custom Message&lt;/button&gt;
                  &lt;button onclick="sendCustomMessage(10)"&gt;Send Custom Message To 10&lt;/button&gt;
                  &lt;button onclick="sendCustomMessage(11)"&gt;Send Custom Message To 11&lt;/button&gt;
                  &lt;button onclick="sendCustomMessage(12)"&gt;Send Custom Message To 12&lt;/button&gt;
              &lt;/p&gt;
  
              &lt;div id="room-urls" style="text-align: center;display: none;background: #F1EDED;margin: 15px -10px;border: 1px solid rgb(189, 189, 189);border-left: 0;border-right: 0;"&gt;&lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div id="videos-container"&gt;&lt;/div&gt;
      &lt;/section&gt;
  
      &lt;script src="https://rtcmulticonnection.herokuapp.com/dist/RTCMultiConnection.min.js"&gt;&lt;/script&gt;
      &lt;script src="https://rtcmulticonnection.herokuapp.com/socket.io/socket.io.js"&gt;&lt;/script&gt;
  
      &lt;script&gt;
          document.getElementById('open-room').onclick = function () {
              disableInputButtons();
              connection.open(document.getElementById('room-id').value, function () {
                  showRoomURL(connection.sessionid);
              });
          };
  
          document.getElementById('join-room').onclick = function () {
              disableInputButtons();
              connection.join(document.getElementById('room-id').value);
          };
  
          document.getElementById('open-or-join-room').onclick = function () {
              disableInputButtons();
              connection.openOrJoin(document.getElementById('room-id').value, function (isRoomExists, roomid) {
                  if (!isRoomExists) {
                      showRoomURL(roomid);
                  }
              });
          };
  
          var chatContainer = document.querySelector('.chat-output');
  
          function appendDIV(event) {
              var div = document.createElement('div');
              div.innerHTML = event.data || event;
              chatContainer.insertBefore(div, chatContainer.firstChild);
              div.tabIndex = 0;
              div.focus();
  
              document.getElementById('input-text-chat').focus();
          }
  
          function sendCustomMessage(event_id) {
              var newConnection = new RTCMultiConnection();
              newConnection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';
              newConnection.socketMessageEvent = 'custom-socket-event-demo-' + event_id;
              newConnection.session = {
                  audio: true,
                  video: true
              };
  
              newConnection.sdpConstraints.mandatory = {
                  OfferToReceiveAudio: true,
                  OfferToReceiveVideo: true
              };
              newConnection.socketCustomEvent = 'custom-socket-event-demo-' + event_id;
              newConnection.connectSocket(function (socket) {
                  // listen custom messages from server
                  socket.on(newConnection.socketCustomEvent, function (message) {
                      if (message.customMessage === 1) {
                          var customMessage = prompt('Enter test message.');
                          socket.emit(newConnection.socketCustomEvent, {
                              sender: newConnection.userid,
                              customMessage: customMessage
                          });
                      }
                      if (message.customMessage === "Yes") {
                          alert("Accepted - " + newConnection.connectionDescription.remoteUserId);
                          newConnection.peers[newConnection.connectionDescription.remoteUserId].peer.close();
  
                      }
                  });
  
                  // send custom messages to server
                  var customMessage = prompt('Enter test message.');
                  socket.emit(newConnection.socketCustomEvent, {
                      sender: newConnection.userid,
                      customMessage: customMessage
                  });
              });
          }
          var connection = new RTCMultiConnection();
  
          connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';
  
          connection.socketMessageEvent = 'custom-socket-event-demo-&lt;?= $_GET["id"] ?&gt;';
  
          connection.session = {
              audio: true,
              video: true
          };
  
          connection.sdpConstraints.mandatory = {
              OfferToReceiveAudio: true,
              OfferToReceiveVideo: true
          };
  
          connection.videosContainer = document.getElementById('videos-container');
          connection.onstream = function (event) {
              connection.videosContainer.appendChild(event.mediaElement);
              event.mediaElement.play();
              setTimeout(function () {
                  event.mediaElement.play();
              }, 5000);
          };
          connection.socketCustomEvent = 'custom-socket-event-demo-&lt;?= $_GET["id"] ?&gt;';
  
          connection.connectSocket(function (socket) {
              // listen custom messages from server
              socket.on(connection.socketCustomEvent, function (message) {
                  if (message.customMessage === "1") {
                      var customMessage = prompt('Enter test message.');
                      socket.emit(connection.socketCustomEvent, {
                          sender: connection.userid,
                          customMessage: customMessage
                      });
                  }
              });
  
              // send custom messages to server
              document.getElementById('send-custom-message').disabled = false;
              document.getElementById('send-custom-message').onclick = function () {
                  var customMessage = prompt('Enter test message.');
                  socket.emit(connection.socketCustomEvent, {
                      sender: connection.userid,
                      customMessage: customMessage
                  });
              }
          });
  
          function disableInputButtons() {
              document.getElementById('open-or-join-room').disabled = true;
              document.getElementById('open-room').disabled = true;
              document.getElementById('join-room').disabled = true;
              document.getElementById('room-id').disabled = true;
          }
  
          function showRoomURL(roomid) {
              var roomHashURL = '#' + roomid;
              var roomQueryStringURL = '?roomid=' + roomid;
  
              var html = '&lt;h2&gt;Unique URL for your room:&lt;/h2&gt;&lt;br&gt;';
  
              html += 'Hash URL: &lt;a href="' + roomHashURL + '" target="_blank"&gt;' + roomHashURL + '&lt;/a&gt;';
              html += '&lt;br&gt;';
              html += 'QueryString URL: &lt;a href="' + roomQueryStringURL + '" target="_blank"&gt;' + roomQueryStringURL + '&lt;/a&gt;';
  
              var roomURLsDiv = document.getElementById('room-urls');
              roomURLsDiv.innerHTML = html;
  
              roomURLsDiv.style.display = 'block';
          }
  
          (function () {
              var params = {},
                      r = /([^&amp;=]+)=?([^&amp;]*)/g;
  
              function d(s) {
                  return decodeURIComponent(s.replace(/\+/g, ' '));
              }
              var match, search = window.location.search;
              while (match = r.exec(search.substring(1)))
                  params[d(match[1])] = d(match[2]);
              window.params = params;
          })();
  
          var roomid = '';
          if (localStorage.getItem(connection.socketMessageEvent)) {
              roomid = localStorage.getItem(connection.socketMessageEvent);
          } else {
              roomid = connection.token();
          }
          document.getElementById('room-id').value = roomid;
          document.getElementById('room-id').onkeyup = function () {
              localStorage.setItem(connection.socketMessageEvent, this.value);
          };
  
          var hashString = location.hash.replace('#', '');
          if (hashString.length &amp;&amp; hashString.indexOf('comment-') == 0) {
              hashString = '';
          }
  
          var roomid = params.roomid;
          if (!roomid &amp;&amp; hashString.length) {
              roomid = hashString;
          }
  
          if (roomid &amp;&amp; roomid.length) {
              document.getElementById('room-id').value = roomid;
              localStorage.setItem(connection.socketMessageEvent, roomid);
  
              // auto-join-room
              (function reCheckRoomPresence() {
                  connection.checkPresence(roomid, function (isRoomExists) {
                      if (isRoomExists) {
                          connection.join(roomid);
                          return;
                      }
  
                      setTimeout(reCheckRoomPresence, 5000);
                  });
              })();
  
              disableInputButtons();
          }
      &lt;/script&gt;
  &lt;/article&gt;
  </code></pre>