Subscriptions allow two picos to communicate with each other on a secure channel. Subscriptions have several advantages and uses:
Subscriptions are formed from two channels from two different Picos. Each channel has a corresponding Eci stored for the other Picos channel.
From each pico's perspective there is an incoming channel and an outgoing channel. The pico receives events and queries from the other pico in the subscriptions over the incoming channel and makes queries and sends events to the other pico using the outgoing channel.
Subscriptions can exist between any two picos. They do not have to have the same parent. In the Forever application, for example, the picos belonged to different people and represented their personal contact information.
There are several important steps in establishing a subscription:
wrangler:subscription
event that includes the following attributes:name
- name of subscription (if none is supplied, a random subscription name will be generated)name_space
- name space for subscription (if none is supplied shared
will be used as the name space)my_role
- Pico A's role in the subscription (if none is supplied, peer
will be used for the role)subscriber_role
- Pico B's role in the subscription (also defaults to peer
). subscriber_eci
- Pico B's well known ECI. Pico A must receive an ECI to contact Pico B. (This eci will be stored after subscription has been accepted. only outbound eci should be used to raise events too.)channel_type
- the channel type for Pico A's yet to be created inbound ECI (if none is supplied, subs
will be used). attributes
- the attributes for this subscription. These are used for Pico A's incoming channel's attributes. wrangler:pending_subscription
event to Pico B, using the channel given by the subscriber_eci in step one with the following attributes:
name
- name of subscription.name_space
- name space for subscription.my_role
- Pico B's role in the subscription.subscriber_role
- Pico A's role in the subscription.outbound_eci
- Pico A's newly created inbound ECI. Pico B must receive an ECI to contact Pico A. channel_type
- the channel type for Pico B's yet to be created inbound ECI. attributes
- the attributes for this subscription. These are used for Pico B's incoming channel's attributes. wrangler:pending_subscription
event with the corresponding attributes above. wrangler:pending_subscription
event, Pico B, creates a pending subscription(channel mentioned above) and raises the wrangler:inbound_pending_subscription_event_added
internal event. Pico A raises wrangler:outbound_pending_subscription_event_added internal event.wrangler:pending_subscription_approval
event (internally) with an attribute named channel_name
giving the name of the channel to approve. Upon successfully creating the subscription. Pico B: wrangler:pending_subscription_approved
event to Pico A on Picos B outbound_eci.wrangler:subscription_added
eventwrangler:pending_subscription_approved
event, Pico A adds an outbound_eci to the subscription on its side and raises the wrangler:subscription_added
internal event. wrangler:inbound_subscription_rejection
event (internally) with an attribute named channel_name
- the name of the channel to reject. Pico B:wrangler:subscription_removal
event to Pico A on Picos B outbound_eci.wrangler:subscription_removal
event.Upon receiving a wrangler:subscription_removal
event, the pico deletes the named subscription from the inbound or outbound subscriptions list as appropriate.
Function | Use |
---|---|
subscriptions | List a set of subscriptions depending on what parameters are past. |
subscriptionAttributes | Lists a subscriptions attributes |
checkSubscriptionName | Checks if a subscriptions name exists |
All subscriptions functions return an object with a status and an return object except for checkSubscriptionName. Documentation will reference the return object only.
Event Domain | Event Type | Actions | Use |
---|---|---|---|
wrangler | subscription | creates outbound pending subscription and sends pending_subscription event to external pico | Creates a new outbound pending subscription |
wrangler | pending_subscription | creates inbound pending subscription | Creates a new inbound pending subscription |
wrangler | pending_subscription_approval | sends pending_subscription_approved event with inbound_eci and outbound status to external pico and raises pending_subscription_approved with inbound status | Aprove inbound pending subscription |
wrangler | pending_subscription_approved | updates subscription status and outbound_eci if needed | Internally for adding aproved subscriptions |
wrangler | subscription_cancellation | inbound_subscription_rejection | outbound_subscription_cancellation | sends subscription_removal event with eci and status and raise the same event to self | alert external pico to remove subscriptions and alert self to remove subscription |
wrangler | subscription_removal | deletes channel used for subscription | internally for removing channel used for subscription |
returns an array of subscriptions collections keyed to subscriptions. Each subscriptions is owned by the pico which calls this function.
Parameter | Datatype | Required |
---|---|---|
<id> | <string> |
|
<collection> | <string> | |
<filtered> | <string> |
On success
key | value |
---|---|
subscriptions | [{ <name_space:channel_name>: {"name_space":<string>, "relationship":<string>, "status":<string>, "channel_name":<string>, "inbound_eci":<string>, "subscriber_role":<string>, "my_role":<string>, "subscriber_eci":<string>, "attributes":<string>, "subscription_name":<string> } ,... }] |
response = v1_wrangler:subscriptions(null,null,null){"subscriptions"}; // all subscriptions response = v1_wrangler:subscriptions("flipper",null,null){"subscriptions"}; // single "flipper" subscriptions response = v1_wrangler:subscriptions(null,"status",null){"subscriptions"}; // collection of subscriptions by status response = v1_wrangler:subscriptions(null,"status","inbound"){"subscriptions"}; // collection of subscriptions with "inbound" as status |