void Init() { node.OnServerStartSuccess += () => OnCreatedChatroom?.Invoke(); node.OnServerStartFailure += e => OnChatroomCreationFailed?.Invoke(e); node.OnServerStop += () => OnlosedChatroom?.Invoke(); node.OnConnectionFailed += ex => OnChatroomJoinFailed?.Invoke(ex); node.OnReceiveID += id => { if (id != 0) { OnJoinedChatroom?.Invoke(id); OnPeerJoinedChatroom?.Invoke(0); // server joins instantly } }; node.OnDisconnected += () => OnLeftChatroom?.Invoke(); node.OnRemoteServerClosed += () => OnLeftChatroom?.Invoke(); node.OnClientJoined += id => OnPeerJoinedChatroom?.Invoke(id); node.OnClientLeft += id => OnPeerLeftChatroom?.Invoke(id); node.OnPacketReceived += (sender, packet) => { if (packet.Tag.Equals("audio")) { var reader = new BytesReader(packet.Payload); var index = reader.ReadInt(); var frequency = reader.ReadInt(); var channels = reader.ReadInt(); var samples = reader.ReadFloatArray(); OnAudioReceived?.Invoke(new ChatroomAudioDTO { id = sender, segmentIndex = index, frequency = frequency, channelCount = channels, samples = samples }); } }; }
private void Start() { node = new APNode(signalingServer); node.OnServerStartSuccess += () => { msg1.text = "Server started"; }; node.OnServerStartFailure += e => { msg1.text = "Server start failed " + e; }; node.OnServerStop += () => { msg1.text = "Stopped server"; msg2.text = ""; }; node.OnConnected += () => { msg1.text = "Connected to server"; }; node.OnReceiveID += id => Debug.Log("Got ID : " + id); node.OnDisconnected += () => msg1.text = "Disconnected from server"; node.OnConnectionFailed += ex => Debug.LogError(ex); node.OnPacketReceived += (id, packet) => { var reader = new BytesReader(packet.Payload); msg2.text = "Received " + reader.ReadInt(); }; node.OnClientJoined += id => Debug.Log("Client joined : " + id); node.OnClientLeft += id => Debug.Log("Client left : " + id); }
void Start() { var writer = new BytesWriter(); writer.WriteInt(90); writer.WriteString("Vatsal"); writer.WriteString("Adrenak"); writer.WriteString("Ambastha"); writer.WriteVector3(Vector3.one); writer.WriteFloatArray(new[] { 1.1f, 2.2f, 3.3f }); var reader = new BytesReader(writer.Bytes); // READ IN THE SAME ORDER Debug.Log(reader.ReadInt()); Debug.Log(reader.ReadString()); Debug.Log(reader.ReadString()); Debug.Log(reader.ReadString()); Debug.Log(reader.ReadVector3()); Debug.Log("Floats : " + string.Join(", ", reader.ReadFloatArray())); }