Channel State acts as a realtime data store attached to every Channel. You can update this state on your backend and frontend clients can subscribe to Channel state objects in realtime.

This reference assumes you have already set up the Hop server-side SDK.

Updating State

Channel state can be updated (manually) through the Hop Console or (programatically) through our server-side SDKs.

updating-state.js
// Import your Hop SDK instance
import {hop} from '.';

const channelId = 'channel_xxx'; // the channel we want to update

/*
 * - Option 1: Rewrite the state.
 * - The existing state is passed as the first arument to Channel#setState
 */

hop.channels.setState(channelId, s => ({...s, name: 'My Channel'}));

/*
 * - Option 2: Update or add variables
 * - This operation will only effect the variables you specify.
 * - The rest of the state will remain unchanged
 */

channel.patchState(channelId, {name: 'My Channel'});

Either of these operations will update the connected clients in realtime.