Skip to content

fishjam-dev/elixir_server_sdk

Repository files navigation

Fishjam Elixir Server SDK

Hex.pm API Docs codecov CircleCI

Elixir server SDK for Fishjam. Currently it allows for:

  • making API calls to Fishjam server (QoL wrapper for HTTP requests)
  • listening to Fishjam server events via WebSocket

Installation

The package can be installed by adding fishjam_server_sdk to your list of dependencies in mix.exs:

def deps do
  [
    {:fishjam_server_sdk, "~> 0.6.0"}
  ]
end

Fishjam connection configuration

Define the connection configuration in the mix config, specifying server address and authentication token (for more information see Fishjam docs)

config :fishjam_server_sdk,
  server_address: "localhost:5002",
  server_api_token: "your-fishjam-token",
  secure?: true

Alternatively, the connection options can be provided when creating a Fishjam.Client or starting Fishjam.WSNotifier:

client =
    Fishjam.Client.new(server_address: "localhost:5002", server_api_token: "your-fishjam-token")

{:ok, notifier} =
    Fishjam.WSNotifier.start(
      server_address: "localhost:5002",
      server_api_token: "your-fishjam-token"
    )

Usage

Make API calls to Fishjam and receive server events:

# start process responsible for receiving events
{:ok, notifier} = Fishjam.WSNotifier.start()
:ok = Fishjam.WSNotifier.subscribe_server_notifications(notifier)

# create HTTP client instance
client = Fishjam.Client.new()

# Create room
{:ok, %Fishjam.Room{id: room_id}, fishjam_address} = Fishjam.Room.create(client, max_peers: 10)

room_id
# => "8878cd13-99a6-40d6-8d7e-8da23d803dab"

# Add peer
{:ok, %Fishjam.Peer{id: peer_id}, peer_token} =
    Fishjam.Room.add_peer(client, room_id, Fishjam.Peer.WebRTC)

receive do
  {:fishjam, %Fishjam.Notification.PeerConnected{room_id: ^room_id, peer_id: ^peer_id}} ->
    # handle the notification
end

# Delete peer
:ok = Fishjam.Room.delete_peer(client, room_id, peer_id)

List of structs representing events can be found in the docs.

Testing

When calling mix test it will automatically start the Fishjam container under the hood. Tests on CI are run with the use of docker-compose, to run it locally in the same way as on CI run mix integration_test.

Copyright and License

Copyright 2023, Software Mansion

Software Mansion

Licensed under the Apache License, Version 2.0