Connecting to Squawk
There are two ways you can connect to Sqauwk: Notes for both WebRTC and RTP:- It is advised to add reconnect functionality for WebSocket. It is useful, in case socket connection drops for any reason (maybe the internet is down for a couple of minutes). So add a functionality to try reconnection at some regular interval after WebScoket gets disconnected.
-
The ID field (id) in each request/message is a unique
UUID
string used to coordinate messages between client and server over WebSocket. -
Each response to a message sent from the client will have
Response
appended at the end of the message’s type sent. For e.g. a message with typejoinRoom
will receive a response with typejoinRoomResponse
- Following is the format of the generic error response. In event of any error to a sent request, you will get the following response:
Using WebRTC
Squawk is built on top of WebRTC. So one can connect to it through WebRTC supported browser using standard WebRTC API methods. The following are the methods that you will need to implement while writing a client for connecting to squawk.- Create a socket connection
- Authenticate
- Join Room
- Create peer connections
- Send ICE Candidate to peers
- Message Types
- Ping/Pong mechanism to keep alive the Web Socket
- Logout
Create a socket connection
First, create a web socket connection to squawk. The Benzinga Squawk WebRTC service WebSocket address is: Address if using API key wss://squawk.benzinga.com/squawk Address if using JWT wss://squawk.benzinga.com/webrtcAuthenticate
There are couple of ways to authenticate: Using API key Once the socket connection is created, authenticate with yourapikey
.
sub
of JWT, to identify each user.
Please refer to https://github.com/Benzinga/jwt for more information on Benzinga JWT token. For JWT, you will need to share the hosting location/endpoint of your public key to Benzinga from where our authenticator service would be able to download the public key using key ID. At the moment this is a manual one time process.
On successful authentication and connection, you should get the following response:
Join Room
Once you have received theiceServers
details, authentication is done. Next, send the join room request/message. The room name for benzinga broadcasts is PRO
. Sample join room request format:
existingPresenters
represents active broadcasters at the moment.
Create peer connections
Add all theexistingPresenters
received in joinRoom
’s response as participants in the room and create a peer connection with each of the presenters to start listening to them. To create a peer connection, send the SDP offer for each participant/presenter through receiveMedia
request. Please note that the SDP offer should only contain audio attributes (no video attributes) and it should be a receive-only (a=recvonly
). Meaning you won’t be able to send anything and will receive audio-only from squawk.
Sample receiveMedia
(SDP offer) for peer connection will look like as below:
userid
is the one from existingPresenters
. On successful negotiation, you should get following SDP answer with the same id:
Send ICE Candidate to peers
Typical request/message format to sendiceCandidate
from each participant’s peer:
- newPresenterArrived
newPresenterArrived
message will be as follow:
userId
, you can map the iceCandidate
to the existing broadcaster/participant.
- presenterLeft
userId
in the message. Typical presenterLeft
message will be received in below format:
- mediaOverride
mediaOverride
message will be in the following format:
Ping/Pong mechanism to keep alive the Web Socket
Implement the regular intervalping
messages to keep the Web Socket connection alive. Every 25-30 seconds should be good enough. Ping request format:
id
:
Logout
Send the logout message when you want to stop listening or your container application’s session ends. The logout request/message should be:Using RTP
Squawk also supports RTP streaming, which can be useful if you are looking to re-broadcast from your media server or for any other RTP specific purpose. One can connect to squawk RTP by implementing the following mechanism.- Create a socket connection
- Authenticate
- SDP negotiation
- Logout
- Media Override Notification
- Ping/Pong mechanism
rtp-receiver
example. 5 open ports are more than enough.
Create a socket connection
Similar to WebRTC, for RTP also, the authentication, joining room, SDP negotiation, and other message exchange happens over WebSocket. So first connect to WebSocket. The Benzinga Squawk RTP service WebSocket address is:Authenticate
At the moment squawk supports only API key authentication for RTP. Using API key Once the socket connection is created, authenticate with yourapikey
.
PRO
. Sample join room request format:
existingPresenters
represents active broadcasters at the moment. So if there are any existing broadcasters, you should start SDP negotiation with each broadcaster to receive the audio stream.
SDP negotiation
Negotiate the SDP offer with each broadcaster usinguserId
received in a presenter object. Sample format as shown below:
8449
. Also when broadcaster left and the streaming session ends, you should return the used IP back to pool fr next time use.
On successful negotiation you should get below response:
sdpAnswer
can be useful if you are aiming to re-broadcast the stream via WebRTC through any media server on your end. If not then simply ignore that. At this point, after successful SDP negotiation, you should start receiving RTP audio stream from Squawk.
Logout
Send the logout message when you want to stop receiving RTP stream- presenterLeft
presenterLeft
message will be received in below format:
mediaOverride
This is the notification that will be sent from Squawk to WebSocket client in a case where you logged in from another session (somewhere else) using the same API key.Ping/Pong mechanism
Similar to WebRTC socket, implement the regular intervalping
messages to keep the Web Socket connection alive. Every 25-30 seconds should be good enough. Ping request format: