mirror of
https://github.com/Dadechin/Unity-WebSocket.git
synced 2025-07-17 18:54:35 +00:00
27 lines
475 B
C#
27 lines
475 B
C#
|
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();
|
||
|
}
|
||
|
}
|