聊天接入

This commit is contained in:
2026-05-24 17:52:30 +08:00
parent 81834ebe09
commit 9b6ed2bcd6
3 changed files with 38 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using RenderStreaming;
using Script.Util;
using Stary.Evo;
@@ -73,18 +74,39 @@ namespace Script
$"{this.GetSystem<IGlobalConfigSystem>().GetConnectionTexture()}.png",
type = "text",
content = _messageInput.text,
isSelf = "true",
isSelf = false,
timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
};
GameObject.FindObjectOfType<MessageChannel>().SendMessage<ChatData>(_messageInput.text, chatData);
var message = new
{
type = "chat-message",
data = chatData
};
var data = new
{
message = message,
connectionId = this.GetSystem<IGlobalConfigSystem>().GetConnectionId()
};
var send = new
{
form = this.GetSystem<IGlobalConfigSystem>().GetConnectionId(),
to = "",
type = "on-message",
data = data
};
SignalingMessageHelper.SendMessage(JsonConvert.SerializeObject(send));
_messageInput.text = "";
chatData.isSelf = !chatData.isSelf;
_chatDatas.Add(chatData);
var entry = _objectRightPool.Get();
SetMessageEntry(chatData, entry);
}
private void OnChatMessageReceivedEvent(string connectionId, ChatData data)
{
if (connectionId != this.GetSystem<IGlobalConfigSystem>().GetConnectionId()) return;
_chatDatas.Add(data);
if (bool.Parse(data.isSelf) == false)
if (data.isSelf == false)
{
var entry = _objectLeftPool.Get();
SetMessageEntry(data, entry);