|
7 | 7 | */
|
8 | 8 | package com.opentok;
|
9 | 9 | import com.fasterxml.jackson.core.JsonProcessingException;
|
| 10 | +import com.fasterxml.jackson.databind.JsonNode; |
10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper;
|
11 | 12 | import com.fasterxml.jackson.databind.ObjectReader;
|
12 | 13 | import com.opentok.exception.InvalidArgumentException;
|
@@ -39,20 +40,17 @@ public class OpenTok {
|
39 | 40 | private int apiKey;
|
40 | 41 | private String apiSecret;
|
41 | 42 | protected HttpClient client;
|
42 |
| - static protected ObjectReader archiveReader = new ObjectMapper() |
43 |
| - .readerFor(Archive.class); |
44 |
| - static protected ObjectReader archiveListReader = new ObjectMapper() |
45 |
| - .readerFor(ArchiveList.class); |
46 |
| - static protected ObjectReader createdSessionReader = new ObjectMapper() |
47 |
| - .readerFor(CreatedSession[].class); |
48 |
| - static protected ObjectReader streamReader = new ObjectMapper() |
49 |
| - .readerFor(Stream.class); |
50 |
| - static protected ObjectReader streamListReader = new ObjectMapper() |
51 |
| - .readerFor(StreamList.class); |
52 |
| - static protected ObjectReader sipReader = new ObjectMapper() |
53 |
| - .readerFor(Sip.class); |
54 |
| - static protected ObjectReader broadcastReader = new ObjectMapper() |
55 |
| - .readerFor(Broadcast.class); |
| 43 | + protected static final ObjectReader |
| 44 | + archiveReader = new ObjectMapper().readerFor(Archive.class), |
| 45 | + archiveListReader = new ObjectMapper().readerFor(ArchiveList.class), |
| 46 | + createdSessionReader = new ObjectMapper().readerFor(CreatedSession[].class), |
| 47 | + streamReader = new ObjectMapper().readerFor(Stream.class), |
| 48 | + streamListReader = new ObjectMapper().readerFor(StreamList.class), |
| 49 | + sipReader = new ObjectMapper().readerFor(Sip.class), |
| 50 | + broadcastReader = new ObjectMapper().readerFor(Broadcast.class), |
| 51 | + renderReader = new ObjectMapper().readerFor(Render.class), |
| 52 | + renderListReader = new ObjectMapper().readerForListOf(Render.class); |
| 53 | + |
56 | 54 | static final String defaultApiUrl = "https://api.opentok.com";
|
57 | 55 |
|
58 | 56 | /**
|
@@ -545,7 +543,7 @@ public void setArchiveLayout(String archiveId, ArchiveProperties properties) thr
|
545 | 543 | }
|
546 | 544 |
|
547 | 545 | /**
|
548 |
| - * Use this method to start a live streaming for an OpenTok session. |
| 546 | + * Starts a live streaming broadcast for an OpenTok session. |
549 | 547 | * This broadcasts the session to an HLS (HTTP live streaming) or to RTMP streams.
|
550 | 548 | * <p>
|
551 | 549 | * To successfully start broadcasting a session, at least one client must be connected to the session.
|
@@ -581,7 +579,7 @@ public Broadcast startBroadcast(String sessionId, BroadcastProperties properties
|
581 | 579 | }
|
582 | 580 |
|
583 | 581 | /**
|
584 |
| - * Use this method to stop a live broadcast of an OpenTok session. |
| 582 | + * Stops a live streaming broadcast of an OpenTok session. |
585 | 583 | * Note that broadcasts automatically stop 120 minutes after they are started.
|
586 | 584 | * <p>
|
587 | 585 | * For more information on broadcasting, see the
|
@@ -819,10 +817,10 @@ public StreamList listStreams(String sessionId) throws OpenTokException {
|
819 | 817 | * such as phone numbers. (The OpenTok client libraries include properties for inspecting
|
820 | 818 | * the connection data for a client connected to a session.) See the
|
821 | 819 | * <a href="https://tokbox.com/developer/guides/signaling/">Token Creation developer guide</a>.
|
822 |
| -. * |
| 820 | + * |
823 | 821 | * @param properties The {@link SipProperties} object defining options for the SIP call.
|
824 | 822 | *
|
825 |
| - * @return The {@link Sip} object. |
| 823 | + * @return The {@link Sip} object. |
826 | 824 | */
|
827 | 825 | public Sip dial(String sessionId, String token, SipProperties properties) throws OpenTokException {
|
828 | 826 | if ((StringUtils.isEmpty(sessionId) || StringUtils.isEmpty(token) || properties == null || StringUtils.isEmpty(properties.sipUri()))) {
|
@@ -863,6 +861,100 @@ public void playDTMF(String sessionId, String connectionId, String dtmfDigits) t
|
863 | 861 | client.playDtmfSingle(sessionId, connectionId, dtmfDigits);
|
864 | 862 | }
|
865 | 863 |
|
| 864 | + /** |
| 865 | + * Starts an Experience Composer render for an OpenTok session. For more information, see the |
| 866 | + * <a href="https://tokbox.com/developer/guides/experience-composer">Experience Composer developer guide</a>. |
| 867 | + * |
| 868 | + * @param sessionId The session ID. |
| 869 | + * @param properties The {@link RenderProperties} object defining the properties for the Render call. |
| 870 | + * |
| 871 | + * @return The {@link Render} response object. |
| 872 | + * |
| 873 | + * @throws OpenTokException |
| 874 | + */ |
| 875 | + public Render startRender(String sessionId, String token, RenderProperties properties) throws OpenTokException { |
| 876 | + if (StringUtils.isEmpty(sessionId) || StringUtils.isEmpty(token) || properties == null) { |
| 877 | + throw new InvalidArgumentException("Session id, token and properties are all required."); |
| 878 | + } |
| 879 | + String render = client.startRender(sessionId, token, properties); |
| 880 | + try { |
| 881 | + return renderReader.readValue(render); |
| 882 | + } catch (JsonProcessingException e) { |
| 883 | + throw new RequestException("Exception mapping json: " + e.getMessage()); |
| 884 | + } |
| 885 | + } |
| 886 | + |
| 887 | + /** |
| 888 | + * Gets a Render object, with details on an Experience Composer. |
| 889 | + * |
| 890 | + * @param renderId The ID of the Experience Composer to retrieve. |
| 891 | + * |
| 892 | + * @return The {@link Render} response object associated with the provided ID. |
| 893 | + * |
| 894 | + * @throws OpenTokException |
| 895 | + */ |
| 896 | + public Render getRender(String renderId) throws OpenTokException { |
| 897 | + if (StringUtils.isEmpty(renderId)) { |
| 898 | + throw new InvalidArgumentException("Render id is required."); |
| 899 | + } |
| 900 | + String render = client.getRender(renderId); |
| 901 | + try { |
| 902 | + return renderReader.readValue(render); |
| 903 | + } catch (JsonProcessingException e) { |
| 904 | + throw new RequestException("Exception mapping json: " + e.getMessage()); |
| 905 | + } |
| 906 | + } |
| 907 | + |
| 908 | + /** |
| 909 | + * Stops an Experience Composer of an OpenTok session. Note that by default |
| 910 | + * Experience Composers automatically stop 2 hours after they are started. You can also set a different |
| 911 | + * maxDuration value when you create the Experience Composer. When the Experience Composer ends, an event is |
| 912 | + * posted to the callback URL, if you have configured one for the project. |
| 913 | + * |
| 914 | + * @param renderId The ID of the Experience Composer to stop. |
| 915 | + * |
| 916 | + * @throws OpenTokException |
| 917 | + */ |
| 918 | + public void stopRender(String renderId) throws OpenTokException { |
| 919 | + if (StringUtils.isEmpty(renderId)) { |
| 920 | + throw new InvalidArgumentException("Render id is required."); |
| 921 | + } |
| 922 | + client.stopRender(renderId); |
| 923 | + } |
| 924 | + |
| 925 | + /** |
| 926 | + * Gets a list of Render objects, representing Experience Composers associated with the |
| 927 | + * OpenTok project. |
| 928 | + * |
| 929 | + * @return The list of {@link Render} objects. |
| 930 | + * |
| 931 | + * @throws OpenTokException |
| 932 | + */ |
| 933 | + public List<Render> listRenders() throws OpenTokException { |
| 934 | + return listRenders(null, null); |
| 935 | + } |
| 936 | + |
| 937 | + /** |
| 938 | + * Gets a list of Render objects, representing a list of Experience Composers associated |
| 939 | + * with the OpenTok project. |
| 940 | + * |
| 941 | + * @param offset (optional) Start offset in the list of existing Renders. |
| 942 | + * @param count (optional) Number of Renders to retrieve starting at offset. Maximum 1000. |
| 943 | + * |
| 944 | + * @return The list of {@link Render} objects. |
| 945 | + * |
| 946 | + * @throws OpenTokException |
| 947 | + */ |
| 948 | + public List<Render> listRenders(Integer offset, Integer count) throws OpenTokException { |
| 949 | + String response = client.listRenders(offset, count); |
| 950 | + try { |
| 951 | + JsonNode root = new ObjectMapper().readTree(response); |
| 952 | + return renderListReader.readValue(root.get("items")); |
| 953 | + } catch (IOException e) { |
| 954 | + throw new RequestException("Exception mapping json: " + e.getMessage()); |
| 955 | + } |
| 956 | + } |
| 957 | + |
866 | 958 | /**
|
867 | 959 | * Used to create an OpenTok object with advanced settings. You can set
|
868 | 960 | * the request timeout for API calls and a proxy to use for API calls.
|
|
0 commit comments