Skip to content

Instantly share code, notes, and snippets.

@YuzuRyo61
Created November 10, 2023 16:02
Show Gist options
  • Save YuzuRyo61/e1c33d61cb4fa6083af2c78f10f20d41 to your computer and use it in GitHub Desktop.
Save YuzuRyo61/e1c33d61cb4fa6083af2c78f10f20d41 to your computer and use it in GitHub Desktop.
Misskey streaming client for Godot game engine
extends Node2D
## Misskey server address
@export var misskey_server_address: String = "misskey.io"
var _client = WebSocketPeer.new()
func _ready():
_client.connect_to_url("wss://%s/streaming" % misskey_server_address)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
_client.poll()
var state = _client.get_ready_state()
if state == WebSocketPeer.STATE_OPEN:
var connect_channel_dict = {
"type": "connect",
"body": {
"channel": "localTimeline",
"id": "gdmk001"
}
}
_client.send_text(JSON.stringify(connect_channel_dict))
while _client.get_available_packet_count():
var raw = _client.get_packet().get_string_from_utf8()
print(raw)
elif state == WebSocketPeer.STATE_CLOSED:
var code = _client.get_close_code()
var reason = _client.get_close_reason()
print("WebSocket closed with code: %d, reason %s. Clean: %s" % [code, reason, code != -1])
set_process(false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment