Show:

Users.Socket Class

Replacements for Q.Socket methods, use these instead. They implement logic involving sockets, users, sessions, devices, and more.

Item Index

Methods

Methods

appId

(
  • platform
  • appId
)
Object static

Get the internal app id and info

Parameters:

  • platform String

    The platform or platform for the app

  • appId String

    Can be either an internal or external app id

Returns:

Object:

Has keys "appId" and "appInfo"

emitToUser

(
  • userId
  • event
  • data
  • excludeSessionIds={}
)
Boolean static

Emits an event to user's socket.io clients that are currently connected

Parameters:

  • userId String

    The id of the user

  • event String

    The name of the event the socket client should emit

  • data Object

    Any data to accompany this event name

  • excludeSessionIds={} Object

    Optional object containing {sessionId: true} for any session ids to skip while emitting the event.

Returns:

Boolean:

Whether any socket clients were connected at all

listen

(
  • options
)
socket.io

Start http server if needed, and start listening to socket. Use this instead of Users.socket This also attaches a few event handlers for Users events.

Parameters:

  • options Object

    Can be any options for the server.listen() in socket.io, as well as the following options:

    • host Object

      Set the hostname to listen on

    • port Object

      Set the port to listen on

    • https Object

      If you use https, pass https options here (see Q.listen)

Returns:

socket.io:

Events

connected

User has connected. Reconnections before disconnect timeout don't count.

Event Payload:

  • client Socket

    The connecting client. Contains userId, sessionId, clientId

  • online Boolean

    Whether any other clients were online for the user before this

disconnected

User has disconnected, and timeout for reconnection has passed

Event Payload:

  • userId String

    id of the user that disconnected