Skip to content

Commit

Permalink
Initial beta release
Browse files Browse the repository at this point in the history
- Fixed example code
- Added debugging for blank SSE events
- Changed next_chat_message to get_message()
  • Loading branch information
thelabcat committed May 4, 2024
1 parent 2d50a0a commit 8a6f91d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ from cocorum import ssechat
chat = ssechat.SSEChat(stream_id = STREAM_ID) #Stream ID can be base 10 or 36
chat.clear_mailbox() #Erase messages that were still visible before we connected
msg = True
while msg:
msg = chat.next_chat_message #Hangs until a new message arrives
while True:
msg = chat.get_message() #Hangs until a new message arrives
print(msg.user.username, ":", msg)
print("Chat has closed.")
```

## Conclusion
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "cocorum"
version = "0.5.3"
version = "1.0.0"
keywords = ["rumble", "api", "wrapper", "livestream"]
authors = [
{ name="Wilbur Jaywright", email="[email protected]" },
Expand All @@ -20,7 +20,7 @@ classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: OS Independent",
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
]

[project.urls]
Expand Down
11 changes: 4 additions & 7 deletions src/cocorum/ssechat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
chat = ssechat.SSEChat(stream_id = STREAM_ID) #Stream ID can be base 10 or 36
chat.clear_mailbox() #Erase messages that were still visible before we connected
msg = True
while msg:
msg = chat.next_chat_message #Hangs until a new message arrives
while True:
msg = chat.get_message() #Hangs until a new message arrives
print(msg.user.username, ":", msg)
print("Chat has closed.")
```
S.D.G."""

Expand Down Expand Up @@ -317,6 +314,7 @@ def next_jsondata(self):
self.chat_running = False #Chat has been closed
return
if not message.data: #Blank SSE event
print("Blank SSE event:", message)
#Self recursion should work so long as we don't get dozens of blank events in a row
return self.next_jsondata()

Expand Down Expand Up @@ -381,8 +379,7 @@ def stream_id_b10(self):
"""The chat ID in user"""
return utils.stream_id_36_to_10(self.stream_id)

@property
def next_chat_message(self):
def get_message(self):
"""Return the next chat message (parsing any additional data), waits for it to come in, returns None if chat closed"""
if not self.__mailbox: #We don't already have messages
#JSON data is coming in, but it isn't of messages type'
Expand Down

0 comments on commit 8a6f91d

Please sign in to comment.