Members

Users can be added to a channel to become a Member of that channel. Application users can add members, remove members or get a list of members within a channel.

When you fetch a list of members it can include properties of users within the channel. These properties don't return the user's online/offline status. Refer to the presence section to retrieve presence details for these users.

State Shape

The data about Members is stored from the perspective of Channels and Users in a normalized structure. The following example shows the shape of Members in the store:

{
"byId":{
"channel_ac4e67b98b34b44c4a39466e93e":[
{
"id":"user_53bbe00387004010a8b9ad5f36bdd4a7",
"custom":{
"starred":true
}
}
]
}
}

Reducers

The PubNub Redux Framework provides reducers your app can implement that respond to various actions that update the store. To track the state of a set of objects in the store, combine the reducers you want into the rootReducer for your app.

createChannelMembersReducer

createChannelMembersReducer instantiates a reducer in the store that responds to actions dispatched to update the state of a channel's members, and all channel members, in the store.

createChannelMembersReducer();

Listeners

The PubNub Redux framework includes listeners that monitor PubNub events from the server and dispatch corresponding actions. All listeners are automatically invoked if your app registers the combined PubNub listener. You can register only specific listeners, or implement your own combine listeners function.

createMembershipListener

createMembershipListener registers a listener in the store that monitors Member events like such as MEMBERS_ADDED or MEMBERS_REMOVED, and dispatches corresponding actions to update the store.

A sample implementation of a single listener:

pubnub.addListener(createMembershipListener(store.dispatch));

Commands

The PubNub Redux framework provides commands that your app can dispatch to the store to be managed by the Thunk middleware. Commands interact with the PubNub API and dispatch basic actions which are then processed by reducers to update the state in the store.

fetchChannelMembers

Get the list of members in a specific channel.

fetchChannelMembers( request, [meta] );

fetchChannelMembers Arguments

ParameterTypeRequiredDescription
requestFetchChannelMembersRequestYesMembers request parameter object.
[meta]objectOptionalStandard meta options object.

fetchChannelMembers FetchChannelMembersRequest Properties

PropertyTypeRequiredDefaultDescription
channelstringYesThe name of the channel whose members you wish to retrieve.
filterstringOptionaln/aExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortstringOptionaln/aKey-value pair of a property to sort by, and a sort direction. Available options are updated, uuid.id, uuid.name, and uuid.updated.
Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending).
For example: {uuid.name: 'asc'}
limitnumberOptional100Maximum number of results to return per page
pageobjectOptionaln/aTo get the next set of results, specify next.
To get the previous set of results, specify prev.
If you specify both, prev is ignored.
{
    next: "next-page-id",
    prev: "prev-page-id"
}
includeobjectOptional{
    customFields: false,
    UUIDFields: false,
    customUUIDFields: false,
    totalCount: false
}
Specifies whether to include custom fields in the response, and whether to include a total result count.

fetchChannelMembers Sample Usage

dispatch(fetchMembers({
channel: 'channel_12345',
limit: '2'
}));

setChannelMembers

Set memberships for a list of users.

setChannelMembers( request, [meta] );

setChannelMembers Arguments

ParameterTypeRequiredDescription
requestMembersRequestYesMembers request parameter object.
[meta]objectOptionalStandard meta options object.

setChannelMembers MembersRequest Properties

PropertyTypeRequiredDefaultDescription
channelstringYesThe name of the channel.
uuidsArray of objectsYesArray of objects indicating the users(s) to be added, along with optional custom data.

[
    {
        id: "user-id-1"
        custom: { ... }
    },
    {
        id: "user-id-2"
        custom: { ... }
    },
]
filterstringOptionaln/aExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortstringOptionaln/aKey-value pair of a property to sort by, and a sort direction. Available options are updated, uuid.id, uuid.name, and uuid.updated.
Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending).
For example: {uuid.name: 'asc'}
limitnumberOptional100Maximum number of results to return per page
pageobjectOptionaln/aTo get the next set of results, specify next.
To get the previous set of results, specify prev.
If you specify both, prev is ignored.
{
    next: "next-page-id",
    prev: "prev-page-id"
}
includeobjectOptional{
    customFields: false,
    UUIDFields: false,
    customUUIDFields: false,
    totalCount: false
}
Specifies whether to include custom fields in the response, and whether to include a total result count.

setChannelMembers Sample Usage

dispatch(setChannelMembers({
channel: 'channel_ac4e67b98b34b44c4a39466e93e',
uuids: [ { id: 'user_53bbe00387004010a8b9ad5f36bdd4a7' } ]
}));

removeChannelMembers

Remove a list of members from a specific channel.

removeMembers( request, [meta] );

removeMembers Arguments

ParameterTypeRequiredDescription
requestMembersRequestYesMembers request parameter object.
[meta]objectOptionalStandard meta options object.

removeChannelMembers MembersRequest Properties

PropertyTypeRequiredDefaultDescription
channelstringYesThe ID of the space.
uuidsArray of stringsYesArray of user(s) to be removed.

["user-id-1","user-id-2"]
filterstringOptionaln/aExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sortstringOptionaln/aKey-value pair of a property to sort by, and a sort direction. Available options are updated, uuid.id, uuid.name, and uuid.updated.
Use asc or desc to specify sort direction, or specify null to take the default sort direction (ascending).
For example: {uuid.name: 'asc'}
limitnumberOptional100Maximum number of results to return per page
pageobjectOptionaln/aTo get the next set of results, specify next.
To get the previous set of results, specify prev.
If you specify both, prev is ignored.
{
    next: "next-page-id",
    prev: "prev-page-id"
}
includeobjectOptional{
    customFields: false,
    uuidFields: false,
    customUUIDFields: false,
    totalCount: false
}
Specifies whether to include custom fields in the response, and whether to include a total result count.

removeChannelMembers Sample Usage

dispatch(removeMembers({
channel: 'channel_ac4e67b98b34b44c4a39466e93e',
uuids: ['user_53bbe00387004010a8b9ad5f36bdd4a7']
}));