Step 3 — Authenticating with BS Collaborate

Now that we are connected to the BS Collaborate server we should authenticate the local user, so that we become visible to the other clients.

For this, as well as everytime you are programming for BS Collaborate, keep in mind that the script you are writing runs in multiple instances, one in each connected users computer. Therefore the script has to always play two roles:

To authenticate the local user we send some credentials to the tryLogin field of the BSCollaborate node. In the most obvious case this is username and password, but it can be anything else, e.g. a session Id that has already been established with a user management system like Drupal by the HTML page containing the x3D scene. There will be a module on the server that receives the credentials and uses them for authentication. You can write the module by yourself or customize one of the default modules.

In this tutorial we use just a Script node that sends "joe", "joe" as username/password pair to the server, which in the default configuration accepts everybody where username and password are the same.

In the console you can see that the BSCollaborate will output a node named "UserData", a session Id (32 bit number) and a TRUE as loginResult. The "UserData" node we will describe later. The session Id is an Id that is assigned to the local user. It is unique for the session, if a user logs in multiple times at the same time.

If you change the credentials to something different, e.g. "joe", "blabla", you'll see that no session Id is assigned to the local user and loginResult outputs FALSE.