Skip to content

Commit b047da6

Browse files
authored
feat: Add Video API snippets (#121)
1 parent 6b8dc4e commit b047da6

26 files changed

+823
-4
lines changed

.env-example

+9-1
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,19 @@ VERIFY_TEMPLATE_NAME="verify"
144144
VERIFY_TEMPLATE_ID="bcdef09-8765-4321-8cde-0123456789ab"
145145
VERIFY_TEMPLATE_FRAGMENT_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
146146

147+
# Video
148+
VIDEO_SESSION_ID="flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN"
149+
VIDEO_TOKEN="eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhcHBsaWNhdGlvbl9pZCI6ImFhYWFhYWFhLWJiYmItNGNjYy04ZGRkLTAxMjM0NTY3ODlhYiJ9.o3U506EejsS8D5Tob90FG1NC1cR69fh3pFOpxnyTHVFfgqI6NWuuN8lEwrS3Zb8bGxE_A9LyyUZ2y4uqLpyXRw"
150+
VIDEO_CONNECTION_ID="bcdef09-8765-4321-8cde-0123456789ab"
151+
VIDEO_STREAM_ID="bcdef09-8765-4321-8cde-0123456789ab"
152+
VIDEO_ARCHIVE_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
153+
VIDEO_BROADCAST_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
154+
147155
# Voice
148156
VOICE_CALL_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
149157
VOICE_TO_NUMBER="447700900000"
150158
VOICE_TEXT="Hello from Vonage! Would you like to learn more?"
151-
VOICE_LANGUAGE="en-US"
159+
VOICE_LANGUAGE="AMERICAN_ENGLISH"
152160
VOICE_DTMF_DIGITS="2468#"
153161
VOICE_CONFERENCE_NAME="My conference call room"
154162
VOICE_NCCO_URL="https://nexmo-community.github.io/ncco-examples/talk.json"

src/main/java/com/vonage/quickstart/EnvironmentVariables.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ public static String envVar(String key) {
150150
VERIFY_FROM_EMAIL = envVar("VERIFY_FROM_EMAIL"),
151151
VERIFY_WHATSAPP_NUMBER = envVar("VERIFY_WHATSAPP_NUMBER"),
152152
VERIFY_TEMPLATE_NAME = envVar("VERIFY_TEMPLATE_NAME"),
153+
VIDEO_STREAM_ID = envVar("VIDEO_STREAM_ID"),
154+
VIDEO_ARCHIVE_ID = envVar("VIDEO_ARCHIVE_ID"),
155+
VIDEO_BROADCAST_ID = envVar("VIDEO_BROADCAST_ID"),
156+
VIDEO_CONNECTION_ID = envVar("VIDEO_CONNECTION_ID"),
157+
VIDEO_SESSION_ID = envVar("VIDEO_SESSION_ID"),
158+
VIDEO_TOKEN = envVar("VIDEO_TOKEN"),
153159
VOICE_CALL_ID = envVar("VOICE_CALL_ID"),
154160
VOICE_TO_NUMBER = envVar("VOICE_TO_NUMBER"),
155161
VOICE_TEXT = envVar("VOICE_TEXT"),
@@ -189,10 +195,10 @@ public static String envVar(String key) {
189195
public static final Type
190196
NUMBER_TYPE = Type.fromString(envVar("NUMBER_TYPE"));
191197

192-
public static final Feature[]
198+
public static final com.vonage.client.numbers.Feature[]
193199
NUMBER_FEATURES = Arrays.stream(envVar("NUMBER_FEATURES").split(","))
194-
.map(Feature::fromString)
195-
.toArray(Feature[]::new);
200+
.map(com.vonage.client.numbers.Feature::fromString)
201+
.toArray(com.vonage.client.numbers.Feature[]::new);
196202

197203
public static final SearchPattern
198204
NUMBER_SEARCH_PATTERN = SearchPattern.values()[Integer.parseInt(envVar("NUMBER_SEARCH_PATTERN"))];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vonage.quickstart.video;
17+
18+
import com.vonage.client.VonageClient;
19+
import com.vonage.client.video.*;
20+
import static com.vonage.quickstart.EnvironmentVariables.*;
21+
22+
public class AddArchiveStream {
23+
public static void main(String[] args) throws Exception {
24+
25+
VideoClient videoClient = VonageClient.builder()
26+
.applicationId(VONAGE_APPLICATION_ID)
27+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
28+
.build().getVideoClient();
29+
30+
videoClient.addArchiveStream(VIDEO_ARCHIVE_ID, VIDEO_STREAM_ID);
31+
32+
System.out.println("Added archive stream");
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vonage.quickstart.video;
17+
18+
import com.vonage.client.VonageClient;
19+
import com.vonage.client.video.*;
20+
import static com.vonage.quickstart.EnvironmentVariables.*;
21+
22+
public class AddBroadcastStream {
23+
public static void main(String[] args) throws Exception {
24+
25+
VideoClient videoClient = VonageClient.builder()
26+
.applicationId(VONAGE_APPLICATION_ID)
27+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
28+
.build().getVideoClient();
29+
30+
videoClient.addBroadcastStream(VIDEO_BROADCAST_ID, VIDEO_STREAM_ID);
31+
32+
System.out.println("Added broadcast stream");
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vonage.quickstart.video;
17+
18+
import com.vonage.client.VonageClient;
19+
import com.vonage.client.video.*;
20+
import static com.vonage.quickstart.EnvironmentVariables.*;
21+
22+
public class CreateArchive {
23+
public static void main(String[] args) throws Exception {
24+
25+
VideoClient videoClient = VonageClient.builder()
26+
.applicationId(VONAGE_APPLICATION_ID)
27+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
28+
.build().getVideoClient();
29+
30+
Archive archive = videoClient.createArchive(
31+
Archive.builder(VIDEO_SESSION_ID)
32+
.streamMode(StreamMode.AUTO)
33+
.hasVideo(true)
34+
.hasAudio(true)
35+
.resolution(Resolution.HD_LANDSCAPE)
36+
.outputMode(OutputMode.COMPOSED).name("My recording")
37+
.build()
38+
);
39+
40+
System.out.println("Started archive: " + archive.toJson());
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vonage.quickstart.video;
17+
18+
import com.vonage.client.VonageClient;
19+
import com.vonage.client.video.*;
20+
import static com.vonage.quickstart.EnvironmentVariables.*;
21+
import java.time.Duration;
22+
23+
public class CreateBroadcast {
24+
public static void main(String[] args) throws Exception {
25+
26+
VideoClient videoClient = VonageClient.builder()
27+
.applicationId(VONAGE_APPLICATION_ID)
28+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
29+
.build().getVideoClient();
30+
31+
Broadcast broadcast = videoClient.createBroadcast(
32+
Broadcast.builder(VIDEO_SESSION_ID)
33+
.hls(Hls.builder().lowLatency(true).build())
34+
.resolution(Resolution.HD_LANDSCAPE)
35+
.streamMode(StreamMode.AUTO)
36+
.maxDuration(Duration.ofMinutes(45))
37+
.build()
38+
);
39+
40+
System.out.println("Started broadcast: " + broadcast.toJson());
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vonage.quickstart.video;
17+
18+
import com.vonage.client.VonageClient;
19+
import com.vonage.client.video.*;
20+
import static com.vonage.quickstart.EnvironmentVariables.*;
21+
22+
public class CreateSession {
23+
public static void main(String[] args) throws Exception {
24+
25+
VideoClient videoClient = VonageClient.builder()
26+
.applicationId(VONAGE_APPLICATION_ID)
27+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
28+
.build().getVideoClient();
29+
30+
CreateSessionResponse session = videoClient.createSession(
31+
CreateSessionRequest.builder()
32+
.mediaMode(MediaMode.ROUTED)
33+
.archiveMode(ArchiveMode.MANUAL)
34+
.build()
35+
);
36+
37+
System.out.println("Created session: " + session.toJson());
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.vonage.quickstart.video;
2+
3+
import com.vonage.client.VonageClient;
4+
import com.vonage.client.video.*;
5+
import static com.vonage.quickstart.EnvironmentVariables.*;
6+
7+
public class DeleteArchive {
8+
public static void main(String[] args) throws Exception {
9+
10+
VideoClient videoClient = VonageClient.builder()
11+
.applicationId(VONAGE_APPLICATION_ID)
12+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
13+
.build().getVideoClient();
14+
15+
videoClient.deleteArchive(VIDEO_ARCHIVE_ID);
16+
17+
System.out.println("Deleted archive");
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.vonage.quickstart.video;
2+
3+
import com.vonage.client.VonageClient;
4+
import com.vonage.client.video.*;
5+
import static com.vonage.quickstart.EnvironmentVariables.*;
6+
7+
public class ForceDisconnect {
8+
public static void main(String[] args) throws Exception {
9+
10+
VideoClient videoClient = VonageClient.builder()
11+
.applicationId(VONAGE_APPLICATION_ID)
12+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
13+
.build().getVideoClient();
14+
15+
videoClient.forceDisconnect(VIDEO_SESSION_ID, VIDEO_CONNECTION_ID);
16+
17+
System.out.println("Force disconnected");
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.vonage.quickstart.video;
2+
3+
import com.vonage.client.VonageClient;
4+
import com.vonage.client.video.*;
5+
import static com.vonage.quickstart.EnvironmentVariables.*;
6+
7+
public class ForceMute {
8+
public static void main(String[] args) throws Exception {
9+
10+
VideoClient videoClient = VonageClient.builder()
11+
.applicationId(VONAGE_APPLICATION_ID)
12+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
13+
.build().getVideoClient();
14+
15+
videoClient.muteStream(VIDEO_SESSION_ID, VIDEO_STREAM_ID);
16+
17+
System.out.println("Force muted");
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.vonage.quickstart.video;
2+
3+
import com.vonage.client.VonageClient;
4+
import com.vonage.client.video.*;
5+
import static com.vonage.quickstart.EnvironmentVariables.*;
6+
7+
import java.time.Duration;
8+
9+
public class GenerateToken {
10+
public static void main(String[] args) throws Exception {
11+
12+
VideoClient videoClient = VonageClient.builder()
13+
.applicationId(VONAGE_APPLICATION_ID)
14+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
15+
.build().getVideoClient();
16+
17+
TokenOptions tokenOptions = TokenOptions.builder()
18+
.role(Role.MODERATOR)
19+
.expiryLength(Duration.ofHours(6))
20+
.data("name=John,id=123")
21+
.build();
22+
23+
String jwt = videoClient.generateToken(VIDEO_SESSION_ID, tokenOptions);
24+
25+
System.out.println("Generated token: " + jwt);
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2025 Vonage
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.vonage.quickstart.video;
17+
18+
import com.vonage.client.VonageClient;
19+
import com.vonage.client.video.*;
20+
import static com.vonage.quickstart.EnvironmentVariables.*;
21+
22+
public class GetArchive {
23+
public static void main(String[] args) throws Exception {
24+
25+
VideoClient videoClient = VonageClient.builder()
26+
.applicationId(VONAGE_APPLICATION_ID)
27+
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
28+
.build().getVideoClient();
29+
30+
Archive archive = videoClient.getArchive(VIDEO_ARCHIVE_ID);
31+
32+
System.out.println("Retrieved archive: " + archive.toJson());
33+
}
34+
}

0 commit comments

Comments
 (0)