BxStrmEngineNGINX.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Stream Stream
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxStrmEngineNGINX extends BxDol
  12. {
  13. public function getName()
  14. {
  15. return 'NGINX';
  16. }
  17. public function isSreamFromBrowser()
  18. {
  19. return false;
  20. }
  21. public function getViewersNum($sStreamKey)
  22. {
  23. $sHost = getParam('bx_stream_server_host');
  24. $sApp = getParam('bx_stream_app');
  25. if (!$sHost || !$sApp)
  26. return false;
  27. $sUrl = str_replace(
  28. ['{host}', '{app}', '{key}'],
  29. [$sHost, $sApp, $sStreamKey],
  30. getParam('bx_stream_server_nginx_stats_url')
  31. );
  32. $s = bx_file_get_contents($sUrl);
  33. if (!$s)
  34. return false;
  35. $o = @simplexml_load_string ($s);
  36. if (!$o)
  37. return false;
  38. foreach ($o->server->application as $oApp) {
  39. if ($sApp == $oApp->name && $sStreamKey == $oApp->live->stream->name)
  40. return (int)$oApp->live->stream->nclients;
  41. }
  42. return false;
  43. }
  44. public function getRtmpSettings($sStreamKey)
  45. {
  46. $sHost = getParam('bx_stream_server_host');
  47. $sApp = getParam('bx_stream_app');
  48. if (!$sHost || !$sApp)
  49. return false;
  50. $sBaseUrl = "rtmp://$sHost:1935/$sApp";
  51. $sParams = '';
  52. if (getParam('bx_stream_server_nginx_auth'))
  53. $sParams = '?s=' . base_convert(substr(md5(BX_DOL_SECRET . $sStreamKey), -4), 16, 36);
  54. return ['server' => $sBaseUrl, 'key' => $sStreamKey . $sParams];
  55. }
  56. public function getRtmpIngestUrl($sStreamKey)
  57. {
  58. if (!($a = $this->getRtmpSettings($sStreamKey)))
  59. return false;
  60. list ($sBaseUrl, $sStreamKey) = $a;
  61. return $a['server'] . '/' . $a['key'];
  62. }
  63. public function getWebrtcIngestUrl($sStreamKey)
  64. {
  65. return false;
  66. }
  67. }
  68. /** @} */