View Source ChannelHandler.API (channel_handler v0.1.1)

Lists all functions allowed in the ChannelHandler API.

Note the functions in this module exist for documentation purposes and one should never need to invoke them directly.

Link to this section Summary

Functions

Defines an event handler function for the given event name.

When used in join, this is the function to run in the channel's join callback.

When used in event or match, this is the function that will be called to process the event. It's mostly equivalent to a c:Phoehix.Channel.handle_in/3 with the following differences

Defines the handle_in/3 functions for a Phoenix channel by matching on exact event names, or prefixes.

The channel path for this handler. By default this has no runtime effect, but can be used by plugs and handlers if necessary.

Defines a matcher function for the given event prefix. The prefix is a string literal that will be used to match the start of the event string.

Registers a plug for the current match or event. Plugs are run in the order they are defined before the event handler.

Link to this section Functions

Defines an event handler function for the given event name.

If the module defining this is called by another event handler via match, the prefixes of previous handlers won't be included in the event name.

For example, if module A defines event "foo" do, and module B matches "app:", then the event "app:foo" will be matched by B and the handler for "foo" in A will be invoked.

plug/1 can be called inside event/2

When used in join, this is the function to run in the channel's join callback.

When used in event or match, this is the function that will be called to process the event. It's mostly equivalent to a c:Phoehix.Channel.handle_in/3 with the following differences:

  • It takes an additional bindings argument, containing the values stored by previous plugs, for the current event. These are cleared after every event.
  • When used in event, the event argument is omitted as it is redundant.

The handler function must return a reply/noreply tuple, just like a regular phoenix event handler.

If a module or mfa tuple is provided, the corresponding handle_in function in that module will be called.

Modules that use ChannelHandler can be used as well, as they define handle_in functions as well.

Defines the handle_in/3 functions for a Phoenix channel by matching on exact event names, or prefixes.

The channel path for this handler. By default this has no runtime effect, but can be used by plugs and handlers if necessary.

The channel value is stored in the socket's :__channel__ assign.

Defines a matcher function for the given event prefix. The prefix is a string literal that will be used to match the start of the event string.

The event name without the prefix will be used when delegating to another handler module with handler/1.

plug/1 can be called inside match/2.

Registers a plug for the current match or event. Plugs are run in the order they are defined before the event handler.