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()}")
|
print(f"{event}: {msg.attrs()}")
|
||||||
|
|
||||||
|
|
||||||
def register_callbacks(client):
|
|
||||||
client.obs.on("streamlabs", on_twitch_event)
|
|
||||||
client.obs.on("twitch_account", on_twitch_event)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
with streamlabsio.connect(token="<apikey>") as client:
|
with streamlabsio.connect(token="<apikey>") as client:
|
||||||
worker = Thread(target=register_callbacks, args=(client,), daemon=True)
|
client.obs.on("streamlabs", on_twitch_event)
|
||||||
worker.start()
|
client.obs.on("twitch_account", on_twitch_event)
|
||||||
|
|
||||||
while cmd := input("<Enter> to exit\n"):
|
# run for 30 seconds then disconnect client from server
|
||||||
if not cmd:
|
client.sio.sleep(30)
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
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
|
### Attributes
|
||||||
|
|
||||||
For event messages you may inspect the available attributes using `attrs()`.
|
For event messages you may inspect the available attributes using `attrs()`.
|
||||||
|
20
__main__.py
20
__main__.py
@ -1,5 +1,4 @@
|
|||||||
import logging
|
import logging
|
||||||
from threading import Thread
|
|
||||||
|
|
||||||
import streamlabsio
|
import streamlabsio
|
||||||
|
|
||||||
@ -15,22 +14,19 @@ def on_twitch_event(event, msg):
|
|||||||
print(f"Received follow from {msg.name}")
|
print(f"Received follow from {msg.name}")
|
||||||
elif event == "bits":
|
elif event == "bits":
|
||||||
print(f"{msg.name} donated {msg.amount} bits! With message: {msg.message}")
|
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):
|
|
||||||
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():
|
def main():
|
||||||
|
# read token from config.toml
|
||||||
with streamlabsio.connect() as client:
|
with streamlabsio.connect() as client:
|
||||||
worker = Thread(target=register_callbacks, args=(client,), daemon=True)
|
client.obs.on("streamlabs", on_twitch_event)
|
||||||
worker.start()
|
client.obs.on("twitch_account", on_twitch_event)
|
||||||
|
client.obs.on("youtube_account", on_youtube_event)
|
||||||
|
|
||||||
while cmd := input("<Enter> to exit\n"):
|
# run for 30 seconds then disconnect client from server
|
||||||
if not cmd:
|
client.sio.sleep(30)
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user