Step 4 — Managing user sessions

This step contains the same VRLM file as the previous, but in three versions that differ only in the nickname they use for logging in. This way you can verify the messages in the console the BSCollaborate node sends whenever a new user joins the scene or one leaves it.

Whenever a client joins the scene, itself receives messages about its own attributes, the fact that login has been accepted and about other users already in the scene. Other clients will receive a message that informs them about the arrival of the new user.

Similarly, when a client leaves the scene, an event about it is sent to all other clients, and the leaving client - if still running - receives event about its own disconnection.

Information about every user is collected in a node of type UserData. This allows the BSCollaborate node to send out a single event with anSFNode reference to such a UserData node when a user sends a chat message, changes position or similar, and the receiving function has all info about the respecitive user at hand. In order to allow a script to easily iterate over all logged-in users, the BSCollaborate node contains an MFNode field named 'users', which contains the UserData nodes of all logged in users.

    field      SFInt32       idx
    field      SFInt32       sessionId
    field      SFString      nickname
    field      SFString      avatarString
    eventOut   SFString      loginState
    eventOut   SFVec3f       position
    eventOut   SFRotation    orientation
    eventOut   SFBool        isMoving
    eventOut   MFString      chat
    field      SFNode        userData

Here idx is the index of the entry in the BSCollaborate.users field of type MFNode, sessionId is a unique id for the client - if a user logs in multiple times with the same nick name you can still distinuish between instances using the session Id. A session Id is valid as long as the corresponding client is logged in. The field nickname indicates the nick name of the user. avatarString is a hint which avatar should be used to represent the user. It is up to the content how to interpret this string, i.e. how to build a URL from it.