Skip to content

Commit 1536d66

Browse files
committed
Enable request/response logging when OPENTOK_DEBUG is defined
1 parent 085539a commit 1536d66

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

src/OpenTok/Util/Client.php

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function createSession($options)
9595
$request = new Request('POST', '/session/create');
9696
try {
9797
$response = $this->client->send($request, [
98-
'debug' => true,
98+
'debug' => $this->isDebug(),
9999
'form_params' => $this->postFieldsForOptions($options)
100100
]);
101101
$sessionXml = $this->getResponseXml($response);
@@ -143,6 +143,7 @@ public function startArchive($sessionId, $options)
143143

144144
try {
145145
$response = $this->client->send($request, [
146+
'debug' => $this->isDebug(),
146147
'json' => array_merge(
147148
array( 'sessionId' => $sessionId ),
148149
$options
@@ -165,7 +166,9 @@ public function stopArchive($archiveId)
165166
);
166167

167168
try {
168-
$response = $this->client->send($request);
169+
$response = $this->client->send($request, [
170+
'debug' => $this->isDebug()
171+
]);
169172
$archiveJson = json_decode($response->getBody(), true);
170173
} catch (\Exception $e) {
171174
// TODO: what happens with JSON parse errors?
@@ -181,7 +184,9 @@ public function getArchive($archiveId)
181184
'/v2/project/'.$this->apiKey.'/archive/'.$archiveId
182185
);
183186
try {
184-
$response = $this->client->send($request);
187+
$response = $this->client->send($request, [
188+
'debug' => $this->isDebug()
189+
]);
185190
$archiveJson = json_decode($response->getBody(), true);
186191
} catch (\Exception $e) {
187192
$this->handleException($e);
@@ -198,7 +203,9 @@ public function deleteArchive($archiveId)
198203
['Content-Type' => 'application/json']
199204
);
200205
try {
201-
$response = $this->client->send($request);
206+
$response = $this->client->send($request, [
207+
'debug' => $this->isDebug()
208+
]);
202209
if ($response->getStatusCode() != 204) {
203210
json_decode($response->getBody(), true);
204211
}
@@ -217,7 +224,9 @@ public function forceDisconnect($sessionId,$connectionId)
217224
['Content-Type' => 'application/json']
218225
);
219226
try {
220-
$response = $this->client->send($request);
227+
$response = $this->client->send($request, [
228+
'debug' => $this->isDebug()
229+
]);
221230
if ($response->getStatusCode() != 204) {
222231
json_decode($response->getBody(), true);
223232
}
@@ -240,7 +249,8 @@ public function listArchives($offset, $count)
240249
}
241250
try {
242251
$response = $this->client->send($request, [
243-
'query' => $queryParams
252+
'debug' => $this->isDebug(),
253+
'query' => $queryParams
244254
]);
245255
$archiveListJson = json_decode($response->getBody(), true);
246256
} catch (\Exception $e) {
@@ -259,10 +269,11 @@ public function startBroadcast($sessionId, $options)
259269

260270
try {
261271
$response = $this->client->send($request, [
262-
'json' => [
263-
'sessionId' => $sessionId,
264-
'layout' => $options['layout']->jsonSerialize()
265-
]
272+
'debug' => $this->isDebug(),
273+
'json' => [
274+
'sessionId' => $sessionId,
275+
'layout' => $options['layout']->jsonSerialize()
276+
]
266277
]);
267278
$broadcastJson = json_decode($response->getBody(), true);
268279
} catch (\Exception $e) {
@@ -280,7 +291,9 @@ public function stopBroadcast($broadcastId)
280291
);
281292

282293
try {
283-
$response = $this->client->send($request);
294+
$response = $this->client->send($request, [
295+
'debug' => $this->isDebug()
296+
]);
284297
$broadcastJson = json_decode($response->getBody(), true);
285298
} catch (\Exception $e) {
286299
$this->handleBroadcastException($e);
@@ -295,7 +308,9 @@ public function getBroadcast($broadcastId)
295308
'/v2/project/'.$this->apiKey.'/broadcast/'.$broadcastId
296309
);
297310
try {
298-
$response = $this->client->send($request);
311+
$response = $this->client->send($request, [
312+
'debug' => $this->isDebug()
313+
]);
299314
$broadcastJson = json_decode($response->getBody(), true);
300315
} catch (\Exception $e) {
301316
$this->handleBroadcastException($e);
@@ -310,7 +325,9 @@ public function getLayout($resourceId, $resourceType = 'broadcast')
310325
'/v2/project/'.$this->apiKey.'/'.$resourceType.'/'.$resourceId.'/layout'
311326
);
312327
try {
313-
$response = $this->client->send($request);
328+
$response = $this->client->send($request, [
329+
'debug' => $this->isDebug()
330+
]);
314331
$layoutJson = json_decode($response->getBody(), true);
315332
} catch (\Exception $e) {
316333
$this->handleException($e);
@@ -326,6 +343,7 @@ public function updateLayout($resourceId, $layout, $resourceType = 'broadcast')
326343
);
327344
try {
328345
$response = $this->client->send($request, [
346+
'debug' => $this->isDebug(),
329347
'json' => $layout->jsonSerialize()
330348
]);
331349
$layoutJson = json_decode($response->getBody(), true);
@@ -343,6 +361,7 @@ public function updateStream($sessionId, $streamId, $properties)
343361
);
344362
try {
345363
$response = $this->client->send($request, [
364+
'debug' => $this->isDebug(),
346365
'json' => $properties
347366
]);
348367
if ($response->getStatusCode() != 204) {
@@ -380,6 +399,7 @@ public function dial($sessionId, $token, $sipUri, $options)
380399

381400
try {
382401
$response = $this->client->send($request, [
402+
'debug' => $this->isDebug(),
383403
'json' => $body
384404
]);
385405
$sipJson = json_decode($response->getBody(), true);
@@ -472,4 +492,8 @@ private function handleBroadcastException($e)
472492
}
473493
}
474494

495+
private function isDebug()
496+
{
497+
return defined('OPENTOK_DEBUG');
498+
}
475499
}

tests/OpenTok/OpenTokTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use OpenTok\TestHelpers;
1818

19-
// define('DEBUG', true);
19+
define('OPENTOK_DEBUG', true);
2020

2121
class OpenTokTest extends PHPUnit_Framework_TestCase
2222
{
@@ -57,9 +57,6 @@ private function setupOTWithMocks($mocks)
5757
'https://api.opentok.com',
5858
$clientOptions
5959
);
60-
if (defined('DEBUG')) {
61-
$this->client->addSubscriber(LogPlugin::getDebugPlugin());
62-
}
6360

6461
// Push history onto handler stack *after* configuring client to
6562
// ensure auth header is added before history handler is invoked

0 commit comments

Comments
 (0)