/// <summary>
        /// Message recieved.
        /// </summary>
        /// <param name="connection">Connection object.</param>
        /// <param name="obj">Message object.</param>
        public void MessageReceived(RtmpConnection connection, object obj)
        {
            //Console.WriteLine("NEW MESSAGE");
            IRtmpEvent    message = null;
            RtmpPacket    packet  = null;
            RtmpHeader    header  = null;
            RtmpChannel   channel = null;
            IClientStream stream  = null;

            try
            {
                packet  = obj as RtmpPacket;
                message = packet.Message;
                header  = packet.Header;
                //Console.WriteLine("DATA TYPE: " + header.DataType);
                channel = connection.GetChannel(header.ChannelId);
                if (connection is IStreamCapableConnection)
                {
                    stream = (connection as IStreamCapableConnection).GetStreamById(header.StreamId);
                }

                // Support stream ids
#if !SILVERLIGHT
                FluorineContext.ValidateContext();
                FluorineContext.Current.Connection.SetAttribute(FluorineContext.FluorineStreamIdKey, header.StreamId);
#endif
                // Increase number of received messages
                connection.MessageReceived();

#if !SILVERLIGHT
                if (log != null && log.IsDebugEnabled)
                {
                    log.Debug("RtmpConnection message received, type = " + header.DataType);
                }
#endif

                if (message != null)
                {
                    message.Source = connection;
                }

                switch (header.DataType)
                {
                case Constants.TypeInvoke:
                    OnInvoke(connection, channel, header, message as Invoke);
                    if (message.Header.StreamId != 0 &&
                        (message as Invoke).ServiceCall.ServiceName == null &&
                        (message as Invoke).ServiceCall.ServiceMethodName == BaseRtmpHandler.ACTION_PUBLISH)
                    {
                        if (stream != null)     //Dispatch if stream was created
                        {
                            (stream as IEventDispatcher).DispatchEvent(message);
                        }
                    }
                    break;

                case Constants.TypeFlexInvoke:
                    OnFlexInvoke(connection, channel, header, message as FlexInvoke);
                    if (message.Header.StreamId != 0 &&
                        (message as Invoke).ServiceCall.ServiceName == null &&
                        (message as Invoke).ServiceCall.ServiceMethodName == BaseRtmpHandler.ACTION_PUBLISH)
                    {
                        if (stream != null)     //Dispatch if stream was created
                        {
                            (stream as IEventDispatcher).DispatchEvent(message);
                        }
                    }
                    break;

                case Constants.TypeNotify:    // just like invoke, but does not return
                    //Console.WriteLine("NOTIFY MESSAGE");
                    if ((message as Notify).Data != null && stream != null)
                    {
                        // Stream metadata
                        (stream as IEventDispatcher).DispatchEvent(message);
                    }
                    else
                    {
                        OnInvoke(connection, channel, header, message as Notify);
                    }
                    break;

                case Constants.TypePing:
                    OnPing(connection, channel, header, message as Ping);
                    break;

                case Constants.TypeBytesRead:
                    OnStreamBytesRead(connection, channel, header, message as BytesRead);
                    break;

                case Constants.TypeSharedObject:
                case Constants.TypeFlexSharedObject:
                    OnSharedObject(connection, channel, header, message as SharedObjectMessage);
                    break;

                case Constants.TypeFlexStreamEnd:
                    if (stream != null)
                    {
                        (stream as IEventDispatcher).DispatchEvent(message);
                    }
                    break;

                case Constants.TypeChunkSize:
                    OnChunkSize(connection, channel, header, message as ChunkSize);
                    break;

                case Constants.TypeAudioData:
                case Constants.TypeVideoData:
                    // NOTE: If we respond to "publish" with "NetStream.Publish.BadName",
                    // the client sends a few stream packets before stopping. We need to
                    // ignore them.
                    if (stream != null)
                    {
                        ((IEventDispatcher)stream).DispatchEvent(message);
                    }
                    break;

                case Constants.TypeServerBandwidth:
                    OnServerBW(connection, channel, header, message as ServerBW);
                    break;

                case Constants.TypeClientBandwidth:
                    OnClientBW(connection, channel, header, message as ClientBW);
                    break;

                default:
                    //Console.WriteLine("Package not WORKING or SENT");
#if !SILVERLIGHT
                    if (log != null && log.IsDebugEnabled)
                    {
                        log.Debug("RtmpService event not handled: " + header.DataType);
                    }
#endif
                    break;
                }
            }
            catch (Exception ex)
            {
#if !SILVERLIGHT
                if (log.IsErrorEnabled)
                {
                    log.Error(__Res.GetString(__Res.Rtmp_HandlerError), ex);
                    log.Error(__Res.GetString(__Res.Error_ContextDump));
                    //log.Error(Environment.NewLine);
                    log.Error(packet);
                    //Console.WriteLine("PACKET ERROR");
                }
#endif
            }
        }
Example #2
0
        /// <summary>
        /// Message recieved.
        /// </summary>
        /// <param name="connection">Connection object.</param>
        /// <param name="obj">Message object.</param>
        public void MessageReceived(RtmpConnection connection, object obj)
        {
            IRtmpEvent message = null;
            RtmpPacket packet = null;
            RtmpHeader header = null;
            RtmpChannel channel = null;
            IClientStream stream = null;
            try
            {
                packet = obj as RtmpPacket;
                message = packet.Message;
                header = packet.Header;
                channel = connection.GetChannel(header.ChannelId);
                if( connection is IStreamCapableConnection )
                    stream = (connection as IStreamCapableConnection).GetStreamById(header.StreamId);

                // Support stream ids
#if !SILVERLIGHT
                FluorineContext.ValidateContext();
                FluorineContext.Current.Connection.SetAttribute(FluorineContext.FluorineStreamIdKey, header.StreamId);
#endif
                // Increase number of received messages
                connection.MessageReceived();

#if !SILVERLIGHT
                if (log != null && log.IsDebugEnabled)
                    log.Debug("RtmpConnection message received, type = " + header.DataType);
#endif

                if (message != null)
                    message.Source = connection;

                switch (header.DataType)
                {
                    case Constants.TypeInvoke:
                        OnInvoke(connection, channel, header, message as Invoke);
                        if (message.Header.StreamId != 0
                            && (message as Invoke).ServiceCall.ServiceName == null
                            && (message as Invoke).ServiceCall.ServiceMethodName == BaseRtmpHandler.ACTION_PUBLISH)
                        {
                            if (stream != null) //Dispatch if stream was created
                                (stream as IEventDispatcher).DispatchEvent(message);
                        }
                        break;
                    case Constants.TypeFlexInvoke:
                        OnFlexInvoke(connection, channel, header, message as FlexInvoke);
                        if (message.Header.StreamId != 0
                            && (message as Invoke).ServiceCall.ServiceName == null
                            && (message as Invoke).ServiceCall.ServiceMethodName == BaseRtmpHandler.ACTION_PUBLISH)
                        {
                            if (stream != null) //Dispatch if stream was created
                                (stream as IEventDispatcher).DispatchEvent(message);
                        }
                        break;
                    case Constants.TypeNotify:// just like invoke, but does not return
                        if ((message as Notify).Data != null && stream != null)
                        {
                            // Stream metadata
                            (stream as IEventDispatcher).DispatchEvent(message);
                        }
                        else
                            OnInvoke(connection, channel, header, message as Notify);
                        break;
                    case Constants.TypePing:
                        OnPing(connection, channel, header, message as Ping);
                        break;
                    case Constants.TypeBytesRead:
                        OnStreamBytesRead(connection, channel, header, message as BytesRead);
                        break;
                    case Constants.TypeSharedObject:
                    case Constants.TypeFlexSharedObject:
                        OnSharedObject(connection, channel, header, message as SharedObjectMessage);
                        break;
                    case Constants.TypeFlexStreamEnd:
                        if (stream != null)
                            (stream as IEventDispatcher).DispatchEvent(message);
                        break;
                    case Constants.TypeChunkSize:
                        OnChunkSize(connection, channel, header, message as ChunkSize);
                        break;
                    case Constants.TypeAudioData:
                    case Constants.TypeVideoData:
                        // NOTE: If we respond to "publish" with "NetStream.Publish.BadName",
                        // the client sends a few stream packets before stopping. We need to
                        // ignore them.
                        if (stream != null)
                            ((IEventDispatcher)stream).DispatchEvent(message);
                        break;
                    case Constants.TypeServerBandwidth:
                        OnServerBW(connection, channel, header, message as ServerBW);
                        break;
                    case Constants.TypeClientBandwidth:
                        OnClientBW(connection, channel, header, message as ClientBW);
                        break;
                    default:
#if !SILVERLIGHT
                        if (log != null && log.IsDebugEnabled)
                            log.Debug("RtmpService event not handled: " + header.DataType);
#endif
                        break;
                }
            }
            catch (Exception ex)
            {
#if !SILVERLIGHT
                if (log.IsErrorEnabled)
                {
                    log.Error(__Res.GetString(__Res.Rtmp_HandlerError), ex);
                    log.Error(__Res.GetString(__Res.Error_ContextDump));
                    //log.Error(Environment.NewLine);
                    log.Error(packet);
                }
#endif
            }
        }
Example #3
0
        public void MessageReceived(RtmpConnection connection, object obj)
        {
            IRtmpEvent evt = null;

            try
            {
                RtmpPacket packet = obj as RtmpPacket;
                evt = packet.Message;
                RtmpHeader    source     = packet.Header;
                RtmpChannel   channel    = connection.GetChannel(source.ChannelId);
                IClientStream streamById = null;
                if (connection is IStreamCapableConnection)
                {
                    streamById = (connection as IStreamCapableConnection).GetStreamById(source.StreamId);
                }
                FluorineContext.Current.Connection.SetAttribute("__@fluorinestreamid", source.StreamId);
                connection.MessageReceived();
                if ((log != null) && log.get_IsDebugEnabled())
                {
                    log.Debug("RtmpConnection message received, type = " + source.DataType);
                }
                if (evt != null)
                {
                    evt.Source = connection;
                }
                switch (source.DataType)
                {
                case 1:
                    this.OnChunkSize(connection, channel, source, evt as ChunkSize);
                    return;

                case 3:
                    this.OnStreamBytesRead(connection, channel, source, evt as BytesRead);
                    return;

                case 4:
                    this.OnPing(connection, channel, source, evt as Ping);
                    return;

                case 5:
                    this.OnServerBW(connection, channel, source, evt as ServerBW);
                    return;

                case 6:
                    this.OnClientBW(connection, channel, source, evt as ClientBW);
                    return;

                case 8:
                case 9:
                    if (streamById != null)
                    {
                        ((IEventDispatcher)streamById).DispatchEvent(evt);
                    }
                    return;

                case 15:
                    if (streamById != null)
                    {
                        (streamById as IEventDispatcher).DispatchEvent(evt);
                    }
                    return;

                case 0x10:
                case 0x13:
                    this.OnSharedObject(connection, channel, source, evt as SharedObjectMessage);
                    return;

                case 0x11:
                    this.OnFlexInvoke(connection, channel, source, evt as FlexInvoke);
                    if ((((evt.Header.StreamId != 0) && ((evt as Invoke).ServiceCall.ServiceName == null)) && ((evt as Invoke).ServiceCall.ServiceMethodName == "publish")) && (streamById != null))
                    {
                        (streamById as IEventDispatcher).DispatchEvent(evt);
                    }
                    return;

                case 0x12:
                    if (((evt as Notify).Data == null) || (streamById == null))
                    {
                        break;
                    }
                    (streamById as IEventDispatcher).DispatchEvent(evt);
                    return;

                case 20:
                    this.OnInvoke(connection, channel, source, evt as Invoke);
                    if ((((evt.Header.StreamId != 0) && ((evt as Invoke).ServiceCall.ServiceName == null)) && ((evt as Invoke).ServiceCall.ServiceMethodName == "publish")) && (streamById != null))
                    {
                        (streamById as IEventDispatcher).DispatchEvent(evt);
                    }
                    return;

                default:
                    goto Label_0304;
                }
                this.OnInvoke(connection, channel, source, evt as Notify);
                return;

Label_0304:
                if ((log != null) && log.get_IsDebugEnabled())
                {
                    log.Debug("RtmpService event not handled: " + source.DataType);
                }
            }
            catch (Exception exception)
            {
                log.Error("Runtime error", exception);
            }
        }