@feathersjs/socket-commons
Shared functionality for websocket providers like @feathers/socketio and @feathersjs/primus. Only intended to be used internally by other Feathers real-time providers.
About
@feathersjs/socket-commons
contains internal shared functionality for Feathers real-time providers (currently Socket.io and Primus).
lib/client.js
is a base socket service client
lib/index.js
returns a configurable function and requires the following options:
done
- A Promise that resolves once the real-time protocol server has been set upemit
- The name of the method to emit data to a socket ('emit'
for Socket.io and 'send'
for Primus)socketKey
- A string or ES6 Symbol which stores the actual socket connectiongetParams
- A function that returns the Feathers connection options for a socket
Channels
Channels provide channel functionality for bi-directional Feathers service providers. It is e.g. used by the Socket.io and Primus provider to quickly determine what messages to send to connected clients.
const channels = require('@feathersjs/socket-commons/lib/channels');
Documentation
app.channel(... names)
Returns a named or combined channel object.
const channel = app.channel('test');
channel.join(connection);
channel.leave(connection);
channel.filter(connection => {})
channel.length
channel.connections
const combined = app.channel('test', 'other');
combined.join(connection);
combined.leave(connection);
channel.filter(connection => {})
combined.length
combined.connections
app.service('servicename').publish(event, callback)
, app.service('servicename').publish(callback)
Register a publishing callback for a service and event (or all events) that returns a (named or combined) channel.
app.use('/test', {
create(data) {
return Promise.resolve(data);
}
});
app.service('test').publish('created', (data, hook) =>
app.channel('*')
);
app.service('test').publish('created', (data, hook) => {
return [
app.channel('admins'),
app.channel('users').send(_.omit(data, 'groups', 'email'))
];
});
app.publish((data, hook) =>
app.channel('*')
);
app.publish('created', (data, hook) =>
app.channel('*')
);
app.service('test').publish((data, hook) =>
app.channel('*')
);
app.on('publish', function(event, channel, hook) {})
An event that will be sent every time a service event that has connections to publish to happens. channel
is a combined channel with all connections to publish the event to.
Note: If there are no channels or connections the publish
event will not be sent.
app.on('publish', (event, channel, hook) => {
channel.connections.forEach(connection => {
});
});
License
Copyright (c) 2015
Licensed under the MIT license.