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:
@@ -179,19 +179,9 @@ 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)
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user