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
- Get Available Streams/Channels
- 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/ws/v4/squawk Address if using JWT wss://squawk.benzinga.com/ws/v4/webrtc Note: API Key support is deprecated and new integrations should use JWT.Authenticate
Using API keyapikey
), please get in touch with the Benzinga licensing team at licensing@benzinga.com. This is a one-time process. Save this API key securely.
Using JWT
Benzinga APIs support asymmetric JWT (JSON Web Token) for authentication.
To authenticate using JWT, send the token in query parameter when you open the WebSocket connection. Pseudo-code for connecting (and authenticating) would be as below:
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.
Get Available Streams/Channels
Fetch the list of available streams/channels in the roomallowedListening
and allowedBroadcasting
indicates if this user has listening and broadcasting rights to the channel.
Subscribe to Stream
Subscribe to a particular stream passing stream id.restart
flag is used to indicate if there needs a peer re-negotiation (ICE Restart) for a stream. This should be used in case of peer connection is failing for any reason (e.g. change in network). It is optional if you are creating a new peer connection. A successful response should have SDP offer for subscribed stream:
Start Stream
Now you have an SDP offer of the subscribed stream. So at this point, process the received SDP offer and send back SDP answer withstartStrea
request to start receiving and listening.
Send ICE Candidate
Typical request/message format to sendiceCandidate
from each stream’s peer:
complete
state (when ICE gathering completed), send the following request to notify same:
Stop Stream
If you want to stop listening and disconnect from all channels/streams, you can send logout request. But in case, if you want to stop listening to a specific stream/channel, you can sendstopStream
request.
subscribeToStream
on an existing peer connection fail event (meaning you are starting over again), then you must invoke stopStream
first to dispose of the existing peer connection before a fresh subscribeToStream
Notifications from server
Add a handler for the following message/notification types, which will be sent by squawk server.- mediaOverride
mediaOverride
notification 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
.
apiKey
. This is a one-time process. Save this API key securely.
Join Room
Once authenticated, 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. 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:
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- newPresenterArrived
- 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: