Obtain a public, canonically named (if possible) room and invite peers
502210
def _get_public_room(self, room_name, invitees: List[User]):
        
        room_name_full = f'#{room_name}:{self._server_name}'
        invitees_uids = [user.user_id for user in invitees]

        for _ in range(JOIN_RETRIES):
            # try joining room
            try:
                room = self._client.join_room(room_name_full)
            except MatrixRequestError as error:
                if error.code == 404:
                    self.log.debug(
                        f'No room for peer, trying to create',
                        room_name=room_name_full,
                        error=error,
                    )
                else:
                    self.log.debug(
                        f'Error joining room',
                        room_name=room_name,
                        error=error.content,
                        error_code=error.code,
                    )
            else:
                # Invite users to existing room
                member_ids = {user.user_id for user in room.get_joined_members(force_resync=True)}
                users_to_invite = set(invitees_uids) - member_ids
                self.log.debug('Inviting users', room=room, invitee_ids=users_to_invite)
                for invitee_id in users_to_invite:
                    room.invite_user(invitee_id)
                self.log.debug('Room joined successfully', room=room)
                break

            # if can't, try creating it
            try:
                room = self._client.create_room(
                    room_name,
                    invitees=invitees_uids,
                    is_public=True,
                )
            except MatrixRequestError as error:
                if error.code == 409:
                    msg = (
                        'Error creating room, '
                        'seems to have been created by peer meanwhile, retrying.'
                    )
                else:
                    msg = 'Error creating room, retrying.'

                self.log.debug(
                    msg,
                    room_name=room_name,
                    error=error.content,
                    error_code=error.code,
                )
            else:
                self.log.debug('Room created successfully', room=room, invitees=invitees)
                break
        else:
            # if can't join nor create, create an unnamed one
            room = self._client.create_room(
                None,
                invitees=invitees_uids,
                is_public=True,
            )
            self.log.warning(
                'Could not create nor join a named room. Successfuly created an unnamed one',
                room=room,
                invitees=invitees,
            )

        return room
204276
def rooms(self, sid, namespace=None):
        
        namespace = namespace or '/'
        return self.manager.get_rooms(sid, namespace)
934864
function gossiperBroadcast( sKey, vValue, pfnCallback )
{
	if ( ! DeUtilsCore.isExistingString( sKey ) )
	{
		return pfnCallback( `GOSSIPER ))) call gossiperBroadcast with invalid sKey: ${ JSON.stringify( sKey ) }` );
	}

	/**
	 * 	update local value and broadcast it to all connected peers
	 */
	_oGossiper.setLocalValue( sKey, vValue, err =>
	{
		if ( err )
		{
			return pfnCallback( err );
		}

		pfnCallback( null );
	});
}
965851
public function create_room($name, $owner_user_id = null, $privacy = null, $topic = null, $guest_access = null) {
     $args = array(
       'name' => $name
     );

     if ($owner_user_id) {
       $args['owner_user_id'] = $owner_user_id;
     }

     if ($privacy) {
       $args['privacy'] = $privacy;
     }

     if ($topic) {
       $args['topic'] = $topic;
     }

     if ($guest_access) {
       $args['guest_access'] = (int)$guest_access;
     }

     // Return the std object
     return $this->make_request('rooms/create', $args, 'POST');
    }
1347088
def get_joined_members(self):
        """"""
        if self._members:
            return list(self._members.values())
        response = self.client.api.get_room_members(self.room_id)
        for event in response["chunk"]:
            if event["content"]["membership"] == "join":
                user_id = event["state_key"]
                self._add_member(user_id, event["content"].get("displayname"))
        return list(self._members.values())
1222515
function sumOnLinePeers() {
	let nowTime = Date.now();
	assocOnlinePeers = {};
	Object.keys(assocAllOutBoundPeers).forEach(function(curUrl){    
		var curPeers = assocAllOutBoundPeers[curUrl];   
		if(nowTime - parseInt(curPeers.time) < 3 * 60 * 1000){
			for (var j=0; j<curPeers.peers.length; j++){
                if(assocOnlinePeers[curPeers.peers[j]]) 
					assocOnlinePeers[curPeers.peers[j]]++;
				else
					assocOnlinePeers[curPeers.peers[j]] = 1;
            }
		}       
    }); 
}
887421
function getOrCreatePeer(id)
    {
        if(scope.peers[id])
        {
            return scope.peers[id];
        }
        return createPeerInstance(id);
    }
745725
def enter_room(self, sid, room, namespace=None):
        
        return self.server.enter_room(sid, room,
                                      namespace=namespace or self.namespace)
898985
MeetMeRoomImpl getOrCreateRoomImpl(String roomNumber)
    {
        MeetMeRoomImpl room;
        boolean created = false;

        synchronized (rooms)
        {
            room = rooms.get(roomNumber);
            if (room == null)
            {
                room = new MeetMeRoomImpl(server, roomNumber);
                populateRoom(room);
                rooms.put(roomNumber, room);
                created = true;
            }
        }

        if (created)
        {
            logger.debug("Created MeetMeRoom " + roomNumber);
        }

        return room;
    }
836142
function join (options) {
  if (options.peerId.length !== 12) {
    return this.emit('we-ready', new Error('Unvalid peerId length, must be 48 bits, received: ' + options.peerId).toString())
  }

  if (peerTable[options.peerId]) {
    return this.emit('we-ready', new Error('peerId already exists').toString())
  }

  peerTable[options.peerId] = {
    socket: this,
    notify: typeof options.notify === 'boolean' && options.notify === true,
    fingers: options.fingers || {
      '0': {
        ideal: idealFinger(new Id(options.peerId), '0').toHex(),
        current: undefined
      }}
  }

  log('peer joined: ' + options.peerId)
  this.emit('we-ready')
  if (Object.keys(peerTable).length === 1) {
    return log('This was the first peer join, do nothing')
  }
  notify()
  if (peerTable[options.peerId].fingers['0'].current === undefined) {
    if (!peerTable[options.peerId].notify) {
      return
    }
    updateFinger(options.peerId, '0')
  }

  // notify if to other peers if this new Peer is a best finger for them
  function notify () {
    const newId = options.peerId
    const peerIds = Object.keys(peerTable)
    // check for all the peers
    // if same id skip
    // if notify === false skip
    // check the first finger that matches the criteria for ideal or next to ideal
    peerIds.forEach((peerId) => {
      if (newId === peerId) {
        return // skip ourselves
      }
      if (!peerTable[peerId].notify) {
        return // skip if it doesn't want to be notified of available peers
      }

      // if it had none, notify to get a successor
      if (peerTable[peerId].fingers['0'].current === undefined) {
        peerTable[peerId].fingers['0'].current = newId
        peerTable[peerId].socket.emit('we-update-finger', {
          row: '0',
          id: newId
        })
        return
      }

      const rows = Object.keys(peerTable[peerId].fingers)
      // find the first row that could use this finger
      rows.some((row) => {
        const finger = peerTable[peerId].fingers[row]
        const bestCandidate = fingerBestFit(
            new Id(peerId),
            new Id(finger.ideal),
            new Id(finger.current),
            new Id(newId))
        if (bestCandidate) {
          peerTable[peerId].fingers[row].current = newId
          peerTable[peerId].socket.emit('we-update-finger', {
            row: row,
            id: newId
          })
          return true
        }
      })
    })
  }
}
536645
def peer_store(key, value, relation_name='cluster'):
    """"""
    cluster_rels = relation_ids(relation_name)
    if len(cluster_rels) > 0:
        cluster_rid = cluster_rels[0]
        relation_set(relation_id=cluster_rid,
                     relation_settings={key: value})
    else:
        raise ValueError('Unable to detect '
                         'peer relation {}'.format(relation_name))
1112732
function toRooms(data) {
    var i, rooms;

    rooms = [];
    for (i = 0; i < data.rooms.length; i++) {
      rooms.push(new Room(connection, data.rooms[i]));
    }

    return rooms;
  }
73936
function(roomName, appRoomObj, callback) {
                // Join room. Creates a default connection room object
                e.app[appName].connection[easyrtcid].room[roomName] = {
                    apiField: {},
                    enteredOn: Date.now(),
                    gotListOn: Date.now(),
                    clientList: {},
                    toRoom: e.app[appName].room[roomName]
                };

                // Add easyrtcid to room clientList
                e.app[appName].room[roomName].clientList[easyrtcid] = {
                    enteredOn: Date.now(),
                    modifiedOn: Date.now(),
                    toConnection: e.app[appName].connection[easyrtcid]
                };

                // Returns connection room object to callback.
                connectionObj.room(roomName, callback);
            }
1106341
def invite(invite)
      code = resolve_invite_code(invite)
      Invite.new(JSON.parse(API::Invite.resolve(token, code)), self)
    end
189434
def listen_many(*rooms):
    """"""

    rooms = set(r.conn for r in rooms)
    for room in rooms:
        room.validate_listeners()
    with ARBITRATOR.condition:
        while any(r.connected for r in rooms):
            ARBITRATOR.condition.wait()
            rooms = [r for r in rooms if r.run_queues()]
            if not rooms:
                return
25551
def room(id, &callback)
      http(:get, "/room/#{id}.json") do |data, http|
        Firering::Room.instantiate(self, data, :room, &callback)
      end
    end
1194989
function(room) {
        this.rooms[room.roomId] = room;
        // add listeners for room member changes so we can keep the room member
        // map up-to-date.
        room.currentState.on("RoomState.members", this._onRoomMember.bind(this));
        // add existing members
        const self = this;
        room.currentState.getMembers().forEach(function(m) {
            self._onRoomMember(null, room.currentState, m);
        });
    }