How to send external notifications only to clients not connected to a channel

I’m building a video call system. When users in a conversation join, they join a conversation:[id] channel. If a user is a first one to join the call, I’d like to send all users not currently connected a push notification (through Apple/Google/etc, not through Phoenix PubSub). I’m struggling to figure out how to query this information. Sockets inside a channel have their user_id attached, so that would be perfect, but it’s looking like that’s not possible? Is there a way? I could manage the state myself, but trying to avoid it if Phoenix is already tracking it for me.

It is probably good to have a common channel for all

and filter out with handle_out

sample code

  intercept ["join_game"]
  
  # Restrict push to players only
  def handle_out("join_game", payload, socket) do
    player_id = socket.assigns.current_user.id
    if (player_id === payload.challenger_id || player_id === payload.other_id) do
      push socket, "join_game", payload
      {:noreply, socket}
    else
      {:noreply, socket}
    end
  end
2 Likes

Thanks for replying! I’m not looking to send out a notification through Phoenix, it’s an Apple push notification, so there’s no handle_out involved. It looks like you can query presence data though, so I’ll probably go that route.

Ok, I see.

I saw you were using channels, But I didn’t notice You wanted to reply with something else :slight_smile:

Hope You’ll make it work