1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SquareetLabs\LaravelOpenVidu; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use JsonSerializable; |
7
|
|
|
use SquareetLabs\LaravelOpenVidu\Enums\OutputMode; |
8
|
|
|
use SquareetLabs\LaravelOpenVidu\Enums\RecordingLayout; |
9
|
|
|
use SquareetLabs\LaravelOpenVidu\Enums\RecordingMode; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class SessionProperties |
13
|
|
|
* @package SquareetLabs\LaravelOpenVidu |
14
|
|
|
*/ |
15
|
|
|
class SessionProperties implements JsonSerializable |
16
|
|
|
{ |
17
|
|
|
/** @var string */ |
18
|
|
|
private $mediaMode; |
19
|
|
|
|
20
|
|
|
/** @var string |
21
|
|
|
* {@see RecordingMode} |
22
|
|
|
*/ |
23
|
|
|
private $recordingMode; |
24
|
|
|
/** @var string |
25
|
|
|
* {@see OutputMode} |
26
|
|
|
*/ |
27
|
|
|
private $defaultOutputMode; |
28
|
|
|
/** @var string |
29
|
|
|
* {@see RecordingLayout} |
30
|
|
|
*/ |
31
|
|
|
private $defaultRecordingLayout; |
32
|
|
|
|
33
|
|
|
/** @var string */ |
34
|
|
|
private $defaultCustomLayout; |
35
|
|
|
|
36
|
|
|
/** @var string */ |
37
|
|
|
private $customSessionId; |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* SessionProperties constructor. |
42
|
|
|
* @param string $mediaMode |
43
|
|
|
* @param string $recordingMode |
44
|
|
|
* @param string $defaultOutputMode |
45
|
|
|
* @param string|null $defaultRecordingLayout |
46
|
|
|
* @param string|null $customSessionId |
47
|
|
|
* @param string|null $defaultCustomLayout |
48
|
|
|
*/ |
49
|
|
|
public function __construct(string $mediaMode, string $recordingMode, string $defaultOutputMode, ?string $defaultRecordingLayout, ?string $customSessionId = null, ?string $defaultCustomLayout = null) |
50
|
|
|
{ |
51
|
|
|
if ($defaultRecordingLayout == RecordingLayout::CUSTOM && empty($defaultCustomLayout)) { |
52
|
|
|
throw new InvalidArgumentException("If you pass the value \"CUSTOM\" for the parameter \"$defaultRecordingLayout\" you must indicate a value for the parameter \"$defaultCustomLayout\"."); |
53
|
|
|
} |
54
|
|
|
$this->mediaMode = $mediaMode; |
55
|
|
|
$this->recordingMode = $recordingMode; |
56
|
|
|
$this->defaultOutputMode = $defaultOutputMode; |
57
|
|
|
$this->defaultRecordingLayout = $defaultRecordingLayout; |
58
|
|
|
$this->defaultCustomLayout = $defaultCustomLayout; |
59
|
|
|
$this->customSessionId = $customSessionId; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function getCustomSessionId(): ?string |
66
|
|
|
{ |
67
|
|
|
return $this->customSessionId; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getMediaMode(): string |
74
|
|
|
{ |
75
|
|
|
return $this->mediaMode; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
|
|
public function getRecordingMode(): string |
82
|
|
|
{ |
83
|
|
|
return $this->recordingMode; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getDefaultOutputMode(): string |
90
|
|
|
{ |
91
|
|
|
return $this->defaultOutputMode; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function getDefaultRecordingLayout(): ?string |
98
|
|
|
{ |
99
|
|
|
return $this->defaultRecordingLayout; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getDefaultCustomLayout(): ?string |
106
|
|
|
{ |
107
|
|
|
return $this->defaultCustomLayout; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Convert the model instance to JSON. |
112
|
|
|
* |
113
|
|
|
* @param int $options |
114
|
|
|
* @return string |
115
|
|
|
* |
116
|
|
|
*/ |
117
|
|
|
public function toJson($options = 0): string |
118
|
|
|
{ |
119
|
|
|
$json = json_encode($this->jsonSerialize(), $options); |
120
|
|
|
return $json; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Specify data which should be serialized to JSON |
125
|
|
|
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php |
126
|
|
|
* @return mixed data which can be serialized by <b>json_encode</b>, |
127
|
|
|
* which is a value of any type other than a resource. |
128
|
|
|
* @since 5.4.0 |
129
|
|
|
*/ |
130
|
|
|
public function jsonSerialize() |
131
|
|
|
{ |
132
|
|
|
return $this->toArray(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Convert the model instance to an array. |
137
|
|
|
* |
138
|
|
|
* @return array |
139
|
|
|
*/ |
140
|
|
|
public function toArray(): array |
141
|
|
|
{ |
142
|
|
|
$array = [ |
143
|
|
|
'mediaMode' => $this->mediaMode, |
144
|
|
|
'recordingMode' => $this->recordingMode, |
145
|
|
|
'defaultOutputMode' => $this->defaultOutputMode, |
146
|
|
|
'defaultRecordingLayout' => $this->defaultRecordingLayout, |
147
|
|
|
'defaultCustomLayout' => $this->defaultCustomLayout, |
148
|
|
|
'customSessionId' => $this->customSessionId |
149
|
|
|
]; |
150
|
|
|
foreach ($array as $key => $value) { |
151
|
|
|
if (is_null($value) || $value == '') { |
152
|
|
|
unset($array[$key]); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
return $array; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|