Skip to content

Commit eb070bb

Browse files
authored
Merge pull request #338 from opentok/feature/hls-broadcast-status
Status keys for broadcast object
2 parents 989f990 + 3008c4a commit eb070bb

File tree

5 files changed

+54
-21
lines changed

5 files changed

+54
-21
lines changed

src/OpenTok/Broadcast.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
*
4545
* @property boolean $isDvr
4646
* Whether the broadcast supports DVR functionality for the HLS stream.
47+
48+
* @property string $status
49+
* Broadcast state. Either `started` or `stopped`
4750
*
4851
* @property boolean $isLowLatency
4952
* Whether the broadcast supports low-latency mode for the HLS stream.
@@ -86,6 +89,8 @@ class Broadcast
8689
private $hasAudio;
8790
/** @ignore */
8891
private $hasVideo;
92+
/** @ignore */
93+
private $status;
8994

9095
public function __construct($broadcastData, $options = array())
9196
{
@@ -107,34 +112,37 @@ public function __construct($broadcastData, $options = array())
107112
);
108113

109114
$options = array_merge($defaults, array_intersect_key($options, $defaults));
110-
list($apiKey, $apiSecret, $apiUrl, $client, $isStopped, $streamMode, $hasAudio, $hasVideo) = array_values($options);
111115

112-
// validate params
113116
Validators::validateBroadcastData($broadcastData);
114-
Validators::validateClient($client);
115-
Validators::validateHasStreamMode($streamMode);
117+
Validators::validateClient($options['client']);
118+
Validators::validateHasStreamMode($options['streamMode']);
116119

117120
$this->data = $broadcastData;
118121

119122
if (isset($this->data['multiBroadcastTag'])) {
120123
$this->multiBroadcastTag = $this->data['multiBroadcastTag'];
121124
}
122125

123-
$this->isStopped = $isStopped;
126+
if (isset($this->data['status'])) {
127+
$this->status = $this->data['status'];
128+
}
129+
130+
$this->isStopped = $options['isStopped'];
124131
$this->resolution = $this->data['resolution'];
125132
$this->isHls = isset($this->data['settings']['hls']);
126133
$this->isLowLatency = $this->data['settings']['hls']['lowLatency'] ?? false;
127134
$this->isDvr = $this->data['settings']['hls']['dvr'] ?? false;
128-
$this->hasAudio = $hasAudio;
129-
$this->hasVideo = $hasVideo;
135+
$this->hasAudio = $options['hasAudio'];
136+
$this->hasVideo = $options['hasVideo'];
137+
138+
$this->client = $options['client'] ?? new Client();
130139

131-
$this->client = isset($client) ? $client : new Client();
132140
if (!$this->client->isConfigured()) {
133-
Validators::validateApiKey($apiKey);
134-
Validators::validateApiSecret($apiSecret);
135-
Validators::validateApiUrl($apiUrl);
141+
Validators::validateApiKey($options['apiKey']);
142+
Validators::validateApiSecret($options['apiSecret']);
143+
Validators::validateApiUrl($options['apiUrl']);
136144

137-
$this->client->configure($apiKey, $apiSecret, $apiUrl);
145+
$this->client->configure($options['apiKey'], $options['apiSecret'], $options['apiUrl']);
138146
}
139147
}
140148

@@ -148,7 +156,6 @@ public function __get($name)
148156
case 'partnerId':
149157
case 'sessionId':
150158
case 'broadcastUrls':
151-
case 'status':
152159
case 'maxDuration':
153160
case 'streamMode':
154161
return $this->data[$name];
@@ -170,6 +177,8 @@ public function __get($name)
170177
return $this->hasAudio;
171178
case 'hasVideo':
172179
return $this->hasVideo;
180+
case 'status':
181+
return $this->status;
173182
default:
174183
return null;
175184
}

tests/OpenTokTest/BroadcastTest.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function setUp(): void
3434
'updatedAt' => 1394394801000,
3535
'partnerId' => 685,
3636
'sessionId' => '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh-',
37+
'multiBroadcastTag' => 'broadcast-1234b',
3738
'layout' => [
3839
'type' => 'custom',
3940
'stylesheet' => 'a layout stylesheet',
@@ -42,8 +43,9 @@ public function setUp(): void
4243
'maxDuration' => 5400,
4344
'resolution' => '640x480',
4445
'streamMode' => StreamMode::AUTO,
45-
'isAudio' => true,
46-
'isVideo' => true
46+
'status' => 'started',
47+
'hasAudio' => true,
48+
'hasVideo' => true
4749
];
4850
}
4951

@@ -134,12 +136,12 @@ private function setupOT()
134136
return $this->setupOTWithMocks([]);
135137
}
136138

137-
public function testInitializes()
139+
public function testInitializes(): void
138140
{
139-
// Arrange
140141
$this->setupOT();
141142
$this->setupBroadcasts(StreamMode::AUTO);
142143
$this->assertInstanceOf(Broadcast::class, $this->broadcast);
144+
143145
}
144146

145147
public function testCannotAddStreamToBroadcastInAutoMode(): void
@@ -238,5 +240,20 @@ public function testCannotRemoveStreamFromBroadcastOnAuto(): void
238240
'5dfds4-asdda4asf4'
239241
);
240242
}
243+
244+
public function testGetters(): void
245+
{
246+
$broadcastObject = new Broadcast($this->broadcastData, [
247+
'apiKey' => 'abc',
248+
'apiSecret' => 'efg',
249+
'client' => $this->client
250+
]);
251+
252+
$this->assertTrue($broadcastObject->hasAudio);
253+
$this->assertTrue($broadcastObject->hasVideo);
254+
$this->assertEquals('broadcast-1234b', $broadcastObject->multiBroadcastTag);
255+
$this->assertEquals('started', $broadcastObject->status);
256+
$this->assertNull($broadcastObject->wrongKey);
257+
}
241258
}
242259

tests/OpenTokTest/OpenTokTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,7 @@ public function testCanStartBroadcastWithDefaultHlsOptions(): void
16401640
$this->assertTrue($broadcast->isHls);
16411641
$this->assertFalse($broadcast->isDvr);
16421642
$this->assertFalse($broadcast->isLowLatency);
1643+
$this->assertEquals('live', $broadcast->broadcastUrls['rtmp']['foo']['status']);
16431644
}
16441645

16451646
public function testCanStartBroadcastWithDvrEnabled(): void

tests/mock/v2/project/APIKEY/broadcast/BROADCASTID/start_default

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
"createdAt":1472435659497,
66
"broadcastUrls":{
77
"hls":"https://cdn-broadcast001-dub.tokbox.com/29908/29908_6706b658-2eba-42cc-b4d2-7d01a104d182.smil/playlist.m3u8",
8+
"hlsStatus": "ready",
89
"rtmp": {
910
"foo": {
1011
"serverUrl": "rtmp://myfooserver/myfooapp",
11-
"streamName": "myfoostreamname"
12+
"streamName": "myfoostreamname",
13+
"status": "live"
1214
},
1315
"bar": {
1416
"serverUrl": "rtmp://mybarserver/mybarapp",
15-
"streamName": "mybarstreamname"
17+
"streamName": "mybarstreamname",
18+
"status": "offline"
1619
}
1720
}
1821
},

tests/mock/v2/project/APIKEY/broadcast/BROADCASTID/start_ll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
"createdAt":1472435659497,
66
"broadcastUrls":{
77
"hls":"https://cdn-broadcast001-dub.tokbox.com/29908/29908_6706b658-2eba-42cc-b4d2-7d01a104d182.smil/playlist.m3u8",
8+
"hlsStatus": "ready",
89
"rtmp": {
910
"foo": {
1011
"serverUrl": "rtmp://myfooserver/myfooapp",
11-
"streamName": "myfoostreamname"
12+
"streamName": "myfoostreamname",
13+
"status": "live"
1214
},
1315
"bar": {
1416
"serverUrl": "rtmp://mybarserver/mybarapp",
15-
"streamName": "mybarstreamname"
17+
"streamName": "mybarstreamname",
18+
"status": "offline"
1619
}
1720
}
1821
},

0 commit comments

Comments
 (0)