001/* 002 * Copyright 2024 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.video; 017 018import com.fasterxml.jackson.annotation.JsonProperty; 019import com.vonage.client.JsonableBaseObject; 020import java.net.URI; 021import java.util.Objects; 022 023/** 024 * Represents an RTMP stream in a video session. 025 */ 026public class Rtmp extends JsonableBaseObject { 027 private String id, streamName; 028 private URI serverUrl; 029 private RtmpStatus status; 030 031 protected Rtmp() { 032 } 033 034 protected Rtmp(Builder builder) { 035 if ((id = builder.id) != null && id.trim().isEmpty()) { 036 throw new IllegalArgumentException("RTMP ID cannot be blank."); 037 } 038 if ((streamName = builder.streamName) == null || streamName.trim().isEmpty()) { 039 throw new IllegalArgumentException("RTMP stream name cannot be blank."); 040 } 041 serverUrl = URI.create(Objects.requireNonNull(builder.serverUrl, "RTMP server URL is required.")); 042 } 043 044 /** 045 * @return A unique identifier for the stream. 046 */ 047 @JsonProperty("id") 048 public String getId() { 049 return id; 050 } 051 052 /** 053 * @return The stream name, such as the YouTube Live stream name or the Facebook stream key. 054 */ 055 @JsonProperty("streamName") 056 public String getStreamName() { 057 return streamName; 058 } 059 060 /** 061 * @return The RTMP server URL. 062 */ 063 @JsonProperty("serverUrl") 064 public URI getServerUrl() { 065 return serverUrl; 066 } 067 068 /** 069 * The status of the RTMP stream. Poll frequently to check status updates. 070 * 071 * @return The status as an enum. 072 */ 073 @JsonProperty("status") 074 public RtmpStatus getStatus() { 075 return status; 076 } 077 078 /** 079 * Entrypoint for creating an instance of this class. 080 * 081 * @return A new Builder instance. 082 */ 083 public static Builder builder() { 084 return new Builder(); 085 } 086 087 public static class Builder { 088 private String id, streamName, serverUrl; 089 090 Builder() {} 091 092 /** 093 * (OPTIONAL) 094 * Sets a unique ID for the stream. 095 * 096 * @param id The unique identifier for this RTMP stream as a string. 097 * 098 * @return This builder. 099 */ 100 public Builder id(String id) { 101 this.id = id; 102 return this; 103 } 104 105 /** 106 * (REQUIRED) 107 * Sets the stream name, such as the YouTube Live stream name or the Facebook stream key. 108 * 109 * @param streamName The name or key for this RTMP stream. 110 * 111 * @return This builder. 112 */ 113 public Builder streamName(String streamName) { 114 this.streamName = streamName; 115 return this; 116 } 117 118 /** 119 * (REQUIRED) 120 * The RTMP server URL. 121 * 122 * @param serverUrl The server URL as a string. 123 * 124 * @return This builder. 125 */ 126 public Builder serverUrl(String serverUrl) { 127 this.serverUrl = serverUrl; 128 return this; 129 } 130 131 /** 132 * Constructs a Rtmp instance with this builder's properties. 133 * 134 * @return A new Rtmp object. 135 */ 136 public Rtmp build() { 137 return new Rtmp(this); 138 } 139 } 140} 141