fix: chat envoie toujours via HTTP, pas Colyseus

Colyseus disconnectait le client si le handler chat n'était pas
déployé côté serveur. Le endpoint HTTP /chat/send broadcaste déjà
dans les rooms Colyseus, donc le path Colyseus est superflu.
Ajout poll immédiat après envoi pour affichage sans délai.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-17 19:01:48 +02:00
parent 01d6128209
commit 597bfe1723

View File

@@ -179,18 +179,8 @@ public class ChatUI : MonoBehaviour
if (string.IsNullOrEmpty(text) || PlayerName.Length == 0) return;
_inputText = "";
_autoScroll = true;
var nm = NetworkManager.Instance;
if (nm != null && nm.IsConnected)
{
// Fast path: through Colyseus (room broadcasts it back to all players AND saves to ChatManager)
nm.SendChatMessage(text);
}
else
{
// Fallback: direct HTTP (for frontend-only visitors or disconnected state)
StartCoroutine(DoSend(PlayerName, text));
}
// Always use HTTP — the server endpoint broadcasts to Colyseus rooms anyway
StartCoroutine(DoSend(PlayerName, text));
}
// ─── HTTP polling ─────────────────────────────────────────────────────
@@ -233,6 +223,9 @@ public class ChatUI : MonoBehaviour
req.downloadHandler = new DownloadHandlerBuffer();
req.SetRequestHeader("Content-Type", "application/json");
yield return req.SendWebRequest();
// Immediate poll so the message appears right away
StartCoroutine(DoPoll());
}
// Called by NetworkManager when a "chat" message arrives via Colyseus