{"id":275743,"date":"2016-03-09T14:33:02","date_gmt":"2016-03-09T11:33:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=275743"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=275743","title":{"rendered":"Asterisk \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0437\u0432\u043e\u043d\u043a\u0430\u0445 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u0447\u0435\u0440\u0435\u0437 Notifications"},"content":{"rendered":"<p>       \u0412 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u043b\u0435\u0444\u043e\u043d 8800, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043a\u0430\u0437 \u0431\u0435\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0430\u0439\u0442\u0443. \u0414\u043b\u044f \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0437\u0432\u043e\u043d\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f call-\u0446\u0435\u043d\u0442\u0440, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430.<\/p>\n<p>  \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u0431\u044b\u043b\u0430 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0437\u0432\u043e\u043d\u043a\u0430 \u043f\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0431\u0430\u0437\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0422\u0430\u043a \u043a\u0430\u043a cron \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0431\u044b\u043b\u0438 \u0431\u044b \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0440\u0435\u0434\u043a\u0438\u043c\u0438 (\u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c 1 \u0440\u0430\u0437 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443), \u0442\u043e \u0437\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u0431\u044b\u043b \u0432\u0437\u044f\u0442 \u0434\u0435\u043c\u043e\u043d \u043d\u0430 php, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u0430\u043d\u0438\u0440\u0443\u0435\u0442 \u043a\u0430\u043d\u0430\u043b\u044b \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0437\u0432\u043e\u043d\u043a\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u0414\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0431\u044b\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d memcached.<\/p>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f Asterisk\u2019a \u2014 11.15.1.<br \/>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 API \u0441\u0432\u044f\u0437\u043a\u0438 php \u0438 Asteriska\u2019a \u2014 <a href=\"https:\/\/github.com\/marcelog\/PAMI\">\u043c\u043e\u0434\u0443\u043b\u044c PAMI<\/a>.<\/p>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u0435\u043c\u043e\u043d\u0430 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u043a\u0438:<\/p>\n<pre><code class=\"php\">class AsteriskDaemon {     private $asterisk;     private $memcache;      public function __construct()     {         $this-&gt;asterisk = new ClientImpl([             ...         ]);          $memcache = new Memcached;         $memcache-&gt;connect('127.0.0.1', '11211');                  $this-&gt;memcache = $memcache;     }      public function start()     {         $asterisk = $this-&gt;asterisk;          $loop = Factory::create();          \/\/ add periodic timer         $loop-&gt;addPeriodicTimer(1, function () use (&$asterisk) {             $pid = \\pcntl_fork();             if ($pid &lt; 0) { \/\/ \u043e\u0448\u0438\u0431\u043a\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f exit;             }elseif ($pid) { \/\/ \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c, \u0436\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u0432                 \\pcntl_waitpid($pid, $status, WUNTRACED);                 if ($status &gt; 0) {                     \/\/ \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u043a\u0430\u043d\u0430\u043b\u0435, \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0435\u043c                     $asterisk-&gt;close();                     usleep(1000);                     $asterisk-&gt;open();                 }                  return;             } else {                 \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430                 try {                     $asterisk-&gt;process();                     exit(0);                 } catch (\\Exception $e) {                     exit(1);                 }             }         });          \/\/ \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432         $loop-&gt;addPeriodicTimer(30, function () {             while (($pid = \\pcntl_waitpid(0, $status, WNOHANG)) &gt; 0) {                 echo &quot;process exit. pid:&quot; . $pid . &quot;. exit code:&quot; . $status . &quot;\\n&quot;;             }         });          $loop-&gt;run();     } } <\/code><\/pre>\n<p>  \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f: \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u0438 \u0440\u0443\u0447\u043d\u043e\u0439 \u0440\u0430\u0437\u0431\u043e\u0440 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 CoreShowChannel, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0441\u0435 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443.<\/p>\n<h4>\u041f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/h4>\n<p>  \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0434\u0435\u043c\u043e\u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 AsteriskEventListener:<\/p>\n<pre><code class=\"php\">... $this-&gt;asterisk-&gt;registerEventListener(new AsteriskEventListener($memcache), function (EventMessage $event) {     \/\/ \u041f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 \u043a\u0430\u043d\u0430\u043b\u0430\u043c\u0438     return $event instanceof BridgeEvent; }); $this-&gt;asterisk-&gt;open(); ... <\/code><\/pre>\n<p>  \u0418 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u043d\u0438\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c:<\/p>\n<pre><code class=\"php\">class AsteriskEventListener implements IEventListener {     private $memcache;     private $bridges = [];      public function __construct($memcache)     {         $this-&gt;memcache = $memcache;     }      private function addBridge($phone1, $phone2)     {         $bFind = false;          if ($this-&gt;bridges) {             foreach ($this-&gt;bridges as $bridge) {                 if (in_array($phone1, $bridge) && in_array($phone2, $bridge)) {                     $bFind = true;                 }             }         }          if (!$bFind) {             $this-&gt;bridges[] = [                 $phone1,                 $phone2             ];             $bFind = true;         }          return $bFind;     }      private function deleteBridge($phone1, $phone2 = null)     {         if ($this-&gt;bridges) {             foreach ($this-&gt;bridges as $key =&gt; $bridge) {                 if (in_array($phone1, $bridge) && (!$phone2 || ($phone2 && in_array($phone2, $bridge)))) {                     unset($this-&gt;bridges[$key]);                 }             }         }     }      public function handle(EventMessage $event)     {         \/\/ \u0414\u0435\u043b\u0430\u0435\u043c \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u0448\u043b\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f\/\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u043d\u0430\u043b\u0430         if ($event instanceof BridgeEvent) {             $this-&gt;bridges = $this-&gt;memcache-&gt;getKey('asterisk-bridges');              $state = $event-&gt;getBridgeState();             $caller1 = $event-&gt;getCallerID1();             $caller2 = $event-&gt;getCallerID2();             if ($state == 'Link') { \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u0430\u043d\u0430\u043b\u0430                 $this-&gt;addBridge($caller1, $caller2);             } else { \/\/ \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u043d\u0430\u043b\u0430                 $this-&gt;deleteBridge($caller1, $caller2);             }              $this-&gt;memcache-&gt;setKey('asterisk-bridges', $this-&gt;bridges);         }     } } <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043a\u0430\u043d\u0430\u043b\u043e\u0432. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0432\u043e\u043d\u043a\u0430 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430\u043c\u0438 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 call-\u0446\u0435\u043d\u0442\u0440\u0430 \u043d\u0430 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430 \u043e\u0431\u0430 \u043a\u0430\u043d\u0430\u043b\u0430 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 \u0442\u0435\u043c, \u043a\u0442\u043e \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u043b, \u0438 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u0441\u0432\u044f\u0437\u043a\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/p>\n<h4>\u0420\u0443\u0447\u043d\u043e\u0439 \u0440\u0430\u0437\u0431\u043e\u0440 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 CoreShowChannel<\/h4>\n<p>  \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u043c\u043e\u043d, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 CoreShowChannel \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u0430\u043c Asterisk \u0435\u0433\u043e \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442:<\/p>\n<pre><code class=\"php\">... \/\/ \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 try {     $message = $asterisk-&gt;send(new CoreShowChannelsAction());     $events = $message-&gt;getEvents();     $this-&gt;parse($events);     $asterisk-&gt;process();      exit(0); } catch (\\Exception $e) {     exit(1); } ... &lt;source&gt; \u0418 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0440\u0430\u0437\u0431\u043e\u0440\u0430:  &lt;source lang=&quot;php&quot;&gt; private function parse($events) {     foreach ($events as $event) {         if ($event instanceof CoreShowChannelEvent) {             $caller1 = $event-&gt;getKey('CallerIDnum');             $caller2 = $event-&gt;getKey('ConnectedLineNum');                          $this-&gt;bridges = $this-&gt;memcache-&gt;getKey('asterisk-bridges');              $this-&gt;addBridge($caller1, $caller2);              $this-&gt;memcache-&gt;setKey('asterisk-bridges', $this-&gt;bridges);         }      } } <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u0435 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u043c\u0435\u0440\u0430 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u043f\u0440\u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043e\u0442 \u043a\u0430\u043d\u0430\u043b\u0430. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0440\u0430\u0437\u0440\u044b\u0432\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"php\">... $this-&gt;asterisk-&gt;registerEventListener(new AsteriskEventListener(), function (EventMessage $event) {     return $event instanceof HangupEvent; }); $this-&gt;asterisk-&gt;open(); ... <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0440\u0430\u0437\u0440\u044b\u0432\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"php\">... public function handle(EventMessage $event) {     if ($event instanceof HangupEvent) {         $this-&gt;bridges = $this-&gt;memcache-&gt;getKey('asterisk-bridges');          $caller1 = $event-&gt;getKey('CallerIDNum');         $caller2 = $event-&gt;getKey('ConnectedLineNum');         $this-&gt;deleteBridge($caller1);         $this-&gt;deleteBridge($caller2);          $this-&gt;memcache-&gt;setKey('asterisk-bridges', $this-&gt;bridges);     } } ... <\/code><\/pre>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c\u0438 asterisk \u0447\u0430\u0441\u0442\u043e \u043f\u0430\u0434\u0430\u043b, \u0438, \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u0442\u0435\u0440\u044f\u043b\u0438\u0441\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0432\u043e\u043d\u043a\u0438. \u0422\u0430\u043a \u0436\u0435 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u0435 \u043d\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u0437\u0432\u043e\u043d\u043a\u0438 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0441 call-\u0446\u0435\u043d\u0442\u0440\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u043e\u043c\u0435\u0440 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430 \u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0431\u044b\u043b\u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u0430\u043d\u0430\u043b\u0430\u0445 (\u041f\u0435\u0440\u0432\u044b\u0439 \u043a\u0430\u043d\u0430\u043b \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 call-\u0446\u0435\u043d\u0442\u0440 \u0438 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430, \u0432\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u043d\u0430\u043b \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 call-\u0446\u0435\u043d\u0442\u0440 \u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0430).<\/p>\n<h4>\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0437\u0432\u043e\u043d\u043a\u0435 \u0447\u0435\u0440\u0435\u0437 Notifications<\/h4>\n<p>  \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0437\u0432\u043e\u043d\u043a\u0430\u0445 \u0431\u044b\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/github.com\/Yaffle\/EventSource\">event-source-polyfill<\/a> \u0438 long-pull \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440. \u041d\u0430\u043f\u043e\u043c\u043d\u044e \u043c\u044b \u0445\u0440\u0430\u043d\u0438\u043c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0437\u0432\u043e\u043d\u043a\u0438 \u0432 memcached.<\/p>\n<p>  \u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0430, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0432\u043a\u043b\u0430\u0434\u043e\u043a \u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u044b\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/www.npmjs.com\/package\/wormhole.js\">wormhole<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u0430\u043d\u0430\u043b\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u043a\u043b\u0430\u0434\u043a\u0430\u043c\u0438.<\/p>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<pre><code class=\"javascript\">(function ($) {     $.getCall = function () {         if (localStorage.callTitle !== undefined && localStorage.callSuccess === undefined) {             var notification,                 title = localStorage.callTitle,                 options = {                     body: localStorage.callText,                     icon: localStorage.callImage                 },                 eventNotification = function () {                     window.open(localStorage.callUrl);                 };              if (!('Notification' in window)) {                 console.error('This browser does not support desktop notification');             } else if (Notification.permission === 'granted') {                 notification = new Notification(title, options);                 notification.onclick = eventNotification;             } else if (Notification.permission !== 'denied') {                 Notification.requestPermission(function (permission) {                     if (permission === 'granted') {                         notification = new Notification(title, options);                         notification.onclick = eventNotification;                     }                 });             }              localStorage.callSuccess = true;         }     };      \/\/ \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 \u0432\u043a\u043b\u0430\u0434\u043a\u0435     wormhole().on('master', function () {         var es = new EventSource('\/check-call');         es.addEventListener('message', function (res) {             var data = JSON.parse(res.data);             if (data['id']) {                 localStorage.callTitle = data['title'];                 localStorage.callText = data['text'];                 localStorage.callImage = data['img'];                 localStorage.callUrl = data['url'];             } else {                 delete localStorage.callTitle;                 delete localStorage.callText;                 delete localStorage.callImage;                 delete localStorage.callUrl;                 delete localStorage.callSuccess;             }         });     }); })(jQuery);  setInterval(function () {     $.getCall(); }, 1000); <\/code><\/pre>\n<p>  \u0418 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432:<\/p>\n<pre><code class=\"php\">public function checkCall() {     header('Content-Type: text\/event-stream');     header('Cache-Control: no-cache');     header('Access-Control-Allow-Origin: *');      \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u043e\u043c\u0435\u0440\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430     $managerPhone = $_SESSION['phone'];      $user = null;     $clientPhone = $this-&gt;getPhone($managerPhone);     if ($clientPhone) {         $user = User::find()-&gt;where(['phone' =&gt; $clientPhone])-&gt;one();     }      if ($user) { \/\/ \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u044f \u0434\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u0435\u0441\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0430\u0439\u0434\u0435\u043d         echo &quot;retry: 30000\\n&quot;;     } else {         echo &quot;retry: 3000\\n&quot;;     }      echo 'id: ' . $managerPhone . &quot;\\n&quot;;      $data = [];     if ($user) {         $data = [             'id' =&gt; $user['id'],             'title' =&gt; '\u041d\u043e\u0432\u044b\u0439 \u0437\u0432\u043e\u043d\u043e\u043a \u043e\u0442 ' . $user['name'],             'text' =&gt; '\u041f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043a\u0430\u0440\u0442\u043e\u0447\u043a\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430',             'img' =&gt; '\/phone.png',             'url' =&gt; '\/user\/' . $user['id']         ];     }      echo &quot;data: &quot; . json_encode($data) . &quot;\\n\\n&quot;; }  \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 public function getPhone($managerPhone) {     $memcache = new Memcached;     $memcache-&gt;addServer('127.0.0.1', '11211');          $extPhone = '';      if (!$managerPhone) {         return $extPhone;     }      $bridges = $memcache-&gt;getKey('asterisk-bridges');     if (!isset($bridges) || !is_array($bridges)) {         return $extPhone;     }      foreach ($bridges as $bridge) {         if (($key = array_search($managerPhone, $bridge)) !== false) {             $extPhone = $bridge[!$key];             break;         }     }      return $extPhone; } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0418\u0442\u043e\u0433\u0438 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f<\/h4>\n<p>  <\/p>\n<ul>\n<li>\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Asterisk\u2019\u043e\u043c \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 Notifications \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043e\u0432.<\/li>\n<li>\u041f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0437\u0432\u043e\u043d\u043a\u043e\u0432.<\/li>\n<li>\u041c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0438\u0441\u043a \u043d\u043e\u043c\u0435\u0440\u0430 \u0432 \u0431\u0430\u0437\u0435 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043a\u0430\u0440\u0442\u043e\u0447\u043a\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/li>\n<li>\u0421\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f \u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0437\u0432\u043e\u043d\u043a\u0430\u0445.<\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/278859\/\"> https:\/\/habrahabr.ru\/post\/278859\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0412 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u043b\u0435\u0444\u043e\u043d 8800, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043a\u0430\u0437 \u0431\u0435\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0430\u0439\u0442\u0443. \u0414\u043b\u044f \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0437\u0432\u043e\u043d\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f call-\u0446\u0435\u043d\u0442\u0440, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430.<\/p>\n<p>  \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u0431\u044b\u043b\u0430 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0437\u0432\u043e\u043d\u043a\u0430 \u043f\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0431\u0430\u0437\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-275743","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/275743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=275743"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/275743\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=275743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=275743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=275743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}