Skip to content

Instantly share code, notes, and snippets.

@haydenjameslee
Created June 1, 2015 05:08
Show Gist options
  • Save haydenjameslee/cb18338294d5739537a8 to your computer and use it in GitHub Desktop.
Save haydenjameslee/cb18338294d5739537a8 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using DaikonForge.VoIP;
using System;
public class MyLocalVoiceController : VoiceControllerBase
{
public PhotonView photonView;
private DateTime lastTalking = DateTime.Now.AddMinutes(-1);
public override bool IsLocal
{
get { return photonView.isMine; }
}
protected override void OnAudioDataEncoded( VoicePacketWrapper encodedFrame )
{
byte[] headers = encodedFrame.ObtainHeaders();
GetComponent<PhotonView>().RPC("vc", PhotonTargets.Others, headers, encodedFrame.RawData);
encodedFrame.ReleaseHeaders();
lastTalking = DateTime.Now;
}
[RPC]
void vc( byte[] headers, byte[] rawData )
{
if (!GetComponent<AudioSource>().enabled) return;
VoicePacketWrapper packet = new VoicePacketWrapper( headers, rawData );
ReceiveAudioData( packet );
}
public bool isTalking ()
{
return DateTime.Now.CompareTo(lastTalking.AddMilliseconds(100)) == -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment