Module: Server C++ SDK

The SDK interface is the entry point for the CoreSDK API.

Attention: The SDK interface contains methods that return async_result. Each function that returns async_result is asynchronous and executes operations on the SDK event loop. The caller can block the calling thread until the operation completes and can use the wait helper. The caller can also chain consecutive operations which depend on the completion of this method using async_result::then calls. When you create an async_result chain, terminate it using async_result::on_error.

#include <sdk.h>

Public Functions

Name
virtual~sdk()
The destructor that shuts down the SDK.
voidset_log_level(log_level level)
Sets the logging level.
virtual services::session &session() =0
The Session Service accessor.
std::unique_ptr< sdk >create(const std::string & access_token, std::function< void(std::unique_ptr< refresh_token >)> && refresh_token_callback)
Creates an instance of the SDK. This method is synchronous and is available when the SDK is created and initialized. Otherwise, SDK triggers errors and exceptions.
virtual services::conference &conference() =0
The Conference Service accessor.
virtual async_result< event_handler_id >add_event_handler(event_handler< signaling_channel_exception > && callback) =0
Adds a listener for the signaling_channel_exception events.
virtual async_result< event_handler_id >add_event_handler(event_handler< invalid_token_exception > && callback) =0
Adds a listener for the invalid_token_exception events.
class dolbyio::comms::sdk;

Public Functions Documentation

function ~sdk

virtual ~sdk()

The destructor that shuts down the SDK.

function set_log_level

static void set_log_level(
    log_level level
)

Sets the logging level.

Parameters:

  • level The log level to set.
dolbyio::comms::sdk::set_log_level(dolbyio::comms::log_level::INFO);

function session

virtual services::session & session() =0

The Session Service accessor.

Return: Reference to the services::session service.

auto session_service = sdk->session();

function create

static std::unique_ptr< sdk > create(
    const std::string & access_token,
    std::function< void(std::unique_ptr< refresh_token >)> && refresh_token_callback
)

Creates an instance of the SDK. This method is synchronous and is available when the SDK is created and initialized. Otherwise, SDK triggers errors and exceptions.

Parameters:

  • access_token The access token that is required to send requests to the Dolby.io backed. The token needs to be fetched externally and provided in the create call.
  • refresh_token_callback The function object that is called to refresh the access token. It fetches a new and valid access token and passes the token to the SDK. To do it, the function object is passed as a pointer to the SDK's refresh_token callable, callable, which needs to be invoked with the newly acquired access token. This callback is invoked twice before the access token expiration.

Exceptions:

Return: The unique pointer to the initialized SDK object.

Attention: The SDK invokes refresh_token_callback on the SDKs event loop thread. Since fetching a token requires a network request, we recommend not blocking the SDK thread. You can use the async_result and solver APIs to create an asynchronous method and chain the SDK refresh_token callback invocation when the token is fetched.

std::unique_ptr<sdk> sdk =
 dolbyio::comms::sdk::create(
   access_token,
   [](std::function<void(std::unique_ptr<dolbyio::comms::refresh_token>)>&& cb) {
     std::shared_ptr<refresh_token> shared_cb = std::move(cb);
     users_fetch_token_method().then([cb{std::move(shared_cb)}](auto&&token)
     {
       (*cb)(std::move(token));
     });
  });

function conference

virtual services::conference & conference() =0

The Conference Service accessor.

Return: The reference to the services::conference service.

auto conference_service = sdk->conference();

function add_event_handler

virtual async_result< event_handler_id > add_event_handler(
    event_handler< signaling_channel_exception > && callback
) =0

Adds a listener for the signaling_channel_exception events.

Parameters:

  • callback The function object that will be invoked when the WebSocket responsible for signaling detects a failure.

Return: The result object producing the event_handler_id asynchronously.

// The method invokes via wait blocks until it succeeds or fails
handlers.push_back(wait(sdk->add_event_handler(
    [](const dolbyio::comms::signalling_channel_exception& e) {
    // process the event
})));

// Changes the successive operations via the `then` call
sdk->add_event_handler(
  [](const dolbyio::comms::signalling_channel_exception& e) {
    // process the event
  })
  .then([this](event_handler_id&& handler) {
    this->handlers.push_back(std::move(handler);
  })
  .on_error([](auto&& e) {
    // handle exception
  });

function add_event_handler

virtual async_result< event_handler_id > add_event_handler(
    event_handler< invalid_token_exception > && callback
) =0

Adds a listener for the invalid_token_exception events.

Parameters:

  • callback The function object that will be invoked in the case of using an invalid token.

Return: The result object producing the event_handler_id asynchronously.

// The method invokes via wait blocks until it succeeds or fails
handlers.push_back(wait(sdk->add_event_handler(
  [](const dolbyio::comms::invalid_token_exception& e) {
    // process the event
  })));

// Changes the successive operations via the `then` call
sdk->add_event_handler(
  [](const dolbyio::comms::invalid_token_exception& e) {
    // process the event
  })
  .then([this](event_handler_id&& handler) {
    this->handlers.push_back(std::move(handler);
  })
  .on_error([](auto&& e) {
    // handle exception
  });


Did this page help you?