mirror of
https://github.com/onyx-and-iris/streamlabs-socketio-py
synced 2024-11-23 07:40:49 +00:00
use sio.sleep in example. add note about sio.wait
This commit is contained in:
parent
feaf06e639
commit
54a323fc81
16
README.md
16
README.md
@ -43,25 +43,21 @@ def on_twitch_event(event, msg):
|
||||
print(f"{event}: {msg.attrs()}")
|
||||
|
||||
|
||||
def register_callbacks(client):
|
||||
def main():
|
||||
with streamlabsio.connect(token="<apikey>") as client:
|
||||
client.obs.on("streamlabs", on_twitch_event)
|
||||
client.obs.on("twitch_account", on_twitch_event)
|
||||
|
||||
|
||||
def main():
|
||||
with streamlabsio.connect(token="<apikey>") as client:
|
||||
worker = Thread(target=register_callbacks, args=(client,), daemon=True)
|
||||
worker.start()
|
||||
|
||||
while cmd := input("<Enter> to exit\n"):
|
||||
if not cmd:
|
||||
break
|
||||
# run for 30 seconds then disconnect client from server
|
||||
client.sio.sleep(30)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
```
|
||||
|
||||
note. From the [SocketIO docs](https://python-socketio.readthedocs.io/en/latest/client.html#managing-background-tasks), `client.sio.wait()` may be used if your application has nothing to do in the main thread.
|
||||
|
||||
### Attributes
|
||||
|
||||
For event messages you may inspect the available attributes using `attrs()`.
|
||||
|
18
__main__.py
18
__main__.py
@ -1,5 +1,4 @@
|
||||
import logging
|
||||
from threading import Thread
|
||||
|
||||
import streamlabsio
|
||||
|
||||
@ -15,22 +14,19 @@ def on_twitch_event(event, msg):
|
||||
print(f"Received follow from {msg.name}")
|
||||
elif event == "bits":
|
||||
print(f"{msg.name} donated {msg.amount} bits! With message: {msg.message}")
|
||||
elif event == "donation":
|
||||
print(f"{msg.name} donated {msg.formatted_amount}! With message: {msg.message}")
|
||||
|
||||
|
||||
def register_callbacks(client):
|
||||
def main():
|
||||
# read token from config.toml
|
||||
with streamlabsio.connect() as client:
|
||||
client.obs.on("streamlabs", on_twitch_event)
|
||||
client.obs.on("twitch_account", on_twitch_event)
|
||||
client.obs.on("youtube_account", on_youtube_event)
|
||||
|
||||
|
||||
def main():
|
||||
with streamlabsio.connect() as client:
|
||||
worker = Thread(target=register_callbacks, args=(client,), daemon=True)
|
||||
worker.start()
|
||||
|
||||
while cmd := input("<Enter> to exit\n"):
|
||||
if not cmd:
|
||||
break
|
||||
# run for 30 seconds then disconnect client from server
|
||||
client.sio.sleep(30)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user