Send() public méthode

public Send ( ) : void
Résultat void
Exemple #1
0
        public Push Leave(TimeSpan?timeout = null)
        {
            _rejoinTimer?.Reset();
            _joinPush.CancelTimeout();

            State = ChannelState.Leaving;

            void TriggerClose()
            {
                if (Socket.HasLogger())
                {
                    Socket.Log(LogLevel.Debug, "channel", $"leave {Topic}");
                }

                Trigger(Message.InBoundEvent.Close);
            }

            var leaveEvent = Message.OutBoundEvent.Leave.Serialized();
            var leavePush  = new Push(this, leaveEvent, null, timeout ?? _timeout);

            leavePush
            .Receive(ReplyStatus.Ok, _ => TriggerClose())
            .Receive(ReplyStatus.Timeout, _ => TriggerClose());
            leavePush.Send();

            if (!CanPush())
            {
                leavePush.Trigger(ReplyStatus.Ok);
            }

            return(leavePush);
        }
Exemple #2
0
        public Push Push(string event_, JObject payload, int timeout)
        {
            if (!_joinedOnce) //jfis - necessary?
            {
                throw new Exception($"tried to push '{event_}' to '{_topic}' before joining. Use channel.join() before pushing events");
            }

            var pushEvent = new Push(this, event_, payload, timeout);

            if (CanPush())
            {
                pushEvent.Send(); //jfis - send now if can
            }
            else
            {
                pushEvent.StartTimeout(); //jfis - if cant add to buffer, but what does start timeout do?
                _pushBuffer.Add(pushEvent);
            }

            return(pushEvent);
        }
Exemple #3
0
        public Push Leave(int timeout)
        {
            Action onClose = () =>
            {
                _socket.Log("channel", $"leave ${_topic}"); //jfis - seems odd to tie logs to socket

                Trigger(Phoenix.CHANNEL_EVENT_CLOSE);       //, "leave");
            };

            var leavePush = new Push(this, Phoenix.CHANNEL_EVENT_LEAVE, Phoenix.EMPTY_JS_OBJECT, timeout);

            leavePush
            .Receive("ok", (_) => onClose())
            .Receive("timeout", (_) => onClose());
            leavePush.Send();

            if (!CanPush()) //jfis - if cant push simulate ok
            {
                leavePush.Trigger("ok", Phoenix.EMPTY_JS_OBJECT);
            }

            return(leavePush);
        }
Exemple #4
0
        public Push Push(string @event, object payload = null, TimeSpan?timeout = null)
        {
            if (!_joinedOnce)
            {
                throw new Exception(
                          $"tried to push '{@event}' to '{Topic}' before joining."
                          + " Use channel.join() before pushing events"
                          );
            }

            var pushEvent = new Push(this, @event, () => payload, timeout ?? _timeout);

            if (CanPush())
            {
                pushEvent.Send();
            }
            else
            {
                pushEvent.StartTimeout();
                _pushBuffer.Add(pushEvent);
            }

            return(pushEvent);
        }
Exemple #5
0
    public Push Leave(int timeout)
    {
      Action onClose = () =>
        {
          _socket.Log("channel", $"leave ${_topic}"); //jfis - seems odd to tie logs to socket

          Trigger(Phoenix.CHANNEL_EVENT_CLOSE);//, "leave");
        };

      var leavePush = new Push(this, Phoenix.CHANNEL_EVENT_LEAVE, Phoenix.EMPTY_JS_OBJECT, timeout);
      leavePush
        .Receive("ok", (_) => onClose())
        .Receive("timeout", (_) => onClose());
      leavePush.Send();

      if (!CanPush()) //jfis - if cant push simulate ok
      {
        leavePush.Trigger("ok", Phoenix.EMPTY_JS_OBJECT);
      }

      return leavePush;
    }
Exemple #6
0
    public Push Push(string event_, JObject payload, int timeout)
    {
      if (!_joinedOnce) //jfis - necessary?
      {
        throw new Exception($"tried to push '{event_}' to '{_topic}' before joining. Use channel.join() before pushing events");
      }

      var pushEvent = new Push(this, event_, payload, timeout);

      if (CanPush())
      {
        pushEvent.Send(); //jfis - send now if can
      }
      else
      {
        pushEvent.StartTimeout(); //jfis - if cant add to buffer, but what does start timeout do? 
        _pushBuffer.Add(pushEvent);
      }

      return pushEvent;
    }
Exemple #7
0
        // TODO: possibly support lazy instantiation of payload (same as Phoenix js)
        public Channel(string topic, ParamsType @params, Socket socket)
        {
            Topic  = topic;
            Socket = socket;

            _timeout  = socket.Opts.Timeout;
            _joinPush = new Push(
                this,
                Message.OutBoundEvent.Join.Serialized(),
                () => @params,
                _timeout
                );

            if (socket.Opts.RejoinAfter != null)
            {
                _rejoinTimer = new Scheduler(
                    () =>
                {
                    if (socket.IsConnected())
                    {
                        Rejoin();
                    }
                },
                    socket.Opts.RejoinAfter,
                    socket.Opts.DelayedExecutor
                    );
            }

            socket.OnError += SocketOnError;
            socket.OnOpen  += SocketOnOpen;

            _joinPush.Receive(ReplyStatus.Ok, message =>
            {
                State = ChannelState.Joined;
                _rejoinTimer?.Reset();
                _pushBuffer.ForEach(push => push.Send());
                _pushBuffer.Clear();
            });

            _joinPush.Receive(ReplyStatus.Error, message =>
            {
                State = ChannelState.Errored;
                if (socket.IsConnected())
                {
                    _rejoinTimer?.ScheduleTimeout();
                }
            });

            OnClose(message =>
            {
                _rejoinTimer?.Reset();
                if (socket.HasLogger())
                {
                    socket.Log(LogLevel.Debug, "channel", $"close {topic}");
                }

                State = ChannelState.Closed;
                // PhoenixJS: See note in socket regarding this
                // basically, we unregister delegates directly in c# instead of offing an array
                // this.off(channel.stateChangeRefs)
                socket.OnError -= SocketOnError;
                socket.OnOpen  -= SocketOnOpen;
                socket.Remove(this);
            });

            OnError(message =>
            {
                if (socket.HasLogger())
                {
                    socket.Log(LogLevel.Debug, "channel", $"error {topic}");
                }

                if (IsJoining())
                {
                    _joinPush.Reset();
                }

                State = ChannelState.Errored;
                if (socket.IsConnected())
                {
                    _rejoinTimer?.ScheduleTimeout();
                }
            });

            _joinPush.Receive(ReplyStatus.Timeout, message =>
            {
                if (socket.HasLogger())
                {
                    socket.Log(LogLevel.Debug, "channel", $"timeout {topic} ({JoinRef})");
                }

                var leaveEvent = Message.OutBoundEvent.Leave.Serialized();
                var leavePush  = new Push(this, leaveEvent, null, _timeout);
                leavePush.Send();

                State = ChannelState.Errored;
                _joinPush.Reset();

                if (socket.IsConnected())
                {
                    _rejoinTimer?.ScheduleTimeout();
                }
            });

            // on phx_reply, also trigger a message for the push using replyEventName
            On(Message.InBoundEvent.Reply.Serialized(), message =>
            {
                message.Event = ReplyEventName(message.Ref);
                Trigger(message);
            });
        }