Skip to content

Commit

Permalink
Add web socket support to rest api (#650)
Browse files Browse the repository at this point in the history
* Add websocket url serializing to rest api

* Fix style issues

* Fix style issues
  • Loading branch information
lluczo authored and bgrozev committed Apr 23, 2018
1 parent 6043598 commit f6bc6f7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/java/org/jitsi/videobridge/rest/JSONSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ final class JSONSerializer
static final String RTP_HEADER_EXTS
= RTPHdrExtPacketExtension.ELEMENT_NAME + "s";

/**
* The name of the JSON pair which specifies the value of the
* <tt>webSockets</tt> property of <tt>WebSocketPacketExtension</tt>.
*/
static final String WEBSOCKET_LIST
= WebSocketPacketExtension.ELEMENT_NAME + "s";

/**
* The name of the JSON pair which specifies the value of the
* <tt>namespace</tt> property of <tt>IceUdpTransportPacketExtension</tt>.
Expand Down Expand Up @@ -979,6 +986,9 @@ public static JSONObject serializeTransport(
DtlsFingerprintPacketExtension.class);
List<CandidatePacketExtension> candidateList
= transport.getCandidateList();
List<WebSocketPacketExtension> webSocketList
= transport.getChildExtensionsOfType(
WebSocketPacketExtension.class);
RemoteCandidatePacketExtension remoteCandidate
= transport.getRemoteCandidate();
boolean rtcpMux = transport.isRtcpMux();
Expand Down Expand Up @@ -1010,6 +1020,12 @@ public static JSONObject serializeTransport(
remoteCandidate.getElementName(),
serializeCandidate(remoteCandidate));
}
if ( (webSocketList != null) && (!webSocketList.isEmpty()) )
{
jsonObject.put(
WEBSOCKET_LIST,
serializeWebSockets(webSocketList));
}
// rtcpMux
if (rtcpMux)
{
Expand All @@ -1021,6 +1037,30 @@ public static JSONObject serializeTransport(
return jsonObject;
}

private static String serializeWebSocket(
WebSocketPacketExtension webSocket)
{
return webSocket.getUrl();
}

private static JSONArray serializeWebSockets(
List<WebSocketPacketExtension> webSocketList)
{
JSONArray webSocketsJSONArray;

if (webSocketList == null)
{
webSocketsJSONArray = null;
}
else
{
webSocketsJSONArray = new JSONArray();
for (WebSocketPacketExtension webSocket : webSocketList)
webSocketsJSONArray.add(serializeWebSocket(webSocket));
}
return webSocketsJSONArray;
}

/** Prevents the initialization of new <tt>JSONSerializer</tt> instances. */
private JSONSerializer()
{
Expand Down

0 comments on commit f6bc6f7

Please sign in to comment.