Example #1
0
 public function testSynchronizeMissingInPhp()
 {
     $streamChannel = CMTest_TH::createStreamChannel(null, CM_Janus_Service::getTypeStatic());
     $streamChannelKey = $streamChannel->getKey();
     $streamPublish = CMTest_TH::createStreamPublish(null, $streamChannel);
     $streamPublishKey = $streamPublish->getKey();
     $streamSubscribe = CMTest_TH::createStreamSubscribe(null, $streamChannel);
     $streamSubscribeKey = $streamSubscribe->getKey();
     $streamChannel2 = CMTest_TH::createStreamChannel(null, CM_Janus_Service::getTypeStatic());
     $streamChannelKey2 = $streamChannel2->getKey();
     CMTest_TH::createStreamPublish(null, $streamChannel2);
     //to make channel non empty
     $location = $this->mockClass('CM_Geo_Point')->newInstanceWithoutConstructor();
     $server1 = $this->mockClass('CM_Janus_Server')->newInstance([1, 'key', 'http://mock', 'ws://mock', [], $location]);
     /** @var CM_Janus_ServerList|\Mocka\AbstractClassTrait $serverList */
     $serverList = $this->mockObject('CM_Janus_ServerList');
     $serverList->mockMethod('getAll')->set([$server1]);
     $status = [['id' => $streamPublishKey, 'channelName' => $streamChannelKey, 'isPublish' => true], ['id' => $streamSubscribeKey, 'channelName' => $streamChannelKey, 'isPublish' => false], ['id' => 'absentStreamKey', 'channelName' => 'absentChannelKey', 'isPublish' => false], ['id' => 'absentStreamKey2', 'channelName' => $streamChannelKey2, 'isPublish' => true]];
     $httpApiClient = $this->mockClass('CM_Janus_HttpApiClient')->newInstanceWithoutConstructor();
     $httpApiClient->mockMethod('fetchStatus')->set(function (CM_Janus_Server $passedServer) use($server1, $status) {
         $this->assertSame($server1, $passedServer);
         return $status;
     });
     $stopStreamMethod = $httpApiClient->mockMethod('stopStream')->at(0, function ($server, $streamKey) use($streamPublishKey, $server1) {
         $this->assertEquals($server1, $server);
         $this->assertSame($streamPublishKey, $streamKey);
     })->at(1, function ($server, $streamKey) use($streamSubscribeKey, $server1) {
         $this->assertEquals($server1, $server);
         $this->assertSame($streamSubscribeKey, $streamKey);
     })->at(2, function ($server, $streamKey) use($server1) {
         $this->assertEquals($server1, $server);
         $this->assertSame('absentStreamKey', $streamKey);
     })->at(3, function ($server, $streamKey) use($server1) {
         $this->assertEquals($server1, $server);
         $this->assertSame('absentStreamKey2', $streamKey);
     });
     /** @var CM_Janus_HttpApiClient $httpApiClient */
     $janus = new CM_Janus_Service($serverList, $httpApiClient);
     $janus->getStreamRepository()->removeStream($streamPublish);
     $janus->getStreamRepository()->removeStream($streamSubscribe);
     $janus->synchronize();
     $this->assertSame(4, $stopStreamMethod->getCallCount());
 }
Example #2
0
 /**
  * @param CM_Janus_Service $janus
  * @param string           $serverKey
  * @throws CM_Exception_AuthFailed
  */
 protected static function _authenticate(CM_Janus_Service $janus, $serverKey)
 {
     if (!$janus->getServerList()->findByKey($serverKey)) {
         throw new CM_Exception_AuthFailed('Invalid serverKey');
     }
 }
Example #3
0
File: TH.php Project: cargomedia/cm
 /**
  * @param int|null    $type
  * @param int|null    $adapterType
  * @param string|null $mediaId
  * @return CM_Model_StreamChannel_Abstract
  */
 public static function createStreamChannel($type = null, $adapterType = null, $mediaId = null)
 {
     if (null === $type) {
         $type = CM_Model_StreamChannel_Media::getTypeStatic();
     }
     if (null === $adapterType) {
         $adapterType = CM_Janus_Service::getTypeStatic();
     }
     $data = array('key' => rand(1, 10000) . '_' . rand(1, 100));
     $className = CM_Model_Abstract::getClassName($type);
     if ('CM_Model_StreamChannel_Media' === $className || is_subclass_of($className, 'CM_Model_StreamChannel_Media')) {
         $mediaId = null !== $mediaId ? (string) $mediaId : null;
         $data['width'] = 480;
         $data['height'] = 720;
         $data['serverId'] = 1;
         $data['adapterType'] = $adapterType;
         $data['mediaId'] = $mediaId;
     }
     return CM_Model_StreamChannel_Abstract::createType($type, $data);
 }