Quickstart#

This quickstart guide will show you how to use the hubsclient library to interact with a Hubs room. This guide can be run as a Jupyter notebook. You can download the notebook from the GitHub repository here or you can run it in Google Colab by clicking the badge below:

Open In Colab

Setup#

If you haven’t installed the library yet, you can do so directly from GitHub with pip:

%pip install git+https://github.com/simvia/hubsclient.git

Joining a room#

To join a room, you need to know the room’s url. If you haven’t already, create a new room on the public Hubs instance at https://hubs.mozilla.com/demo. Once you have created a room, your URL will look something like this: https://hubs.mozilla.com/waycoA2/obedient-best-get-together. The room id is the part immediately after the domain name, in this case waycoA2.

In addition to the room id, you will need information about your avatar, such as the name you want to use and the id of the avatar model. We’ll explain how to get this information in a later section, but for now, let’s use the base bot avatar. This avatar has the id basebot. We can set our display name to something like Python User.

Now that we have our room id and our avatar info, we can instantiate a client and join the room:

from hubsclient import HubsClient

client = HubsClient(
    host="hubs.mozilla.com",
    room_id="waycoA2",
    avatar_id="basebot",
    display_name="Python User",
)

The client will automatically join the room and start listening for events.

Moving around#

Now that we have joined the room, we can move around by setting the position and rotation attributes of the client.

Let’s advance the client’s position on the x-axis by 1 meter:

client.avatar.position.x += 1

We can also rotate the client by 90 degrees:

client.avatar.rotation.y = 90

In order to see the changes, we need to send the new position and rotation to the server by calling the sync method:

client.sync()

More avatar features#

The client has a number of other attributes that can be used to control the avatar. For example, we adjust the position and rotation of the avatar’s head:

client.avatar.head_transform.position.y -= 0.1
client.avatar.head_transform.rotation.x = 20
client.sync()

We can also manipulate the avatar’s hands:

Lets make the left hand visible and move it to the left of the avatar’s head:

client.avatar.lefthand.visible = True
client.avatar.lefthand.position.x = -0.5
client.sync()

Now, we can make it show a thumbs up:

from hubsclient.avatar import HandPose

client.avatar.lefthand.pose = HandPose.thumbsUp
client.sync()

Sending messages#

We can send messages to other users in the room by calling the send_chat method:

client.send_chat("Hello everyone!")

Leaving the room#

When you are done, you can leave the room by calling the close method:

client.close()

Going further#

Read the API docs for more information about the library’s features.