Recording::getStatus()   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
use SquareetLabs\LaravelOpenVidu\Enums\RecordingStatus;
9
10
/**
11
 * Class Recording
12
 * @package SquareetLabs\LaravelOpenVidu
13
 */
14
class Recording implements JsonSerializable
15
{
16
17
    /** @var  string */
18
    private $id;
19
20
    /** @var  string */
21
    private $sessionId;
22
23
    /** @var int */
24
    private $createdAt;
25
26
    /** @var int */
27
    private $size = 0;
28
29
    /** @var float */
30
    private $duration;
31
32
    /** @var string */
33
    private $url;
34
35
    /** @var RecordingStatus */
36
    private $status;
37
38
39
    /** @var RecordingProperties */
40
    private $recordingProperties;
41
42
    /**
43
     * Session constructor.
44
     * @param  string  $id
45
     * @param  string  $sessionId
46
     * @param  int  $createdAt
47
     * @param  int  $size
48
     * @param  float|null  $duration
49
     * @param  string|null  $url
50
     * @param  RecordingProperties|null  $recordingProperties
51
     */
52
    public function __construct(string $id, string $sessionId, int $createdAt, int $size, ?float $duration, ?string $url, ?RecordingProperties $recordingProperties = null)
53
    {
54
        $this->id = $id;
55
        $this->sessionId = $sessionId;
56
        $this->createdAt = $createdAt;
57
        $this->size = $size;
58
        $this->duration = $duration;
59
        $this->url = $url;
60
        $this->recordingProperties = $recordingProperties ? $recordingProperties : $this->getDefaultRecordingProperties();
61
62
    }
63
64
    /**
65
     * @return RecordingProperties
66
     */
67
    private function getDefaultRecordingProperties(): RecordingProperties
68
    {
69
        return new RecordingProperties($this->sessionId, $this->sessionId, OutputMode::COMPOSED, RecordingLayout::BEST_FIT);
70
    }
71
72
    /**
73
     * Session associated to the recording
74
     * @return string
75
     */
76
    public function getSessionId(): string
77
    {
78
        return $this->sessionId;
79
    }
80
81
    /**
82
     * Time when the recording started in UTC milliseconds
83
     * @return int
84
     */
85
    public function getCreatedAt(): int
86
    {
87
        return $this->createdAt;
88
    }
89
90
    /**
91
     * Size of the recording in bytes (0 until the recording is stopped)
92
     * @return int
93
     */
94
    public function getSize(): int
95
    {
96
        return $this->size;
97
    }
98
99
    /**
100
     * Duration of the recording in seconds (0 until the recording is stopped)
101
     * @return float
102
     */
103
    public function getDuration(): float
104
    {
105
        return $this->duration;
106
    }
107
108
    /**
109
     * URL of the recording. You can access the file from there. It is
110
     * <code>null</code> until recording reaches "ready" or "failed" status. If
111
     * <a href="https://openvidu.io/docs/reference-docs/openvidu-server-params/"
112
     * target="_blank">OpenVidu Server configuration</a> property
113
     * <code>openvidu.recording.public-access</code> is false, this path will be
114
     * secured with OpenVidu credentials
115
     */
116
    public function getUrl(): string
117
    {
118
        return $this->url;
119
    }
120
121
    /**
122
     * Status of the recording
123
     * @return RecordingStatus
124
     */
125
    public function getStatus()
126
    {
127
        return $this->status;
128
    }
129
130
131
    /**
132
     * Technical properties of the recorded file
133
     * @return RecordingProperties
134
     */
135
    public function getRecordingProperties(): RecordingProperties
136
    {
137
        return $this->recordingProperties;
138
    }
139
140
    /**
141
     * @return string
142
     */
143
    public function __toString(): string
144
    {
145
        return $this->getId();
146
    }
147
148
    /**
149
     * Recording unique identifier
150
     * @return string
151
     */
152
    public function getId(): string
153
    {
154
        return $this->id;
155
    }
156
157
    /**
158
     * Convert the model instance to JSON.
159
     *
160
     * @param  int  $options
161
     * @return string
162
     *
163
     */
164
    public function toJson($options = 0): string
165
    {
166
        $json = json_encode($this->jsonSerialize(), $options);
167
        return $json;
168
    }
169
170
    /**
171
     * Specify data which should be serialized to JSON
172
     * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
173
     * @return mixed data which can be serialized by <b>json_encode</b>,
174
     * which is a value of any type other than a resource.
175
     * @since 5.4.0
176
     */
177
    public function jsonSerialize()
178
    {
179
        return $this->toArray();
180
    }
181
182
    /**
183
     * Convert the model instance to an array.
184
     *
185
     * @return array
186
     */
187
    public function toArray(): array
188
    {
189
        $array = ['id' => $this->id, 'sessionId' => $this->sessionId, 'size' => $this->size, 'status' => $this->status, 'duration' => $this->duration, 'resolution' => $this->getResolution(), 'hasAudio' => $this->hasAudio(), 'hasVideo' => $this->hasVideo(), 'url' => $this->url, 'createdAt' => $this->createdAt];
190
        foreach ($array as $key => $value) {
191
            if (is_null($value) || $value == '') {
192
                unset($array[$key]);
193
            }
194
        }
195
        return $array;
196
    }
197
198
    /**
199
     * Resolution of the video file. Only defined if OutputMode of the Recording is
200
     * set to {@see OutputMode::COMPOSED}
201
     */
202
    public function getResolution(): string
203
    {
204
        return $this->recordingProperties->resolution();
205
    }
206
207
    /**
208
     * <code>true</code> if the recording has an audio track, <code>false</code>
209
     * otherwise (currently fixed to true)
210
     */
211
    public function hasAudio(): bool
212
    {
213
        return $this->recordingProperties->hasAudio();
214
    }
215
216
    /**
217
     * <code>true</code> if the recording has a video track, <code>false</code>
218
     * otherwise (currently fixed to true)
219
     */
220
    public function hasVideo(): bool
221
    {
222
        return $this->recordingProperties->hasVideo();
223
    }
224
}
225