Squawk v3
Squawk is a realtime broadcast which includes important headlines, price movement and rumors as stories develop to give traders and investors news in the fastest and most convenient form.”
Notes: The squawk v3 version will be deprecated in near future. So it is suggested you use the v4 version if you are working on a new integration. Also, migrate your existing v3 integration to v4. Refer to Squawk v4 API documentation for more details.
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:
As stated earlier, the type indicates the response to the message earlier sent.
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/webrtc
Authenticate
There are couple of ways to authenticate:
Using API key
Once the socket connection is created, authenticate with your apikey
.
Note: If you do not yet have an API key (apikey), please get in touch with the Benzinga licensing team. 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:
With JWT there is no need to send a separate auth message as the token includes all of the relevant properties. Make sure to send a unique uuid in 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:
The ice server details will be needed to share/obtain ICE candidates.
Join Room
Once you have received the iceServers
details, authentication is done. Next, send the join room request/message. The room name for benzinga broadcasts is PRO
. Sample join room request format:
If the join room is successful, you should just get the same message id in response and no error. On success, you should create a room on client side.
existingPresenters
represents active broadcasters at the moment.
Create peer connections
Add all the existingPresenters
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:
Process the received SDP answer with peer connection. If any error is received, reject the connection.
If you want to know more about SDP negotiation and format, please refer a good blog at https://www.kurento.org/blog/rtp-i-intro-rtp-and-sdp#sdp
Send ICE Candidate to peers
Typical request/message format to send iceCandidate
from each participant’s peer:
Response:
Notifications from server
Add a handler for the following message/notification types, which will be sent by squawk server.
- newPresenterArrived
Indicates the new presenter/broadcaster has joined. Add new presenter creating a new peer connection. typical newPresenterArrived
message will be as follow:
Upon receiving this notification, create a new participant and follow the create a peer and share ICE candidates to start receiving audio.
From userId
, you can map the iceCandidate
to the existing broadcaster/participant.
- presenterLeft
Upon receiving this notification, close the peer connection and remove the broadcaster/participant from room identifying received userId
in the message. Typical presenterLeft
message will be received in below format:
- mediaOverride
Meaning this user has started playing from another session (could be logged in from another browser/client). So discard all peer connections and disconnect from this session. The mediaOverride
message will be in the following format:
Ping/Pong mechanism to keep alive the Web Socket
Implement the regular interval ping
messages to keep the Web Socket connection alive. Every 25-30 seconds should be good enough. Ping request format:
In response, you should just get the same 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
For RTP receiver sample implementation, you can refer https://github.com/Benzinga/benzinga-squawk-client. There are chances that more than one broadcaster active at the same time. In such a case, there will be multiple streams from each broadcaster. So keep around 5 ports open for incoming RTP streams and configure them as shown in 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 your apikey
.
Response:
Note: Please get in touch with the Benzinga licensing team for acquiring 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:
If the join room is successful, you should just get the same message id in response and no error. On success, you should create a room on client side.
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 using userId
received in a presenter object. Sample format as shown below:
Some references for SDP: Quick overview of SDP fields RTP and SDP
Sample SDP offer:
Please note that to receive RTP stream on your end you must have a publicly accessible IP:Port. As stated earlier, you should create a pool of 4-5 open ports and use them while you generate SDP offer for a broadcaster. For e.g. in the above SDP offer, the port is 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
Upon receiving this notification, start SDP negotiation to receive RTP stream from this broadcaster.
- presenterLeft
Indicates that the presenter/broadcaster has left and streaming stopped. So should cutoff the RTP stream on receiving this notification and return the associated port to free pool for using on next incoming stream. Typical 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.
Probably, you should close the socket connection in the current session on receiving the media override notification.
Ping/Pong mechanism
Similar to WebRTC socket, implement the regular interval ping
messages to keep the Web Socket connection alive. Every 25-30 seconds should be good enough. Ping request format:
In case if you are using a WebSocket library, it may already have this mechanism and in such a case, you don’t need to add the ping message sending functionality.
Was this page helpful?