Example #1
0
 /**
  * @param string          $method
  * @param CM_Janus_Server $server
  * @param string          $path
  * @param array|null      $body
  * @return string
  * @throws CM_Exception_Invalid
  */
 protected function _request($method, CM_Janus_Server $server, $path, array $body = null)
 {
     $context = CM_Service_Manager::getInstance()->getLogger()->getContext();
     $appContext = $this->_contextFormatter->formatAppContext($context);
     $url = $server->getHttpAddress() . $path;
     $body = (array) $body;
     $options = ['query' => ['context' => CM_Util::jsonEncode($appContext)], 'body' => $body, 'headers' => ['Server-Key' => $server->getKey()]];
     $request = $this->_httpClient->createRequest($method, $url, $options);
     try {
         $response = $this->_httpClient->send($request);
     } catch (GuzzleHttp\Exception\TransferException $e) {
         throw new CM_Exception_Invalid('Fetching contents from url failed', null, ['url' => $url, 'originalExceptionMessage' => $e->getMessage()]);
     }
     $body = $response->getBody();
     if (null === $body) {
         throw new CM_Exception_Invalid('Empty response body');
     }
     return $body->getContents();
 }
Example #2
0
 public function testConstructorAndBasicGetters()
 {
     $serverId = 1;
     $key = 'server-key';
     $httpAddress = 'http://api';
     $webSocketAddress = 'ws://connect:8810';
     $pluginList = ['my-plugin'];
     $location = CMTest_TH::createGeoPoint();
     $iceServerList = ['ice-server'];
     $server = new CM_Janus_Server($serverId, $key, $httpAddress, $webSocketAddress, $pluginList, $location, $iceServerList);
     $this->assertSame($serverId, $server->getId());
     $this->assertSame($key, $server->getKey());
     $this->assertSame($httpAddress, $server->getHttpAddress());
     $this->assertSame($webSocketAddress, $server->getWebSocketAddress());
     $this->assertSame($pluginList, $server->getPluginList());
     $this->assertSame($location, $server->getLocation());
     $this->assertSame($iceServerList, $server->getIceServerList());
 }