using UnityEngine;
using WebSocketSharp;

public class OpusVoiceSender : MonoBehaviour
{
    private WebSocket ws;

    void Start()
    {
        ws = new WebSocket("ws://192.168.31.10:8765");
        ws.Connect();

        GetComponent<OpusMicRecorder>().OnEncodedAudio += SendEncoded;
    }

    void SendEncoded(byte[] data)
    {
        if (ws.ReadyState == WebSocketState.Open)
            ws.Send(data);
    }

    void OnDestroy()
    {
        ws?.Close();
    }
}
