Esempio n. 1
0
 def subscribe(self):
     r = self.rc.post('/restapi/v1.0/subscription',
                      json=self._request_body())
     self.subscription = r.json()
     pnconfig = PNConfiguration()
     pnconfig.subscribe_key = self.subscription['deliveryMode'][
         'subscriberKey']
     pnconfig.daemon = True
     pnconfig.reconnect_policy = PNReconnectionPolicy.EXPONENTIAL
     self.pubnub = PubNubSDK(pnconfig)
     self.pubnub.add_listener(self.callback)
     self.pubnub.subscribe().channels(
         self.subscription['deliveryMode']['address']).execute()
Esempio n. 2
0
import platform 

from pubnub.callbacks import SubscribeCallback
from pubnub.pnconfiguration import PNConfiguration, PNHeartbeatNotificationOptions
from pubnub.pubnub import PubNub

#import keys.keys as keys

my_channel = "my_channel_1234"

pnconfig = PNConfiguration()
pnconfig.subscribe_key = 'demo'
pnconfig.publish_key = 'demo'
# pnconfig.heartbeat_notification_options = PNHeartbeatNotificationOptions.ALL

pnconfig.daemon = True

my_pubnub = PubNub(pnconfig)


def my_publish_callback(envelope, status):
    print('my_publish_callback', status.is_error(), datetime.datetime.now())


class MySubscribeCallback(SubscribeCallback):
    def presence(self, pubnub, presence):
        print('presence', pubnub, presence)

    def status(self, pubnub, status):
        print('status.category', status.category, datetime.datetime.now())