@ feathersjs/ socket- commons (英语)
共享 Websocket 供应商的功能 @feathers/ socketio (英语) 财务报告和审定财务报表 @ feathersjs/ primus (英语)。仅打算供其他Feathers实时供应商内部使用.
关于
@feathersjs/socket-commons 包含Feathers实时供应商的内部共享功能(目前为Socket.io和Primus).
lib/client.js 是基本套接字服务客户端
lib/index.js 返回可配置的函数,并需要下列选项:
done- 承诺一旦建立实时协议服务器就能解决emit- 向套接字发送数据的方法的名称('emit'用于Socket.io和'send'用于Primus)socketKey- 存储实际套接字连接的字符串或ES6符号getParams- 返回套接字连接选项的函数
频道
频道为双向羽毛服务供应商提供频道功能. 例如被Socket.io和Primus提供商用来快速确定要发送到连接客户端的信息.
const channels = require('@feathersjs/socket-commons/lib/channels');
文档
app.channel(... names)
返回一个命名或合并的通道对象.
const channel = app.channel('test'); // return a `test` channel
channel.join(connection); // join a channel
channel.leave(connection); // leave a channel
channel.filter(connection => {}) // return a new channel with filtered connections
channel.length // return the number of connections
channel.connections // all connections in this channel
const combined = app.channel('test', 'other'); // return a combined channel
combined.join(connection); // join the `test` and `other` channel
combined.leave(connection); // leave the `test` and `other` channel
channel.filter(connection => {}) // return a new channel with filtered connections (connections will only be iterated once)
combined.length // return the number of connections
combined.connections // all connections in the combined channel (if a connection is in multiple channels it will only show once)
app.service('servicename').publish(event, callback), (中文(简体) ), app.service('servicename').publish(callback)
为返回(名称或合并)频道的服务和事件(或所有事件)注册一个出版回调.
app.use('/test', {
create(data) {
return Promise.resolve(data);
}
});
// `created` event for the `test` service
app.service('test').publish('created', (data, hook) =>
app.channel('*')
);
// `created` event for the `test` service, sending different data to two different channels
app.service('test').publish('created', (data, hook) => {
return [
app.channel('admins'),
app.channel('users').send(_.omit(data, 'groups', 'email'))
];
});
// All events for all services
app.publish((data, hook) =>
app.channel('*')
);
// All `created` events for all services
app.publish('created', (data, hook) =>
app.channel('*')
);
// All events for `test` service
app.service('test').publish((data, hook) =>
app.channel('*')
);
app.on('publish', function(event, channel, hook) {})
每次有连接要发布的服务事件都会发送的事件. channel 是一个包含所有连接的合并信道来发布此事件.
说明: 如果没有频道或连接
publish将不发送事件.
app.on('publish', (event, channel, hook) => {
channel.connections.forEach(connection => {
// Do something with `connection`
});
});
许可证
版权(c)2015年
凭 麻省理工学院许可证。 。 。 .
