Skip to main content

Socket.io Client

The @feathersjs/socketio-client module provides real-time connectivity for Feathers client applications using Socket.io.

Installation

socketioClient()

Configures a Feathers client to use Socket.io for real-time communication.

Signature

Socket
required
Socket.io client connection instance from socket.io-client
object
Additional configuration options

Returns

TransportConnection<Services>
A transport connection that can be passed to app.configure()

Example

Connection Options

Socket.io connection options are passed when creating the socket:
string[]
default:"['polling', 'websocket']"
Transport methods to use (e.g., ['websocket'] for WebSocket only)
boolean
default:"true"
Whether to automatically reconnect
number
default:"1000"
Delay before reconnection attempt in milliseconds
number
default:"Infinity"
Maximum number of reconnection attempts
number
default:"20000"
Connection timeout in milliseconds
object
Authentication data sent with the connection handshake

Service Methods

Socket.io client services implement all standard Feathers service methods with real-time support:

find()

get()

create()

update()

patch()

remove()

Real-Time Events

Socket.io clients automatically receive real-time service events:

Event Listeners

Remove Event Listeners

Custom Methods

Register and use custom service methods:

Authentication

Integrate with Feathers authentication:

Re-authentication on Reconnect

Connection Events

Listen to Socket.io connection events:

Application Extensions

The Socket.io client extends the application with:
Socket
The Socket.io client instance for direct access

Example

Error Handling

Handle errors from service calls:

Params

Socket.io client params:
object
Query parameters for the service method
object
Custom headers (available in service hooks on server)

Example

Complete Example

Browser Usage