# In

Join a room.

Parameters:

  | newRoom,: | the name (String) or the id (int) of the room to join.
  | pword,: | the room's password, if it's a private room (optional).
  | isSpectator,: | a boolean flag indicating wheter you join as a spectator or not (optional).
  | dontLeave,: | a boolean flag indicating if the current room must be left after successfully joining the new room (optional).
  | oldRoom,: | the id of the room to leave (optional, default value: activeRoomId). NOTE: the last two optional parameters enable the advanced multi-room join feature of SmartFoxServer, which allows a user to join two or more rooms at the same time. If this feature is not required, the parameters can be omitted.

SFSEvent::onJoinRoom SFSEvent::onJoinRoomError

the following example the user requests to join a room with id = 10; by default SmartFoxServer will disconnect him from the previous room. `smartFox.joinRoom(10)`

In the following example the user requests to join a room with id = 12 and password = "mypassword"; by default SmartFoxServer will disconnect him from the previous room. `smartFox.joinRoom(12, "mypassword")`

In the following example the user requests to join the room with id = 15 and passes true to the dontLeave flag; this will join the user in the new room while keeping him in the old room as well. `smartFox.joinRoom(15, "", false, true)`

See also:
  SFSEvent::onJoinRoom

  SFSEvent::onJoinRoomError

Version:
  SmartFoxServer Basic / Pro