RecordingProperties::hasVideo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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  string  $name
36
     * @param  string  $outputMode
37
     * @param  string  $recordingLayout
38
     * @param  string|null  $resolution
39
     * @param  bool  $hasAudio
40
     * @param  bool  $hasVideo
41
     * @param  string|null  $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
    {
67
        return $this->session;
68
    }
69
70
    /**
71
     * Defines the name you want to give to the video file. You can access this same
72
     * value in your clients on recording events (<code>recordingStarted</code>,
73
     * <code>recordingStopped</code>)
74
     *
75
     * @return string
76
     */
77
    public function name()
78
    {
79
        return $this->name;
80
    }
81
82
    /**
83
     * Defines the mode of recording: {@see OutputMode::COMPOSED} or {@see OutputMode::COMPOSED_QUICK_START} for a
84
     * single archive in a grid layout or {@@see OutputMode::INDIVIDUAL}
85
     * for one archive for each stream.<br>
86
     * <br>
87
     *
88
     * Default to {@see OutputMode::COMPOSED}
89
     *
90
     * @return OutputMode|string
91
     */
92
    public function outputMode()
93
    {
94
        return $this->outputMode;
95
    }
96
97
    /**
98
     * Defines the layout to be used in the recording.<br>
99
     * Will only have effect if has been cealled with value {@see OutputMode::COMPOSED} or {@see OutputMode::COMPOSED_QUICK_START}.<br>
100
     * <br>
101
     *
102
     * Default to {@see RecordingLayout#BEST_FIT}
103
     *
104
     * @return RecordingLayout|string
105
     */
106
    public function recordingLayout()
107
    {
108
        return $this->recordingLayout;
109
    }
110
111
    /**
112
     * If {@see RecordingProperties::$recordingLayout} is
113
     * set to {@see RecordingLayout::CUSTOM}, this property
114
     * defines the relative path to the specific custom layout you want to use.<br>
115
     * See <a href="https://openvidu.io/docs/advanced-features/recording#custom-recording-layouts" target="_blank">Custom recording layouts</a> to learn more
116
     *
117
     * @return string|null
118
     */
119
    public function customLayout()
120
    {
121
        return $this->customLayout;
122
    }
123
124
    /**
125
     * Defines the resolution of the recorded video.<br>
126
     * Will only have effect if has been called with value
127
     * {@see  outputMode::COMPOSED}.
128
     * {@see  OutputMode::COMPOSED_QUICK_START}
129
     * {@see  OutputMode::INDIVIDUAL}
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
        return json_encode($this->jsonSerialize(), $options);
178
    }
179
180
    /**
181
     * Specify data which should be serialized to JSON
182
     * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
183
     * @return mixed data which can be serialized by <b>json_encode</b>,
184
     * which is a value of any type other than a resource.
185
     * @since 5.4.0
186
     */
187
    public function jsonSerialize()
188
    {
189
        return $this->toArray();
190
    }
191
192
    /**
193
     * Convert the model instance to an array.
194
     *
195
     * @return array
196
     */
197
    public function toArray(): array
198
    {
199
        $array = [
200
            'session' => $this->session,
201
            'hasAudio' => $this->hasAudio,
202
            'hasVideo' => $this->hasVideo,
203
            'name' => $this->name,
204
            'outputMode' => $this->outputMode,
205
            'recordingLayout' => $this->recordingLayout,
206
            'resolution' => $this->resolution,
207
            'customLayout' => $this->customLayout
208
        ];
209
        foreach ($array as $key => $value) {
210
            if (is_null($value) || $value == '') {
211
                unset($array[$key]);
212
            }
213
        }
214
        return $array;
215
    }
216
}
217