BxDolSocketsSoketi.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolSocketsSoketi extends BxDolSockets
  10. {
  11. protected $_sKey;
  12. protected $_sJsClass;
  13. protected $_sJsObject;
  14. protected function __construct()
  15. {
  16. parent::__construct();
  17. $this->_sKey = getParam('sys_sockets_key');
  18. $this->_sJsClass = 'BxDolSockets';
  19. $this->_sJsObject = 'oBxDolSockets';
  20. }
  21. public function sendEvent($sSocket, $iContentId, $sEvent, $sMessage)
  22. {
  23. try {
  24. $oPusher = new Pusher\Pusher($this->_sKey, getParam('sys_sockets_secret'), getParam('sys_sockets_app_id'), [
  25. 'host' => $this->_sHost,
  26. 'port' => $this->_sPort,
  27. 'scheme' => $this->_sScheme,
  28. 'encrypted' => true,
  29. 'useTLS' => false,
  30. ]);
  31. $b = $oPusher->trigger($sSocket . '_' . $iContentId, $sEvent, $sMessage);
  32. }
  33. catch (Exception $oException) {
  34. $this->writeLog($oException->getFile() . ':' . $oException->getLine() . ' ' . $oException->getMessage());
  35. return false;
  36. }
  37. }
  38. public function getJsCode()
  39. {
  40. $sMask = "{var} {object} = new {class}({params});";
  41. $aParams = [
  42. 'sKey' => $this->_sKey,
  43. 'sHost' => $this->_sHost,
  44. 'sPort' => $this->_sPort,
  45. ];
  46. return bx_replace_markers($sMask, [
  47. 'var' => 'var',
  48. 'object' => $this->_sJsObject,
  49. 'class' => $this->_sJsClass,
  50. 'params' => json_encode($aParams)
  51. ]);
  52. }
  53. }
  54. /** @} */