Set up your server
Install the SDK
Install the SDK for the language of your choice. We provide libraries for Node and Python.
It's also possible to use the bare REST API, in this case you can skip this step.
- NPM
- YARN
- PIP
- POETRY
npm install @fishjam-cloud/js-server-sdk
yarn add @fishjam-cloud/js-server-sdk
pip install fishjam-server-sdk
poetry add fishjam-server-sdk
Setup your client
Let's setup everything you need to start communicating with a Fishjam instance.
First of all, view your app in the Fishjam developer panel and copy your Fishjam URL and the Management Token.
They are required to proceed. Now, we are ready to dive into the code.
- Typescript
- Python
import {
FishjamClient } from '@fishjam-cloud/js-server-sdk'; constfishjamUrl =process .env .FISHJAM_URL ; constmanagementToken =process .env .FISHJAM_MANAGEMENT_TOKEN ; constfishjamClient = newFishjamClient ({fishjamUrl ,managementToken });
import os from fishjam import FishjamClient fishjam_url = os.environ["FISHJAM_URL"] management_token = os.environ["FISHJAM_MANAGEMENT_TOKEN"] fishjam_client = FishjamClient(fishjam_url, management_token)
Managing rooms
Create a room to get the roomId
and be able to start adding peers.
- Typescript
- Python
const
createdRoom = awaitfishjamClient .createRoom (); consttheSameRoom = awaitfishjamClient .getRoom (createdRoom .id ); awaitfishjamClient .deleteRoom (theSameRoom .id ) // puff, it's gone!
created_room = fishjam_client.create_room() the_same_room = fishjam_client.get_room(created_room.id) fishjam_client.delete_room(the_same_room.id) # puff, it's gone!
Managing peers
Create a peer to obtain the peer token allowing your user to join the room. At any time you can terminate user's access by deleting the peer.
- Typescript
- Python
const {
peer ,peerToken } = awaitfishjamClient .createPeer (created_room .id ); awaitfishjamClient .deletePeer (created_room .id ,peer .id );
peer, token = fishjam_client.create_peer(room_id) fishjam_client.delete_peer(room_id, peer.id)
Metadata
When creating a peer, you can also assign metadata to that peer, which can be read later with the mobile SDK or web SDK. This metadata can be only set when creating the peer and can't be updated later.
- Typescript
- Python
const {
peer ,peerToken } = awaitfishjamClient .createPeer (created_room .id , {metadata : {realName : 'Tom Reeves' }, });
options = PeerOptions( metadata={"realName": "Tom Reeves"}, ) peer, token = self.fishjam_client.create_peer(room_id, options=options)
Listening to events
Fishjam instance is a stateful server that is emitting messages upon certain events.
You can listen for those messages and react as you prefer.
There are two options to obtain these.
Webhooks
Simply pass the your webhook url as a webhookUrl
parameter when creating a room.
- Typescript
- Python
const
webhookUrl = "https://example.com/"; awaitfishjamClient .createRoom ({webhookUrl });
from fishjam import RoomOptions options = RoomOptions(webhook_url="https://example.com/") fishjam_client.create_room(options)
SDK Notifier
Our SDKs come equipped with a Notifier allowing you to subscribe for messages. It sets up a websocket connection with a Fishjam instance and provides a simple interface allowing you to handle messages.
- Typescript
- Python
import {
FishjamWSNotifier } from '@fishjam-cloud/js-server-sdk'; constonClose =console .log ; constonError =console .error ; constonConnectionFailed =console .error ; constfishjamNotifier = newFishjamWSNotifier ({fishjamUrl ,managementToken },onError ,onClose ,onConnectionFailed );fishjamNotifier .on ('roomCreated',console .log );
import asyncio from fishjam import FishjamNotifier notifier = FishjamNotifier(server_address=fishjam_url, server_api_token=management_token) @notifier.on_server_notification def handle_notification(notification): match notification: case ServerMessageRoomCreated(): print(notification) case _: ... async def run_notifier(): notifier_task = asyncio.create_task(notifier.connect()) # Wait for notifier to be ready to receive messages await notifier.wait_ready() await notifier_task asyncio.run(run_notifier())