apns_connection (apns v2.6.0)
This gen_statem handles the APNs Connection.
Copyright 2017 Erlang Solutions Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Summary
Functions
Close the connection with APNs gracefully
Builds a connection() map from the environment variables.
Returns the gun's connection PID. This function is only used in tests.
Pushes notification to certificate APNs connection.
Pushes notification to certificate APNs connection.
starts the gen_statem
Waits until the APNS connection is up.
Types
connection/0
-type connection() :: #{name := name(), apple_host := host(), apple_port := inet:port_number(), certdata => binary(), certfile => path(), keydata => keydata(), keyfile => path(), timeout => integer(), type := type(), proxy_info => proxy_info()}.
host/0
-type host() :: string() | inet:ip_address().
keydata/0
-type keydata() :: {'RSAPrivateKey' | 'DSAPrivateKey' | 'ECPrivateKey' | 'PrivateKeyInfo', binary()}.
name/0
-type name() :: atom().
notification/0
-type notification() :: binary().
path/0
-type path() :: string().
proxy_info/0
-type proxy_info() :: #{type := connect, host := host(), port := inet:port_number(), username => iodata(), password => iodata()}.
state/0
-opaque state()
type/0
-type type() :: certdata | cert | token.
Functions
await_tunnel_up(EventType, EventContent, StateData)
-spec await_tunnel_up(_, _, _) -> _.
await_up(EventType, EventContent, StateData)
-spec await_up(_, _, _) -> _.
callback_mode()
-spec callback_mode() -> state_functions.
certdata(_)
-spec certdata(connection()) -> binary().
certfile(_)
-spec certfile(connection()) -> path().
close_connection(ConnectionId)
Close the connection with APNs gracefully
code_change(OldVsn, StateName, StateData, Extra)
connected(EventType, Event, StateData)
-spec connected(_, _, _) -> _.
default_connection(_, ConnectionName)
-spec default_connection(type(), name()) -> connection().
Builds a connection() map from the environment variables.
down(EventType, EventContent, StateData)
-spec down(_, _, _) -> _.
gun_pid(ConnectionId)
Returns the gun's connection PID. This function is only used in tests.
host(_)
-spec host(connection()) -> host().
init(_)
-spec init({connection(), pid()}) -> {ok, open_connection, State :: state(), {next_event, internal, init}}.
keydata(_)
-spec keydata(connection()) -> keydata().
keyfile(_)
-spec keyfile(connection()) -> path().
name(_)
-spec name(connection()) -> name().
open_common(_, _, StateData)
-spec open_common(_, _, _) -> _.
open_connection(_, _, StateData)
-spec open_connection(_, _, _) -> _.
open_origin(_, _, StateData)
-spec open_origin(_, _, _) -> _.
open_proxy(_, _, StateData)
-spec open_proxy(_, _, _) -> _.
port(_)
-spec port(connection()) -> inet:port_number().
proxy_connect_to_origin(_, _, StateData)
-spec proxy_connect_to_origin(_, _, _) -> _.
push_notification(ConnectionId, DeviceId, Notification, Headers)
-spec push_notification(name() | pid(), apns:device_id(), notification(), apns:headers()) -> apns:response() | {error, not_connection_owner}.
Pushes notification to certificate APNs connection.
push_notification(ConnectionId, Token, DeviceId, Notification, Headers)
-spec push_notification(name() | pid(), apns:token(), apns:device_id(), notification(), apns:headers()) -> apns:response() | {error, not_connection_owner}.
Pushes notification to certificate APNs connection.
reply_errors_and_cancel_timers(Streams, Reason)
start_link(Connection, Client)
-spec start_link(connection(), pid()) -> {ok, Pid :: pid()} | ignore | {error, Reason :: term()}.
starts the gen_statem
type(_)
-spec type(connection()) -> type().
wait_apns_connection_up(Server)
-spec wait_apns_connection_up(pid()) -> ok.
Waits until the APNS connection is up.
Note that this function does not need to be called before sending push notifications, since they will be queued up and sent when the connection is established.