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,18 +179,8 @@ public class ChatUI : MonoBehaviour
|
|||||||
if (string.IsNullOrEmpty(text) || PlayerName.Length == 0) return;
|
if (string.IsNullOrEmpty(text) || PlayerName.Length == 0) return;
|
||||||
_inputText = "";
|
_inputText = "";
|
||||||
_autoScroll = true;
|
_autoScroll = true;
|
||||||
|
// Always use HTTP — the server endpoint broadcasts to Colyseus rooms anyway
|
||||||
var nm = NetworkManager.Instance;
|
StartCoroutine(DoSend(PlayerName, text));
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── HTTP polling ─────────────────────────────────────────────────────
|
// ─── HTTP polling ─────────────────────────────────────────────────────
|
||||||
@@ -233,6 +223,9 @@ public class ChatUI : MonoBehaviour
|
|||||||
req.downloadHandler = new DownloadHandlerBuffer();
|
req.downloadHandler = new DownloadHandlerBuffer();
|
||||||
req.SetRequestHeader("Content-Type", "application/json");
|
req.SetRequestHeader("Content-Type", "application/json");
|
||||||
yield return req.SendWebRequest();
|
yield return req.SendWebRequest();
|
||||||
|
|
||||||
|
// Immediate poll so the message appears right away
|
||||||
|
StartCoroutine(DoPoll());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by NetworkManager when a "chat" message arrives via Colyseus
|
// Called by NetworkManager when a "chat" message arrives via Colyseus
|
||||||
|
|||||||
Reference in New Issue
Block a user