How to use the phoenix.Presence.syncState function in phoenix

To help you get started, we’ve selected a few phoenix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / phoenix / phoenix-tests.ts View on Github external
if(!current){
        console.log("user has entered for the first time", newPres)
      } else {
        console.log("user additional presence", newPres)
      }
    };

    const onLeave = (id: string, current: any, leftPres: any) => {
      if(current.metas.length === 0){
        console.log("user has left from all devices", leftPres)
      } else {
        console.log("user left from a device", leftPres)
      }
    };

    state = Presence.syncState(state, stateFromServer, onJoin, onLeave);

    const listBy = (id: string, {metas: [first, ...rest]} : {metas: any[]}) => {
      first.count = rest.length + 1;
      first.id = id;

      return first;
    };

    const onlineUsers = Presence.list(state, listBy);
}
github rsilvestre / phoenix-react-redux-starter-kit / web / static / js / modules / session.js View on Github external
interfaceChannel.on('presence_state', state => {
            presences = Presence.syncState(presences, state)
            dispatch(updatePresences(Presence.list(presences, listBy)))
          })
github kenforthewin / mentat / assets / js / components / App.js View on Github external
this.channel.on("presence_state", state => {
      this.setState({
        ...this.state,
        presences: Presence.syncState(this.state.presences, state)
      });
    });
github bnhansn / sling / web / src / actions / room.js View on Github external
channel.on('presence_state', (state) => {
      presences = Presence.syncState(presences, state);
      syncPresentUsers(dispatch, presences);
    });
github akshaykmr / oorja / app / imports / ui / components / Room / index.js View on Github external
const handlePresenceState = (initialPresence) => {
      const syncedPresence = Presence.syncState(this.stateBuffer.presence, initialPresence);
      this.updateState({ presence: { $set: syncedPresence } });
      Object.keys(syncedPresence).forEach(this.handleJoin);
    };
github danieldocki / slack-clone-vuejs-elixir-phoenix / web / src / store / plugins.js View on Github external
channel.on('presence_state', (state) => {
            presences = Presence.syncState(presences, state)
            store.dispatch('syncPresentUsers', presences)
          })
github stride-nyc / remote_retro / web / static / js / components / remote_retro.js View on Github external
room.on("presence_state", state => {
      presences = Presence.syncState(presences, state)
      const users = values(presences).map(presence => presence.user)
      this.setState({ users })
    })