Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presence engine - states and events #178

Merged
merged 16 commits into from
Feb 8, 2024
Merged
16 changes: 9 additions & 7 deletions examples/cli_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pubnub.pnconfiguration import PNConfiguration

parser = argparse.ArgumentParser(description="Chat with others using PubNub")
parser.add_argument("name", help="Your name")
parser.add_argument("channel", help="The channel you want to join")
parser.add_argument("-n", metavar="name", help="Your name", default=None, required=False)
parser.add_argument("-c", metavar="channel", help="The channel you want to join", default=None, required=False)
args = parser.parse_args()


Expand All @@ -17,11 +17,13 @@ def message(self, pubnub, message):
print(f"{message.publisher}> {message.message}\n")

def presence(self, pubnub, presence):
print(f"{presence.event} {presence.uuid}\n")
print(f"-- {presence.uuid} {'joined' if presence.event == 'join' else 'left'} \n")

def status(self, pubnub, status):
# print(status.__dict__)
pass
if status.is_error():
print(f"! Error: {status.error_data}")
else:
print(f"* Status: {status.category.name}")


async def async_input():
Expand All @@ -31,8 +33,8 @@ async def async_input():


async def main():
name = args.name if args.name else input("Enter your name: ")
channel = args.channel if args.channel else input("Enter the channel you want to join: ")
name = args.name if hasattr(args, "name") else input("Enter your name: ")
channel = args.channel if hasattr(args, "channel") else input("Enter the channel you want to join: ")

print("Welcome to the chat room. Type 'exit' to leave the chat.")

Expand Down
2 changes: 1 addition & 1 deletion pubnub/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def string(cls, method):
return "PATCH"


class PNStatusCategory(object):
class PNStatusCategory(Enum):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: For most of situations this doesn't change anything. Enum inherits from object (which is leftover from py2.7 btw) and only adds functionality like this status.category.name to extract the name based on the value

PNUnknownCategory = 1
PNAcknowledgmentCategory = 2
PNAccessDeniedCategory = 3
Expand Down
3 changes: 0 additions & 3 deletions pubnub/event_engine/statemachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ def trigger(self, event: events.PNEvent) -> states.PNTransition:
self.logger.debug(f'Current State: {self.get_state_name()}')
self.logger.debug(f'Triggered event: {event.__class__.__name__}({event.__dict__}) on {self.get_state_name()}')

if (isinstance(event, events.SubscriptionChangedEvent)):
print(f"SubscriptionChangedEvent in : {self.get_state_name()}")

if not self._enabled:
self.logger.error('EventEngine is not enabled')
return False
Expand Down
Loading