How to publish an audio stream from a client with FluorineFx?

1.8k views Asked by At

I can't figure out how to publish an audio stream from a client to the server using FluorineFx on the client. We want to stream recorded audio data from the client to the stream via the already established NetConnection. There is a NetStream class in FluorineFx but it has no publish method. The NetStream class in FluorineFx only has the play method. But as far as I understand this plays a stream from the server on the client.

Is publish not implemented in FluorineFx or do I miss something?

3

There are 3 answers

1
Jan Deinhard On BEST ANSWER

Unfortunately this feature doesn't seem to be implemented.

1
adamcodes On

Check out http://www.fluorinefx.com/docs/fluorine/

See Publishing streams and subscribing to streams under Real-time Messaging.

0
user6453459 On

Recently, I also look into the codes of fluorinefx. It is strange why the publish is not implemented in the codes although the doc mentioned it.

Actually, in its PlayEngine.cs, there is a similar implementation PullAndPush() which can pull data from a FLV file and push it to the remote.

So, I tried some similar codes in Netstream class, it can almost work and can push the stream to the rtmplite server and can be played by the test web in rtmplite.

public void Publish(params object[] arguments)
        {
            ValidationUtils.ArgumentConditionTrue(arguments != null && arguments.Length > 0, "arguments", "At least the name of a file must be specified");
            ValidationUtils.ArgumentNotNullOrEmptyOrWhitespace(arguments[0] as string, "name");
            _name = arguments[0] as string;


            INetConnectionClient client = _connection.NetConnectionClient;
            RtmpConnection connection = _connection.NetConnectionClient.Connection as RtmpConnection;
            IPendingServiceCallback callback = new CreateStreamCallBack(this, connection, new PublishCallBack(this,_connection, _name));
            client.Call("createStream", callback);
        }

        public void AttachFile(string filepath)
        {

            FileProvider fileProvider = new FileProvider(this.Scope, new System.IO.FileInfo(filepath));
            _pullPushPipe.Subscribe(fileProvider, null);
            PullAndPush();
        }

        public void PullAndPush()
        {

            while(true)
            {
                var msg = _pullPushPipe.PullMessage();
                if (msg == null)
                {
                    // No more packets to send
                    Stop();
                    break;
                }
                else
                {
                    if (msg is RtmpMessage)
                    {
                        RtmpMessage rtmpMessage = (RtmpMessage)msg;
                        IRtmpEvent body = rtmpMessage.body;
                     //   SendMessage(rtmpMessage);
                        // Adjust timestamp when playing lists
                        //  EnsurePullAndPushRunning();
                        _pullPushPipe.PushMessage(msg);
                    }
                }
            }
        }

        class PublishCallBack : IPendingServiceCallback
        {
            NetConnection _connection;
            NetStream _stream;
            string _name;
            string _mode;

            public PublishCallBack(NetStream stream, NetConnection connection, string name, string mode = "live")
            {
                _connection = connection;
                _name = name;
                _mode = mode;
                _stream = stream;
            }

            public void ResultReceived(IPendingServiceCall call)
            {
                if ("createStream".Equals(call.ServiceMethodName))
                {
                    RtmpConnection connection = _connection.NetConnectionClient.Connection as RtmpConnection;
                    object[] args = new object[2] {_name, _mode};
                    PendingCall pendingCall = new PendingCall("publish", args);
                    pendingCall.RegisterCallback(new PublishResultCallBack());
                    connection.Invoke(pendingCall, (byte)connection.GetChannelForStreamId(_stream.StreamId));
                }
            }
        }