forked from nickbart/php-plex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.php
300 lines (278 loc) · 6.57 KB
/
Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?php
/**
* Plex Client
*
* @category php-plex
* @package Plex_Client
* @author <[email protected]> Nick Bartkowiak
* @copyright (c) 2012 Nick Bartkowiak
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3)
* @version 0.0.1
*
* This file is part of php-plex.
*
* php-plex is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* php-plex is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/**
* Represents a Plex client on the network.
*
* @category php-plex
* @package Plex_Client
* @author <[email protected]> Nick Bartkowiak
* @copyright (c) 2012 Nick Bartkowiak
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public Licence (GPLv3)
* @version 0.0.1
*/
class Plex_Client extends Plex_MachineAbstract
{
/**
* Plex client host as returned by Plex_Server::getClients().
* @var string
*/
private $host;
/**
* Plex client machine identifier as returned by Plex_Server::getClients().
* @var string
*/
private $machineIdentifier;
/**
* Version of Plex the client is running as returned by
* Plex_Server::getClients().
* @var string
*/
private $version;
/**
* The server that registered the client.
* @var Plex_server
*/
private $server;
/**
* The default port on which a Plex client listens.
*/
const DEFAULT_PORT = 3000;
/**
* Sets up our Plex client using the minimum amount of data required to
* interact.
*
* @param string $name The name of the Plex client.
* @param string $address The IP address of the Plex client.
* @param integer $port The port on which the Plex client is listening.
*
* @uses Plex_MachineAbstract::$name
* @uses Plex_MachineAbstract::$address
* @uses Plex_MachineAbstract::$port
* @uses Plex_Client::DEFAULT_PORT
*
* @return void
*/
public function __construct($name, $address, $port)
{
$this->name = $name;
$this->address = $address;
$this->port = $port ? $port : self::DEFAULT_PORT;
}
/**
* Given a controller type, returns an instantiated controller object.
*
* @param string $type The type of controller to be insantiated.
*
* @uses Plex_Client_ControllerAbstract::factory()
* @uses Plex_Client::$name
* @uses Plex_Client::$address
* @uses Plex_Client::$port
* @uses Plex_Client::getServer()
*
* @return Plex_Client_ControllerAbstract The requsted controller.
*/
private function getController($type)
{
return Plex_Client_ControllerAbstract::factory(
$type,
$this->name,
$this->address,
$this->port,
$this->getServer()
);
}
/**
* Returns the navigation controller.
*
* @uses Plex_Client::getController()
* @uses Plex_Client_ControllerAbstract::TYPE_NAVIGATION
*
* @return Plex_Client_Controller_Navigation The navigation controller.
*/
public function getNavigationController()
{
return $this->getController(
Plex_Client_ControllerAbstract::TYPE_NAVIGATION
);
}
/**
* Returns the playback controller.
*
* @uses Plex_Client::getController()
* @uses Plex_Client_ControllerAbstract::TYPE_PLAYBACK
*
* @return Plex_Client_Controller_Playback The playback controller.
*/
public function getPlaybackController()
{
return $this->getController(
Plex_Client_ControllerAbstract::TYPE_PLAYBACK
);
}
/**
* Returns the application controller.
*
* @uses Plex_Client::getController()
* @uses Plex_Client_ControllerAbstract::TYPE_APPLICATION
*
* @return Plex_Client_Controller_Application The application controller.
*/
public function getApplicationController()
{
return $this->getController(
Plex_Client_ControllerAbstract::TYPE_APPLICATION
);
}
/**
* Returns the Plex client's name.
*
* @uses Plex_MachineAbstract::$name
*
* @return string The name of the Plex client.
*/
public function getName()
{
return $this->name;
}
/**
* Returns the Plex client's IP address.
*
* @uses Plex_MachineAbstract::$address
*
* @return string The IP address of the Plex client.
*/
public function getAddress()
{
return $this->address;
}
/**
* Returns the port on which the Plex client listens.
*
* @uses Plex_MachineAbstract::$port
*
* @return integer The port on which the Plex client listens.
*/
public function getPort()
{
return $this->port;
}
/**
* Returns the hostname of the Plex client.
*
* @uses Plex_Client::$host
*
* @return string The hostname of the Plex client.
*/
public function getHost()
{
return $this->host;
}
/**
* Sets the hostname of the Plex client.
*
* @param string $host The hostname of the Plex client.
*
* @uses Plex_client::$host
*
* @return void
*/
public function setHost($host)
{
$this->host = $host;
}
/**
* Returns the mac address of the Plex client.
*
* @uses Plex_Client::$machineIdentifier
*
* @return string The mac address of the Plex client.
*/
public function getMachineIdentifier()
{
return $this->machineIdentifier;
}
/**
* Sets the mac address of the Plex client.
*
* @param string $machineIdentifier The macc address of the Plex client.
*
* @uses Plex_Client::$machineIdentifier
*
* @return void
*/
public function setMachineIdentifier($machineIdentifier)
{
$this->machineIdentifier = $machineIdentifier;
}
/**
* Returns the version of the Plex software the Plex client is running.
*
* @uses Plex_Client::$version
*
* @return string The version of the Plex software the Plex client is
* running.
*/
public function getVersion()
{
return $this->version;
}
/**
* Sets the version of the Plex software the Plex client is running.
*
* @param string $version The version of the Plex software teh Plex client
* is running.
*
* @uses Plex_Client::$version
*
* @return void
*/
public function setVersion($version)
{
$this->version = $version;
}
/**
* Returns the server that registered the client.
*
* @uses Plex_Client::$server
*
* @return Plex_Server The server that registered the client.
*/
protected function getServer()
{
return $this->server;
}
/**
* Sets the server that registered the client.
*
* @param Plex_Server $server The server that registered the client.
*
* @uses Plex_Client::$server
*
* @return void
*/
public function setServer(Plex_Server $server)
{
$this->server = $server;
}
}