private function subscribePlatform($platform, $topic)
 {
     foreach ($this->sns->getPaginator('ListEndpointsByPlatformApplication', ['PlatformApplicationArn' => $this->arns[$platform]]) as $endpoint) {
         $this->logger && $this->logger->info('Subscribing device to topic', ['device' => $endpoint['EndpointArn'], 'topic' => $topic, 'platform' => $platform]);
         try {
             $this->sns->subscribe(['TopicArn' => $topic, 'Protocol' => 'application', 'Endpoint' => $endpoint['EndpointArn']]);
         } catch (SnsException $e) {
             $this->logger && $this->logger->info('Error subscribing device to topic', ['device' => $endpoint['EndpointArn'], 'topic' => $topic, 'platform' => $platform, 'exception' => $e]);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Enable all devices registered on platform
  *
  * @param string $platform
  */
 private function enablePlatform($platform)
 {
     foreach ($this->sns->getPaginator('ListEndpointsByPlatformApplication', ['PlatformApplicationArn' => $this->arns[$platform]]) as $endpoint) {
         if ($endpoint['Attributes']['Enabled'] == "false") {
             try {
                 $this->sns->setEndpointAttributes(['EndpointArn' => $endpoint['EndpointArn'], 'Attributes' => ['Enabled' => "true"]]);
                 $this->logger && $this->logger->info("Enabled {$endpoint['EndpointArn']}");
             } catch (\Exception $e) {
                 $this->logger && $this->logger->error("Failed to push set attributes on {$endpoint['EndpointArn']}", ['exception' => $e, 'endpoint' => $endpoint]);
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Enable all devices registered on platform
  *
  * @param string $platform
  */
 private function removeFromPlatform($platform)
 {
     foreach ($this->sns->getPaginator('ListEndpointsByPlatformApplication', ['PlatformApplicationArn' => $this->arns[$platform]]) as $endpoint) {
         if ($endpoint['Attributes']['Enabled'] == "false") {
             try {
                 $this->sns->deleteEndpoint(['EndpointArn' => $endpoint['EndpointArn']]);
                 $this->logger && $this->logger->info("Removed {$endpoint['EndpointArn']}");
             } catch (\Exception $e) {
                 $this->logger && $this->logger->error("Failed to remove endpoint {$endpoint['EndpointArn']}", ['exception' => $e, 'endpoint' => $endpoint]);
             }
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Send a message to all devices on a platform
  *
  * @param Message|string $message
  * @param string $platform
  */
 private function broadcastToPlatform($message, $platform)
 {
     if ($this->debug) {
         $this->logger && $this->logger->notice("Message would have been sent to {$platform}", ['Message' => $message]);
         return;
     }
     foreach ($this->sns->getPaginator('ListEndpointsByPlatformApplication', ['PlatformApplicationArn' => $this->arns[$platform]]) as $endpoint) {
         if ($endpoint['Attributes']['Enabled'] == "true") {
             try {
                 $this->send($message, $endpoint['EndpointArn']);
             } catch (\Exception $e) {
                 $this->logger && $this->logger->error("Failed to push to {$endpoint['EndpointArn']}", ['Message' => $message, 'Exception' => $e, 'Endpoint' => $endpoint]);
             }
         } else {
             $this->logger && $this->logger->info("Disabled endpoint {$endpoint['EndpointArn']}", ['Message' => $message, 'Endpoint' => $endpoint]);
         }
     }
 }