| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace SquareetLabs\LaravelOpenVidu; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use JsonSerializable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SquareetLabs\LaravelOpenVidu\Enums\OutputMode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SquareetLabs\LaravelOpenVidu\Enums\RecordingLayout; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Class RecordingProperties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @package SquareetLabs\LaravelOpenVidu | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class RecordingProperties implements JsonSerializable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** @var  string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private $session; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** @var  string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     private $customLayout; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** @var  bool */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private $hasAudio; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** @var  bool */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     private $hasVideo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** @var  string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     private $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** @var  string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private $outputMode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** @var  string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     private $recordingLayout; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** @var  string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     private $resolution; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * RecordingProperties constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @param  string  $session | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @param  bool  $hasAudio | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @param  bool  $hasVideo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @param  string  $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @param  string  $outputMode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param  string  $recordingLayout | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param  string  $resolution | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param  string  $customLayout | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function __construct(string $session, string $name, string $outputMode, string $recordingLayout, ?string $resolution = null, ?bool $hasAudio = true, ?bool $hasVideo = true, ?string $customLayout = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->session = $session; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->hasAudio = $hasAudio; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->hasVideo = $hasVideo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->name = $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->outputMode = $outputMode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         if ($this->outputMode === OutputMode::COMPOSED && $this->hasVideo) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $this->resolution = $resolution ? $resolution : '1920x1080'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             $this->recordingLayout = $recordingLayout ? $recordingLayout : RecordingLayout::BEST_FIT; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             if ($this->recordingLayout === RecordingLayout::CUSTOM) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 $this->customLayout = $customLayout; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * Session name of the recording | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function session() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         return $this->session; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * Defines the name you want to give to the video file. You can access this same | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * value in your clients on recording events (<code>recordingStarted</code>, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * <code>recordingStopped</code>) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     public function name() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         return $this->name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * Defines the mode of recording: {@see OutputMode::COMPOSED} for a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * single archive in a grid layout or {@@see OutputMode::INDIVIDUAL} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * for one archive for each stream.<br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * <br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * Default to {@see OutputMode::COMPOSED} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @return OutputMode|string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     public function outputMode() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return $this->outputMode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * Defines the layout to be used in the recording.<br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * Will only have effect if has been cealled with value {@see OutputMode::COMPOSED}.<br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * <br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * Default to {@see RecordingLayout#BEST_FIT} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * @return RecordingLayout|string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     public function recordingLayout() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         return $this->recordingLayout; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * If {@see RecordingProperties::$recordingLayout} is | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * set to {@see RecordingLayout::CUSTOM}, this property | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * defines the relative path to the specific custom layout you want to use.<br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * See <a href="https://openvidu.io/docs/advanced-features/recording#custom-recording-layouts" target="_blank">Custom recording layouts</a> to learn more | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * @return string|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     public function customLayout() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         return $this->customLayout; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * Defines the resolution of the recorded video.<br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      * Will only have effect if has been called with value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      * {@see  outputMode::COMPOSED}. For | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * {@see  OutputMode::INDIVIDUAL} all | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * individual video files will have the native resolution of the published | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * stream.<br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * <br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * Default to "1920x1080" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     public function resolution(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         return $this->resolution; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |      * Defines whether to record audio or not. Cannot be set to false at the same | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |      * time as {@see hasVideo()}.<br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |      * <br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * Default to true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     public function hasAudio() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         return $this->hasAudio; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      * Defines whether to record video or not. Cannot be set to false at the same | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      * time as {@see hasAudio()}.<br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |      * <br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |      * Default to true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     public function hasVideo() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         return $this->hasVideo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |      * Convert the model instance to JSON. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |      * @param  int  $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     public function toJson($options = 0): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         $json = json_encode($this->jsonSerialize(), $options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         return $json; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      * Specify data which should be serialized to JSON | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |      * @link https://php.net/manual/en/jsonserializable.jsonserialize.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |      * @return mixed data which can be serialized by <b>json_encode</b>, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |      * which is a value of any type other than a resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |      * @since 5.4.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |     public function jsonSerialize() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         return $this->toArray(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |      * Convert the model instance to an array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 197 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 198 |  |  |     public function toArray(): array | 
            
                                                                        
                            
            
                                    
            
            
                | 199 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 200 |  |  |         $array = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 201 |  |  |             'session' => $this->session, | 
            
                                                                        
                            
            
                                    
            
            
                | 202 |  |  |             'hasAudio' => $this->hasAudio, | 
            
                                                                        
                            
            
                                    
            
            
                | 203 |  |  |             'hasVideo' => $this->hasVideo, | 
            
                                                                        
                            
            
                                    
            
            
                | 204 |  |  |             'name' => $this->name, | 
            
                                                                        
                            
            
                                    
            
            
                | 205 |  |  |             'outputMode' => $this->outputMode, | 
            
                                                                        
                            
            
                                    
            
            
                | 206 |  |  |             'recordingLayout' => $this->recordingLayout, | 
            
                                                                        
                            
            
                                    
            
            
                | 207 |  |  |             'resolution' => $this->resolution, | 
            
                                                                        
                            
            
                                    
            
            
                | 208 |  |  |             'customLayout' => $this->customLayout | 
            
                                                                        
                            
            
                                    
            
            
                | 209 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 210 |  |  |         foreach ($array as $key => $value) { | 
            
                                                                        
                            
            
                                    
            
            
                | 211 |  |  |             if (is_null($value) || $value == '') { | 
            
                                                                        
                            
            
                                    
            
            
                | 212 |  |  |                 unset($array[$key]); | 
            
                                                                        
                            
            
                                    
            
            
                | 213 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 214 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 215 |  |  |         return $array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 217 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 218 |  |  |  |