BxStrmEngineNGINX.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 isSreamFromBrowser()
  14. {
  15. return false;
  16. }
  17. public function getViewersNum($sStreamKey)
  18. {
  19. $sHost = getParam('bx_stream_server_host');
  20. $sApp = getParam('bx_stream_app');
  21. if (!$sHost || !$sApp)
  22. return false;
  23. $sUrl = str_replace(
  24. ['{host}', '{app}', '{key}'],
  25. [$sHost, $sApp, $sStreamKey],
  26. getParam('bx_stream_server_nginx_stats_url')
  27. );
  28. $s = bx_file_get_contents($sUrl);
  29. if (!$s)
  30. return false;
  31. $o = @simplexml_load_string ($s);
  32. if (!$o)
  33. return false;
  34. foreach ($o->server->application as $oApp) {
  35. if ($sApp == $oApp->name && $sStreamKey == $oApp->live->stream->name)
  36. return (int)$oApp->live->stream->nclients;
  37. }
  38. return false;
  39. }
  40. public function getRtmpSettings($sStreamKey)
  41. {
  42. $sHost = getParam('bx_stream_server_host');
  43. $sApp = getParam('bx_stream_app');
  44. if (!$sHost || !$sApp)
  45. return false;
  46. $sBaseUrl = "rtmp://$sHost:1935/$sApp";
  47. $sParams = '';
  48. if (getParam('bx_stream_server_nginx_auth'))
  49. $sParams = '?s=' . base_convert(substr(md5(BX_DOL_SECRET . $sStreamKey), -4), 16, 36);
  50. return ['server' => $sBaseUrl, 'key' => $sStreamKey . $sParams];
  51. }
  52. public function getRtmpIngestUrl($sStreamKey)
  53. {
  54. if (!($a = $this->getRtmpSettings($sStreamKey)))
  55. return false;
  56. list ($sBaseUrl, $sStreamKey) = $a;
  57. return $a['server'] . '/' . $a['key'];
  58. }
  59. public function getWebrtcIngestUrl($sStreamKey)
  60. {
  61. return false;
  62. }
  63. }
  64. /** @} */