public Presence(Channel channel, Options opts = null) { _channel = channel; var options = opts ?? new Options(); channel.On(options.StateEvent, message => { var serializer = channel.Socket.Opts.MessageSerializer; var newState = serializer.MapPayload <State>(message.Payload); _joinRef = channel.JoinRef; State = SyncState(State, newState, OnJoin, OnLeave); State = _pendingDiffs.Aggregate( State, (state, diff) => SyncDiff(new State(state), diff, OnJoin, OnLeave) ); _pendingDiffs.Clear(); OnSync?.Invoke(); }); channel.On(options.DiffEvent, message => { var diff = channel.Socket.Opts.MessageSerializer.MapPayload <Diff>(message.Payload); if (InPendingSyncState()) { _pendingDiffs.Add(diff); } else { State = SyncDiff(new State(State), diff, OnJoin, OnLeave); OnSync?.Invoke(); } }); }
internal void StartTimeout() { // PhoenixJS: null check implicit CancelTimeout(); Ref = _channel.Socket.MakeRef(); _refEvent = Channel.ReplyEventName(Ref); var serializer = _channel.Socket.Opts.MessageSerializer; _channel.On(_refEvent, message => { CancelRefEvent(); CancelTimeout(); _receivedResp = serializer.MapReply(message.Payload); MatchReceive(_receivedResp); }); _delayedExecution = _channel.Socket.Opts.DelayedExecutor.Execute(() => { Trigger(ReplyStatus.Timeout); }, _timeout); }
//startTimeout(){ if(this.timeoutTimer){ return } // this.ref = this.channel.socket.makeRef() // this.refEvent = this.channel.replyEventName(this.ref) // this.channel.on(this.refEvent, payload => { // this.cancelRefEvent() // this.cancelTimeout() // this.receivedResp = payload // this.matchReceive(payload) // }) // this.timeoutTimer = setTimeout(() => { // this.trigger("timeout", {}) // }, this.timeout) //} internal void StartTimeout() { if (_timeoutTimer.Enabled) { return; //jfis - dont do if timer running } _ref = _channel.Socket.MakeRef(); //jfis - get new ref _refEvent = _channel.ReplyEventName(_ref); //jfis - ref as string _channel.On(_refEvent, (payload, _) => //make binding for refEvent { CancelRefEvent(); CancelTimeout(); var json = (JObject)payload; _receivedResp = json; MatchReceive(json); }); _timeoutTimer.Interval = _timeout; _timeoutTimer.Start(); //start timeout timer, which triggers "timeout" }