Skip to content

feat: Add Video API snippets #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
363fa8a
Add video API snippets, Fix fatJar errors, and Add JsonPrinter utility
ydumburs Apr 22, 2025
56f2a32
Update EnvironmentVariables order
SMadani Apr 25, 2025
59e49bc
Update CreateArchive.java
SMadani Apr 25, 2025
0552daa
Update EnvironmentVariables.java
SMadani Apr 25, 2025
323a735
Update AddArchiveStream.java
SMadani Apr 25, 2025
bd1ead4
Update AddBroadcastStream.java
SMadani Apr 25, 2025
6ffce11
Update CreateBroadcast.java
SMadani Apr 25, 2025
bba35e9
Update CreateSession.java
SMadani Apr 25, 2025
66427af
Update CreateArchive.java
SMadani Apr 25, 2025
2c7a8e6
Update GetArchive.java
SMadani Apr 25, 2025
bf3e714
Update GetBroadcast.java
SMadani Apr 25, 2025
67b4435
Update GetStream.java
SMadani Apr 25, 2025
83ee95d
Update ListArchives.java
SMadani Apr 25, 2025
5c5f6c7
Update ListBroadcasts.java
SMadani Apr 25, 2025
d80ea03
Update ListStreams.java
SMadani Apr 25, 2025
68cfd1b
Update ListStreams.java
SMadani Apr 25, 2025
c0f8db1
Update RemoveArchiveStream.java
SMadani Apr 25, 2025
ffbb7c5
Update RemoveBroadcastStream.java
SMadani Apr 25, 2025
847a9c9
Update SendSignal.java
SMadani Apr 25, 2025
233adda
Update SetStreamLayout.java
SMadani Apr 25, 2025
8aa40c9
Update SipDial.java
SMadani Apr 25, 2025
fea9dfc
Update StopArchive.java
SMadani Apr 25, 2025
ee6f0a3
Update StopBroadcast.java
SMadani Apr 25, 2025
0d0d151
Update UpdateArchiveLayout.java
SMadani Apr 25, 2025
aafa2e5
Update UpdateBroadcastLayout.java
SMadani Apr 25, 2025
e40f6db
Update .env-example
SMadani Apr 25, 2025
e83c4d7
Delete JsonPrinter.java
SMadani Apr 25, 2025
d701860
Update CreateBroadcast.java
SMadani Apr 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,19 @@ VERIFY_TEMPLATE_NAME="verify"
VERIFY_TEMPLATE_ID="bcdef09-8765-4321-8cde-0123456789ab"
VERIFY_TEMPLATE_FRAGMENT_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"

# Video
VIDEO_SESSION_ID="flR1ZSBPY3QgMjkgMTI6MTM6MjMgUERUIDIwMTN"
VIDEO_TOKEN="eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhcHBsaWNhdGlvbl9pZCI6ImFhYWFhYWFhLWJiYmItNGNjYy04ZGRkLTAxMjM0NTY3ODlhYiJ9.o3U506EejsS8D5Tob90FG1NC1cR69fh3pFOpxnyTHVFfgqI6NWuuN8lEwrS3Zb8bGxE_A9LyyUZ2y4uqLpyXRw"
VIDEO_CONNECTION_ID="bcdef09-8765-4321-8cde-0123456789ab"
VIDEO_STREAM_ID="bcdef09-8765-4321-8cde-0123456789ab"
VIDEO_ARCHIVE_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
VIDEO_BROADCAST_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"

# Voice
VOICE_CALL_ID="aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab"
VOICE_TO_NUMBER="447700900000"
VOICE_TEXT="Hello from Vonage! Would you like to learn more?"
VOICE_LANGUAGE="en-US"
VOICE_LANGUAGE="AMERICAN_ENGLISH"
VOICE_DTMF_DIGITS="2468#"
VOICE_CONFERENCE_NAME="My conference call room"
VOICE_NCCO_URL="https://nexmo-community.github.io/ncco-examples/talk.json"
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/vonage/quickstart/EnvironmentVariables.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ public static String envVar(String key) {
VERIFY_FROM_EMAIL = envVar("VERIFY_FROM_EMAIL"),
VERIFY_WHATSAPP_NUMBER = envVar("VERIFY_WHATSAPP_NUMBER"),
VERIFY_TEMPLATE_NAME = envVar("VERIFY_TEMPLATE_NAME"),
VIDEO_STREAM_ID = envVar("VIDEO_STREAM_ID"),
VIDEO_ARCHIVE_ID = envVar("VIDEO_ARCHIVE_ID"),
VIDEO_BROADCAST_ID = envVar("VIDEO_BROADCAST_ID"),
VIDEO_CONNECTION_ID = envVar("VIDEO_CONNECTION_ID"),
VIDEO_SESSION_ID = envVar("VIDEO_SESSION_ID"),
VIDEO_TOKEN = envVar("VIDEO_TOKEN"),
VOICE_CALL_ID = envVar("VOICE_CALL_ID"),
VOICE_TO_NUMBER = envVar("VOICE_TO_NUMBER"),
VOICE_TEXT = envVar("VOICE_TEXT"),
Expand Down Expand Up @@ -189,10 +195,10 @@ public static String envVar(String key) {
public static final Type
NUMBER_TYPE = Type.fromString(envVar("NUMBER_TYPE"));

public static final Feature[]
public static final com.vonage.client.numbers.Feature[]
NUMBER_FEATURES = Arrays.stream(envVar("NUMBER_FEATURES").split(","))
.map(Feature::fromString)
.toArray(Feature[]::new);
.map(com.vonage.client.numbers.Feature::fromString)
.toArray(com.vonage.client.numbers.Feature[]::new);

public static final SearchPattern
NUMBER_SEARCH_PATTERN = SearchPattern.values()[Integer.parseInt(envVar("NUMBER_SEARCH_PATTERN"))];
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/vonage/quickstart/video/AddArchiveStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2025 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.quickstart.video;

import com.vonage.client.VonageClient;
import com.vonage.client.video.*;
import static com.vonage.quickstart.EnvironmentVariables.*;

public class AddArchiveStream {
public static void main(String[] args) throws Exception {

VideoClient videoClient = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build().getVideoClient();

videoClient.addArchiveStream(VIDEO_ARCHIVE_ID, VIDEO_STREAM_ID);

System.out.println("Added archive stream");
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/vonage/quickstart/video/AddBroadcastStream.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2025 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.quickstart.video;

import com.vonage.client.VonageClient;
import com.vonage.client.video.*;
import static com.vonage.quickstart.EnvironmentVariables.*;

public class AddBroadcastStream {
public static void main(String[] args) throws Exception {

VideoClient videoClient = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build().getVideoClient();

videoClient.addBroadcastStream(VIDEO_BROADCAST_ID, VIDEO_STREAM_ID);

System.out.println("Added broadcast stream");
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/vonage/quickstart/video/CreateArchive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2025 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.quickstart.video;

import com.vonage.client.VonageClient;
import com.vonage.client.video.*;
import static com.vonage.quickstart.EnvironmentVariables.*;

public class CreateArchive {
public static void main(String[] args) throws Exception {

VideoClient videoClient = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build().getVideoClient();

Archive archive = videoClient.createArchive(
Archive.builder(VIDEO_SESSION_ID)
.streamMode(StreamMode.AUTO)
.hasVideo(true)
.hasAudio(true)
.resolution(Resolution.HD_LANDSCAPE)
.outputMode(OutputMode.COMPOSED).name("My recording")
.build()
);

System.out.println("Started archive: " + archive.toJson());
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/vonage/quickstart/video/CreateBroadcast.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2025 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.quickstart.video;

import com.vonage.client.VonageClient;
import com.vonage.client.video.*;
import static com.vonage.quickstart.EnvironmentVariables.*;
import java.time.Duration;

public class CreateBroadcast {
public static void main(String[] args) throws Exception {

VideoClient videoClient = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build().getVideoClient();

Broadcast broadcast = videoClient.createBroadcast(
Broadcast.builder(VIDEO_SESSION_ID)
.hls(Hls.builder().lowLatency(true).build())
.resolution(Resolution.HD_LANDSCAPE)
.streamMode(StreamMode.AUTO)
.maxDuration(Duration.ofMinutes(45))
.build()
);

System.out.println("Started broadcast: " + broadcast.toJson());
}
}
39 changes: 39 additions & 0 deletions src/main/java/com/vonage/quickstart/video/CreateSession.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2025 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.quickstart.video;

import com.vonage.client.VonageClient;
import com.vonage.client.video.*;
import static com.vonage.quickstart.EnvironmentVariables.*;

public class CreateSession {
public static void main(String[] args) throws Exception {

VideoClient videoClient = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build().getVideoClient();

CreateSessionResponse session = videoClient.createSession(
CreateSessionRequest.builder()
.mediaMode(MediaMode.ROUTED)
.archiveMode(ArchiveMode.MANUAL)
.build()
);

System.out.println("Created session: " + session.toJson());
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/vonage/quickstart/video/DeleteArchive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.vonage.quickstart.video;

import com.vonage.client.VonageClient;
import com.vonage.client.video.*;
import static com.vonage.quickstart.EnvironmentVariables.*;

public class DeleteArchive {
public static void main(String[] args) throws Exception {

VideoClient videoClient = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build().getVideoClient();

videoClient.deleteArchive(VIDEO_ARCHIVE_ID);

System.out.println("Deleted archive");
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/vonage/quickstart/video/ForceDisconnect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.vonage.quickstart.video;

import com.vonage.client.VonageClient;
import com.vonage.client.video.*;
import static com.vonage.quickstart.EnvironmentVariables.*;

public class ForceDisconnect {
public static void main(String[] args) throws Exception {

VideoClient videoClient = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build().getVideoClient();

videoClient.forceDisconnect(VIDEO_SESSION_ID, VIDEO_CONNECTION_ID);

System.out.println("Force disconnected");
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/vonage/quickstart/video/ForceMute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.vonage.quickstart.video;

import com.vonage.client.VonageClient;
import com.vonage.client.video.*;
import static com.vonage.quickstart.EnvironmentVariables.*;

public class ForceMute {
public static void main(String[] args) throws Exception {

VideoClient videoClient = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build().getVideoClient();

videoClient.muteStream(VIDEO_SESSION_ID, VIDEO_STREAM_ID);

System.out.println("Force muted");
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/vonage/quickstart/video/GenerateToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.vonage.quickstart.video;

import com.vonage.client.VonageClient;
import com.vonage.client.video.*;
import static com.vonage.quickstart.EnvironmentVariables.*;

import java.time.Duration;

public class GenerateToken {
public static void main(String[] args) throws Exception {

VideoClient videoClient = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build().getVideoClient();

TokenOptions tokenOptions = TokenOptions.builder()
.role(Role.MODERATOR)
.expiryLength(Duration.ofHours(6))
.data("name=John,id=123")
.build();

String jwt = videoClient.generateToken(VIDEO_SESSION_ID, tokenOptions);

System.out.println("Generated token: " + jwt);
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/vonage/quickstart/video/GetArchive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2025 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.quickstart.video;

import com.vonage.client.VonageClient;
import com.vonage.client.video.*;
import static com.vonage.quickstart.EnvironmentVariables.*;

public class GetArchive {
public static void main(String[] args) throws Exception {

VideoClient videoClient = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build().getVideoClient();

Archive archive = videoClient.getArchive(VIDEO_ARCHIVE_ID);

System.out.println("Retrieved archive: " + archive.toJson());
}
}
Loading