public void SendHeadTransform(Vector3 position, Quaternion rotation) { // If we are connected to a session, broadcast our head info if (this.serverConnection != null && this.serverConnection.IsConnected()) { // Create an outgoing network message to contain all the info we want to send NetworkOutMessage msg = CreateMessage((byte)TestMessageID.HeadTransform); AppendTransform(msg, position, rotation); // Send the message as a broadcast, which will cause the server to forward it to all other users in the session. this.serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, MessageChannel.Avatar); } }
public void SendNirImageNetworkStatus(bool connected) { // If we are connected to a session, broadcast the info we want if (this.serverConnection != null && this.serverConnection.IsConnected()) { // Create an outgoing network message to contain all the info we want to send NetworkOutMessage msg = CreateMessage((byte)TestMessageID.NirImageNetworkStatus); AppendBoolean(msg, connected); // Send the message as a broadcast, which will cause the server to forward it to all other users in the session. this.serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Avatar); } }
void appendHeight(NetworkOutMessage msg, int height) { msg.Write(height); }
/* #region HelperFunctionsForWriting * * void AppendVector3(NetworkOutMessage msg, Vector3 vector) * { * msg.Write(vector.x); * msg.Write(vector.y); * msg.Write(vector.z); * } * #endregion HelperFunctionsForWriting * #region HelperFunctionsForReading * * public Vector3 ReadVector3(NetworkInMessage msg) * { * return new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat()); * } * #endregion HelperFunctionsForReading */ void appendWidth(NetworkOutMessage msg, int width) { msg.Write(width); }
public void SendDepthData(MsgTag tag, ushort[] depthData) { // If we are connected to a session, broadcast our info if (this.serverConnection != null && this.serverConnection.IsConnected()) { /*ushort[] source = new ushort[217088]; * source = depthData; * byte[] target = new byte[source.Length * 2]; * Buffer.BlockCopy(source, 0, target, 0, source.Length * 2); * uint len = (uint)target.Length;*/ //int length = 217088; //int offset = 0; //if ((2 * length) > MAX_PACKET_SIZE) // Will need to divide depth data into at least two messages //{ // offset = (int)Math.Ceiling((float)(length) / 2f); //} // Start first message // 1) Start with UserMessageIDStart NetworkOutMessage msg = CreateMessage((int)TestMessageID.StartID); // 2) Add message type ID msg.Write((byte)tag); //// 3) Add message length //if (offset == 0) // will just send one depth message //{ // msg1.Write((int)length); //} else // will send two depth messages //{ // msg1.Write((int)offset); //} // 3) Add message length //msg.Write((int)length); // 4) Write message int length = depthData.Length; for (int i = 0; i < length; i++) { msg.Write((short)depthData[i]); } //msg.WriteArray(target, len); //Debug.Log("msg.write in cs2 is:" + msg1.ToString()); // Send the message as a broadcast this.serverConnection.Broadcast( msg, MessagePriority.Immediate, MessageReliability.UnreliableSequenced, MessageChannel.Avatar); //// Send second message //if (offset != 0) //{ // // Start second message // // 1) Start with UserMessageIDStart // NetworkOutMessage msg2 = CreateMessage((int)TestMessageID.StartID); // // 2) Add message type ID // msg2.Write((byte)MsgID.DEPTH2); // // 3) Add message length // msg2.Write((int)(length - offset)); // // 4) Add message // for (int i = offset; i < length; i++) // { // msg2.Write((short)depthData[i]); // } // // Send the message as a broadcast // this.serverConnection.Broadcast( // msg2, // MessagePriority.Immediate, // MessageReliability.UnreliableSequenced, // MessageChannel.Avatar); //} } }
private void SendFixedSizedChunk(NetworkConnection connection, byte[] data, int dataSize) { System.DateTime currentTime = System.DateTime.Now; float seconds = (float)(currentTime - timeOfLastPacketSend).TotalSeconds; timeOfLastPacketSend = currentTime; if (seconds < 10.0) { if (worstTimeBetweenPackets < seconds) { worstTimeBetweenPackets = seconds; } if (ShowInterPacketTime) { UnityEngine.Debug.Log("Microphone: Millisecs since last sent: " + seconds * 1000.0 + " Worst: " + worstTimeBetweenPackets * 1000.0); } } int clientId = SharingStage.Instance.Manager.GetLocalUser().GetID(); // pack the header NetworkOutMessage msg = connection.CreateMessage((byte)MessageID.AudioSamples); int dataCountFloats = dataSize / 4; msg.Write((byte)5); // 8 byte header size Int32 pack = 0; versionPacker.SetBits(ref pack, 1); // version audioStreamCountPacker.SetBits(ref pack, 1); // AudioStreamCount channelCountPacker.SetBits(ref pack, 1); // ChannelCount sampleRatePacker.SetBits(ref pack, sampleRateType); // SampleRate: 1 = 16000, 3 = 48000 sampleTypePacker.SetBits(ref pack, 0); // SampleType sampleCountPacker.SetBits(ref pack, dataCountFloats); // SampleCount (data count is in bytes and the actual data is in floats, so div by 4) codecTypePacker.SetBits(ref pack, 0); // CodecType mutePacker.SetBits(ref pack, Mute ? 1 : 0); sequenceNumberPacker.SetBits(ref pack, sequenceNumber++); sequenceNumber %= 32; msg.Write((int)pack); // the packed bits // This is where stream data starts. Write all data for one stream msg.Write((float)0.0f); // average amplitude. Not needed in direction from client to server. msg.Write((int)clientId); // non-zero client ID for this client. // HRTF position bits Vector3 cameraPosRelativeToGlobalAnchor = Vector3.zero; Vector3 cameraDirectionRelativeToGlobalAnchor = Vector3.zero; if (GlobalAnchorTransform != null) { cameraPosRelativeToGlobalAnchor = MathUtils.TransformPointFromTo( null, GlobalAnchorTransform, Camera.main.transform.position); cameraDirectionRelativeToGlobalAnchor = MathUtils.TransformDirectionFromTo( null, GlobalAnchorTransform, Camera.main.transform.position); } cameraPosRelativeToGlobalAnchor.Normalize(); cameraDirectionRelativeToGlobalAnchor.Normalize(); // Camera position msg.Write(cameraPosRelativeToGlobalAnchor.x); msg.Write(cameraPosRelativeToGlobalAnchor.y); msg.Write(cameraPosRelativeToGlobalAnchor.z); // HRTF direction bits msg.Write(cameraDirectionRelativeToGlobalAnchor.x); msg.Write(cameraDirectionRelativeToGlobalAnchor.y); msg.Write(cameraDirectionRelativeToGlobalAnchor.z); msg.WriteArray(data, (uint)dataCountFloats * 4); connection.Send(msg, MessagePriority.Immediate, MessageReliability.ReliableOrdered, MessageChannel.Audio, true); }
void AppendVector3(NetworkOutMessage msg, Vector3 vector) { msg.Write(vector.x); msg.Write(vector.y); msg.Write(vector.z); }
void AppendTransform(NetworkOutMessage msg, Vector3 position, Quaternion rotation) { AppendVector3(msg, position); AppendQuaternion(msg, rotation); }
private void AppendInt(NetworkOutMessage msg, int value) { msg.Write(value); }