class Phoenix::Push

Overview

A Push is returned from Channel#join, Channel#leave and Channel#push calls. Callbacks can be bound to server replies using #receive.

Defined in:

phoenix/push.cr

Instance Method Summary

Instance Method Detail

def receive(status : String, &block : JSON::Any -> ) : Push #

Register a callback for a push reply of a given status

This example shows registering both "ok" and "error" callbacks for a channel join push. This also works for general channel pushes (if configured on the server to reply).

channel.join
  .receive "ok" do |response|
    puts "Joined successfully: #{response}"
  end
  .receive "error" do |response|
    puts "Unable to join: #{response}"
  end

[View source]