fix websocket

This commit is contained in:
helloworldlv
2025-10-20 14:15:38 +08:00
parent add1d1a369
commit 711470301f
2 changed files with 16 additions and 4 deletions
@@ -27,6 +27,7 @@ namespace laya
}
void JSWebSocketDelegate::onOpen(WebSocket* ws)
{
m_js_WebSocket->m_nWebSocketState = WSS_OPEN;
#ifdef OHOS
LOGI("JSWebSocketDelegate::onOpen() this=%{public}x ws=%{public}x", (long)this,(long)m_js_WebSocket);
#else
@@ -52,7 +53,8 @@ namespace laya
void JSWebSocketDelegate::onError(WebSocket* ws, const WebSocket::ErrorCode& error)
{
LOGW("JSWebSocketDelegate::onError( code=%{public}d )this=%{public}x ws=%{public}x", error, (long)this, (long)m_js_WebSocket);
if (m_js_WebSocket->m_nWebSocketState == WSS_OPEN)
//if (m_js_WebSocket->m_nWebSocketState == WSS_OPEN)
if (m_js_WebSocket->m_nWebSocketState != WSS_CLOSE)
{
LOGW("JSWebSocketDelegate::onError123( code=%{public}d )this=%{public}x ws=%{public}x", error, (long)this, (long)m_js_WebSocket);
std::string p_sEvent = "error";
@@ -140,13 +142,13 @@ namespace laya
//if (m_nWebSocketState == WSS_OPEN)
if (m_nWebSocketState != WSS_CLOSE)
{
m_nWebSocketState = WSS_CLOSE;
//m_nWebSocketState = WSS_CLOSE;
m_pJSFunctionOnError.Call(p_sEvent.c_str());
}
else
/*else
{
m_nWebSocketState = WSS_CLOSE;
}
}*/
}
void JSWebSocket::onSocketMessageCallJSFunctionArrayBuffer(const char* pBuf, int p_nLen, bool isBin, std::weak_ptr<int> cbref)
{
@@ -617,6 +617,16 @@ int WebSocket::onSocketCallback(
}
break;
case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE:
{
// Remote peer sent a Close frame. Mark as closing; libwebsockets
// will transition to CLOSED and trigger the closed callback below.
m_readyState = State::CLOSING;
LOGI("WebSocket onSocketCallback peer initiated close (%zu bytes)", len);
}
break;
case LWS_CALLBACK_WSI_DESTROY:
case LWS_CALLBACK_CLIENT_CLOSED:
case LWS_CALLBACK_CLOSED:
{