mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
b55a462945
After months of work and over a hundred commits on this repo alone (not to mention the old, half-working repos on GitHub), StreamGraph is finally ready to be shown to the public, even if in an incomplete state. This PR is a culmination of numerous design discussions, re-writes, and hours spent by both @Eroax and myself. Reviewed-on: https://codeberg.org/Eroax/StreamGraph/pulls/18 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
58 lines
1.4 KiB
GDScript
58 lines
1.4 KiB
GDScript
extends WebSocketPeer
|
|
class_name Websocket_Client
|
|
|
|
## Helper Class for handling the freaking polling of a WebSocketPeer
|
|
|
|
## Emitted when [method WebSocketPeer.get_ready_state()] returns
|
|
## [member WebSocketPeer.STATE_OPEN]
|
|
signal socket_open
|
|
## Emitted when [method WebSocketPeer.get_ready_state()] returns
|
|
## [member WebSocketPeer.STATE_CLOSED]
|
|
signal socket_closed(close_code, close_reason)
|
|
## Emitted when [method WebSocketPeer.get_ready_state()] returns
|
|
## [member WebSocketPeer.STATE_CONNECTING]
|
|
signal socket_connecting
|
|
## Emitted when [method WebSocketPeer.get_ready_state()] returns
|
|
## [member WebSocketPeer.STATE_CLOSING]
|
|
signal socket_closing
|
|
## Emitted when [method WebSocketPeer.get_available_packets()] returns greater
|
|
## than 0. Or, when a packet has been received.
|
|
signal packet_received(packet_data)
|
|
|
|
## Works as a wrapper around [method WebSocketPeer.poll] to handle the logic of
|
|
## checking get_ready_state() more simply.
|
|
func poll_socket():
|
|
|
|
poll()
|
|
|
|
var state = get_ready_state()
|
|
|
|
match state:
|
|
|
|
STATE_OPEN:
|
|
|
|
socket_open.emit(get_connected_host(), get_connected_port())
|
|
|
|
if get_available_packet_count() > 0:
|
|
|
|
packet_received.emit(get_packet())
|
|
|
|
|
|
|
|
STATE_CONNECTING:
|
|
|
|
socket_connecting.emit()
|
|
|
|
|
|
STATE_CLOSING:
|
|
|
|
socket_closing.emit()
|
|
|
|
|
|
STATE_CLOSED:
|
|
|
|
socket_closed.emit(get_close_code(), get_close_reason())
|
|
|
|
|
|
|
|
|