Skip to main content
Version: 0.6.3

Notifications

Fishjam sends server side notifications whenever some important event occurs, e.g.:

  • a room has been created
  • some peer has connected
  • component has crashed
  • etc.

A full list of available notifications is always present in specific server SDK documentation. Notifications can be received through WebSockets or Webhooks.

WebSockets

WebSocket (WS) is a communication protocol that provides full-duplex communication between a client and a server over a persistent connection. When you create a notifier, it will open WS connection, receive notifications, decode and return them to you via callbacks or messages. In other words, you don't have to do anything on your own.

from fishjam import Notifier

server_address = "localhost:5002"
server_api_token = "development"

notifier = Notifier(server_address = server_address, server_api_token = server_api_token)

@notifier.on_server_notification
def handle_notification(server_notification):
print(f'Received a notification: {server_notification}')

@notifier.on_metrics
def handle_metrics(metrics_report):
print(f'Received WebRTC metrics: {metrics_report}')

async def run():
await notifier.connect()
await notifier.wait_ready()

asyncio.run(run())

As a result, you should see the following logs on the server side

07:45:02.684 [info] New incoming server WebSocket connection, accepting
07:45:02.688 [info] Server WS authenticated.

Webhooks

Webhooks are simply HTTP POST requests sent to a specified URL. They are a common choice in serverless architectures where a WebSocket connection cannot be established.

The most important difference between Webhook and WebSocket notifications is that you have to receive those POST requests on your own and then use SDK's decode functions to get the actual notification.

To receive server notifications through webhooks you have to pass webhook_url during room creation.

from fishjam import Notifier, RoomApi
from fishjam import recevie_binary

server_address = "localhost:5002"
server_api_token = "development"
webhook_url = "http://localhost:5003/webhook"

room_api = RoomApi(server_address = server_address, server_api_token = server_api_token)
_, room = room_api.create_room(webhook_url=webhook_url)

# assuming you are using Flask
@app.route("/webhook", methods=["POST"])
def respond_root():
data = request.get_data()
notification = receive_binary(data)

return Response(status=200)