public void RegisterChannel(ChannelCreate createPacket) { ushort channelId = createPacket.Header.ChannelId; NanoChannel channel = NanoChannelClass.GetIdByClassName(createPacket.Name); RegisterChannel(channelId, channel); }
/// <summary> /// /// </summary> /// <typeparam name="TChannel"></typeparam> /// <returns></returns> private async Task <ChannelOpen> WaitForChannelOpenAsync(NanoChannel channel) { return(await _transport.WaitForMessageAsync <ChannelOpen>( TimeSpan.FromSeconds(3), startAction : null, filter : open => open.Channel == channel)); }
/// <summary> /// /// </summary> /// <param name="channel"></param> /// <param name="reason"></param> /// <returns></returns> internal Task SendChannelClose(NanoChannel channel, uint reason) { var packet = new Nano.Packets.ChannelClose(reason); packet.Channel = channel; return(SendAsyncControl(packet)); }
/// <summary> /// /// </summary> /// <param name="channel"></param> /// <param name="flags"></param> /// <returns></returns> internal Task SendChannelOpen(NanoChannel channel, byte[] flags) { var packet = new Nano.Packets.ChannelOpen(flags); packet.Channel = channel; return(SendAsyncControl(packet)); }
public ushort GetChannelId(NanoChannel channel) { if (!_channels.ContainsValue(channel)) { throw new Exception($"NanoChannel {channel} is not registered"); } return(_channels.First(x => x.Value == channel).Key); }
private static INanoPacket CreateFromStreamerHeader(EndianReader reader, NanoChannel channel) { if (channel == NanoChannel.Unknown) { throw new NanoPackingException( $"Received Streamer Msg on UNKNOWN channel"); } StreamerHeader streamerHeader = new StreamerHeader(); streamerHeader.Deserialize(reader); uint streamerType = streamerHeader.PacketType; switch (channel) { case NanoChannel.Audio: case NanoChannel.ChatAudio: return(CreateFromAudioPayloadType((AudioPayloadType)streamerType)); case NanoChannel.Video: return(CreateFromVideoPayloadType((VideoPayloadType)streamerType)); case NanoChannel.Input: case NanoChannel.InputFeedback: return(CreateFromInputPayloadType((InputPayloadType)streamerType)); case NanoChannel.Control: // Skip to opCode reader.Seek(8, SeekOrigin.Current); ushort opCode = reader.ReadUInt16LE(); return(CreateFromControlOpCode((ControlOpCode)opCode)); default: throw new NanoPackingException( $"Received Streamer Msg on INVALID channel: {channel}"); } }
public void RegisterChannel(ushort channelId, NanoChannel channel) { _channels[channelId] = channel; }
/// <summary> /// Registers the channel via channel number and channel Id. /// </summary> /// <param name="channelNumber">Channel number.</param> /// <param name="channelId">Channel identifier.</param> public void RegisterChannel(ushort channelNumber, NanoChannel channelId) { _channels[channelNumber] = channelId; }
public static INanoPacket ParsePacket(byte[] data, NanoChannelContext context) { EndianReader packetReader = new EndianReader(data); RtpHeader header = new RtpHeader(); header.Deserialize(packetReader); NanoPayloadType payloadType = header.PayloadType; // It might be NanoChannel.Unknown at this point, if ChannelCreate // packet was not processed yet // It gets processed at the end of the function NanoChannel channel = context.GetChannel(header.ChannelId); INanoPacket packet = null; long payloadOffset = packetReader.Position; switch (payloadType) { // FIXME: Create from Attribute is broken case NanoPayloadType.UDPHandshake: packet = new UdpHandshake(); break; case NanoPayloadType.ControlHandshake: packet = new ControlHandshake(); break; case NanoPayloadType.ChannelControl: // Read type to pinpoint exact payload ChannelControlType cct = (ChannelControlType)packetReader.ReadUInt32LE(); packet = CreateFromChannelControlType(cct); break; case NanoPayloadType.Streamer: packet = CreateFromStreamerHeader(packetReader, channel); break; default: throw new NanoPackingException( $"Unknown packet type received: {payloadType}"); } if (packet == null) { throw new NanoPackingException("Failed to find matching body for packet"); } packetReader.Seek(payloadOffset, SeekOrigin.Begin); packet.Deserialize(packetReader); packet.Header = header; if (packet as ChannelCreate != null) { string channelName = ((ChannelCreate)packet).Name; channel = NanoChannelClass.GetIdByClassName(channelName); } if (channel == NanoChannel.Unknown) { throw new NanoPackingException("ParsePacket: INanoPacket.Channel is UNKNOWN"); } packet.Channel = channel; return(packet); }