feathersjs 频道的事件不会传到客户端
Events of feathersjs channels do not come through to client
我在 their guide 之后设置了一个非常基本的 Featherjs 频道。所以在服务器上我有:
module.exports = app => {
// If no real-time functionality has been configured just return
if (typeof app.channel !== 'function') return
app.on('connection', connection => {
// On a new real-time connection, add it to the anonymous channel
app.channel('anonymous').join(connection)
})
app.on('login', (authResult, {connection}) => {
// connection can be undefined if there is no
// real-time connection, e.g. when logging in via REST
if (connection) {
// Obtain the logged in user from the connection
const {user} = connection
// When the connection is no longer anonymous (as you the user is logged in), remove it
app.channel('anonymous').leave(connection)
// Add it to the authenticated user channel
app.channel('authenticated').join(connection)
}
})
app.publish((data, hook) => {
return app.channel('authenticated')
})
app.service('points').publish('created', () => app.channel('authenticated'))
}
在我的客户中:
api.on('authenticated', response => {
console.log('Yes, here is the event from the channel: ', response)
})
此设置应提供来自我所有 featherjs 服务的所有事件。但是,当我登录时,我只会在我的客户端上收到一个事件。当我随后通过我的 feathers api 服务创建对象时,没有显示任何内容/没有任何事件通过。为什么不呢?
authenticated event 是一个纯粹的客户端事件,当客户端验证成功时将被触发。它不是从服务器发送的事件。
频道仅适用于从服务器发送的service events。对于您的示例,这意味着使用类似
app.service('points').on('created', point => {})
在客户端。客户端只有在通过身份验证后才会收到 created
事件。
我在 their guide 之后设置了一个非常基本的 Featherjs 频道。所以在服务器上我有:
module.exports = app => {
// If no real-time functionality has been configured just return
if (typeof app.channel !== 'function') return
app.on('connection', connection => {
// On a new real-time connection, add it to the anonymous channel
app.channel('anonymous').join(connection)
})
app.on('login', (authResult, {connection}) => {
// connection can be undefined if there is no
// real-time connection, e.g. when logging in via REST
if (connection) {
// Obtain the logged in user from the connection
const {user} = connection
// When the connection is no longer anonymous (as you the user is logged in), remove it
app.channel('anonymous').leave(connection)
// Add it to the authenticated user channel
app.channel('authenticated').join(connection)
}
})
app.publish((data, hook) => {
return app.channel('authenticated')
})
app.service('points').publish('created', () => app.channel('authenticated'))
}
在我的客户中:
api.on('authenticated', response => {
console.log('Yes, here is the event from the channel: ', response)
})
此设置应提供来自我所有 featherjs 服务的所有事件。但是,当我登录时,我只会在我的客户端上收到一个事件。当我随后通过我的 feathers api 服务创建对象时,没有显示任何内容/没有任何事件通过。为什么不呢?
authenticated event 是一个纯粹的客户端事件,当客户端验证成功时将被触发。它不是从服务器发送的事件。
频道仅适用于从服务器发送的service events。对于您的示例,这意味着使用类似
app.service('points').on('created', point => {})
在客户端。客户端只有在通过身份验证后才会收到 created
事件。