godotengine / godotengine/webrtc-native
Godot 4.8dev2 : Websocket Peer connecting (0) for about 10 frames then closed (3) when running from editor
- Dominant language
- C++
- Stars
- 286
- Forks
- 47
- Avg merge
- 15d 12h
- Merged PRs (30d)
- 1
Description
### Godot version
4.8dev2
### Plugin version
latest release
### System information
Win 11
### Issue description
It still works when running in browser, but seems to not work in the editor anymore (it was fine in 4.7)
### Steps to reproduce
Run the MRP from the editor, then run in Web Browser, not the print output.
### Minimal reproduction project
extends Node
class_name MRP
const DEFAULT_SCHEME : String = "wss"
const DEFAULT_HOST : String = "your_server_address.com/"
const DEFAULT_PORT : int = 443
const DEFAULT_TIMEOUT : int = 30
var _ws := WebSocketPeer.new()
var _ws_last_state := WebSocketPeer.STATE_CLOSED
var _timeout : int = 30
var _start : int = 0
var _base_uri : String
func _ready():
_base_uri = "%s://%s" % [DEFAULT_SCHEME, DEFAULT_HOST]
connect_to_host(_base_uri, DEFAULT_TIMEOUT)
func is_connected_to_host():
return _ws.get_ready_state() == WebSocketPeer.STATE_OPEN
func is_connecting_to_host():
return _ws.get_ready_state() == WebSocketPeer.STATE_CONNECTING
func close():
if OS.is_debug_build():
print("Closing socket")
_ws.close()
func connect_to_host(p_uri : String, p_timeout : int):
_timeout = p_timeout
_start = int(Time.get_unix_time_from_system())
var err = _ws.connect_to_url(p_uri)
if err != OK:
if OS.is_debug_build():
printerr("Error connecting to host %s" % p_uri)
return
_ws_last_state = WebSocketPeer.STATE_CLOSED
func _process(_delta):
if _ws.get_ready_state() != WebSocketPeer.STATE_CLOSED:
_ws.poll()
var state = _ws.get_ready_state()
if _ws_last_state != state:
if OS.is_debug_build():
print("Socket state changed from %d to %d" % [_ws_last_state, state])
_ws_last_state = state
if state == WebSocketPeer.STATE_OPEN:
if OS.is_debug_build():
print("Socket connected")
elif state == WebSocketPeer.STATE_CLOSED:
if OS.is_debug_build():
printerr("Socket closed with code %d and reason: %s" % [_ws.get_close_code(), _ws.get_close_reason()])
if state == WebSocketPeer.STATE_CONNECTING:
if _start + _timeout < Time.get_unix_time_from_system():
if OS.is_debug_build():
printerr("Timeout when connecting to socket")
_ws.close()
while _ws.get_ready_state() == WebSocketPeer.STATE_OPEN and _ws.get_available_packet_count():
if OS.is_debug_build():
print(_ws.get_packet())
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running the minimal reproduction project from the Godot editor and then in a web browser, comparing the WebSocketPeer state and close code printed by the reproduction. Check whether the editor-specific connection closes after entering STATE_CONNECTING; done means identifying and fixing the editor-only regression so the connection remains open as it does in the browser.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100