Example #1
0
 public function testStopStream()
 {
     $contextFormatter = $this->mockInterface('CM_Log_ContextFormatter_Interface')->newInstanceWithoutConstructor();
     $contextFormatter->mockMethod('formatAppContext')->set(['key' => 'value']);
     /** @var CM_Log_ContextFormatter_Interface $contextFormatter */
     $httpClient = $this->mockObject('GuzzleHttp\\Client');
     $sendRequestMethod = $httpClient->mockMethod('send')->set(function (\GuzzleHttp\Message\RequestInterface $request) {
         $this->assertSame('http://cm-janus.dev:8080/stopStream?context={"key":"value"}', urldecode($request->getUrl()));
         $this->assertSame('POST', $request->getMethod());
         $this->assertSame('streamId=foo', $request->getBody()->getContents());
         $this->assertSame('bar', $request->getHeader('Server-Key'));
         $body = $this->mockClass('\\GuzzleHttp\\Post\\PostBody')->newInstanceWithoutConstructor();
         $body->mockMethod('getContents')->set('{"success":"Stream stopped"}');
         $response = $this->mockClass('\\GuzzleHttp\\Message\\Response')->newInstanceWithoutConstructor();
         $response->mockMethod('getBody')->set($body);
         return $response;
     });
     /** @var GuzzleHttp\Client $httpClient */
     $location = $this->mockClass('CM_Geo_Point')->newInstanceWithoutConstructor();
     /** @var CM_Geo_Point $location */
     $server = new CM_Janus_Server(0, 'bar', 'http://cm-janus.dev:8080', 'ws://cm-janus.dev:8188', [], $location);
     $api = new CM_Janus_HttpApiClient($httpClient, $contextFormatter);
     $api->stopStream($server, 'foo');
     $this->assertSame(1, $sendRequestMethod->getCallCount());
 }
Example #2
0
 /**
  * @param CM_Model_Stream_Abstract $stream
  * @throws CM_Exception_Invalid
  * @throws CM_Janus_StopStreamError
  */
 protected function _stopStream(CM_Model_Stream_Abstract $stream)
 {
     /** @var $streamChannel CM_Model_StreamChannel_Media */
     $streamChannel = $stream->getStreamChannel();
     $server = $this->_serverList->getById($streamChannel->getServerId());
     $result = $this->_httpApiClient->stopStream($server, $stream->getKey());
     if (array_key_exists('error', $result)) {
         throw new CM_Janus_StopStreamError($result['error']);
     }
 }