mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
d0313b9697
- Add credential saving for Twitch - Sync NoTwitch with upstream to allow for API and EventSub access - Add Twitch Connected Account Info and Twitch Request User Info nodes Co-authored-by: Eroax <eroaxe.business@gmail.com> Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/56 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
70 lines
1.1 KiB
GDScript
70 lines
1.1 KiB
GDScript
extends Websocket_Client
|
|
|
|
const eventsub_url := "wss://eventsub.wss.twitch.tv/ws"
|
|
|
|
## Stores the "session id" for this EventSub connection.
|
|
var session_id
|
|
|
|
var connection : Twitch_Connection
|
|
|
|
signal notif_received(data)
|
|
|
|
signal welcome_received()
|
|
|
|
|
|
func _init(owner):
|
|
|
|
connection = owner
|
|
|
|
packet_received.connect(data_received)
|
|
|
|
|
|
func connect_to_eventsub(events : Array[Twitch_Connection.EventSub_Subscription] = []):
|
|
|
|
connect_to_url(eventsub_url)
|
|
await welcome_received
|
|
|
|
if events.is_empty():
|
|
|
|
return
|
|
|
|
|
|
var responses : Array[Twitch_Connection.HTTPResponse]
|
|
|
|
for all in events:
|
|
|
|
responses.append(connection.add_eventsub_subscription(all))
|
|
|
|
|
|
return responses
|
|
|
|
|
|
func data_received(packet : PackedByteArray):
|
|
|
|
var info = JSON.parse_string(packet.get_string_from_utf8())
|
|
|
|
match info.metadata.message_type:
|
|
|
|
"session_welcome":
|
|
|
|
session_id = info.payload.session.id
|
|
welcome_received.emit()
|
|
|
|
|
|
"session_ping":
|
|
|
|
send_pong(info)
|
|
|
|
|
|
"notification":
|
|
|
|
notif_received.emit(info)
|
|
|
|
|
|
|
|
|
|
func send_pong(pong):
|
|
|
|
pong.metadata.message_type = "session_pong"
|
|
send_text(str(pong))
|
|
|