public ObservablePhotonPeer(ConnectionProtocol protocolType, string peerName = null, int serviceCallRate = 20)
: base(new ObservablePhotonPeerListener(), protocolType)
{
if (serviceCallRate <= 0)
{
throw new ArgumentOutOfRangeException("serviceCallRate must be > 0, serviceCallRate:" + serviceCallRate);
}
this.Timeout = TimeSpan.FromSeconds(15); // default timeout
this.PeerName = peerName;
this.callIntervalMs = (int)(1000 / serviceCallRate);
this.serviceLoop = new Timer(CallService, null, callIntervalMs, System.Threading.Timeout.Infinite);
#if UNITY_EDITOR
PhotonWire.Editor.PhotonWireWindow.AddConnection(this);
MainThreadDispatcher.OnApplicationQuitAsObservable().Subscribe(_ =>
{
// If connection is leaked, unity freeze on play again.
// http://forum.photonengine.com/discussion/6082/leaked-connection-causes-unity-to-freeze
this.Dispose();
});
#endif
}