本文整理汇总了TypeScript中@feathersjs/feathers.ServerApp.channel方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ServerApp.channel方法的具体用法?TypeScript ServerApp.channel怎么用?TypeScript ServerApp.channel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@feathersjs/feathers.ServerApp
的用法示例。
在下文中一共展示了ServerApp.channel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
app.on('connection', (connection) => {
app.channel('anonymous').join(connection);
app.channel('all').join(connection);
app.channel('region:eu').join(connection);
});
示例2: async
return async (payload: Payload, meta: Meta) => {
if (meta.provider === 'rest') {
return;
}
try {
const user = await getUserFromPayload(app, payload);
if (user === null) {
return;
}
// Check if the userId is still authenticated on any other socket
const isStillConnected = app
.channel('authenticated')
.filter(connection => connection.user && connection.user.id === user.id)
.length > 0;
// Don't set the userId to online: false when the userId has still active sockets
if (isStillConnected) {
return;
}
await app.service('users').patch(user.id, {
online: false,
lastOnline: Date.now(),
});
log('Successfully logged out user', { userId: user.id });
} catch (error) {
log('Error in logout callback', { error });
}
};
示例3: async
return async (data, cb) => {
const user = connection.feathers.user;
// Make sure a userId is authenticated
if (!user) {
return cb(new NotAuthenticated());
}
const oldRegion = user.region;
try {
await app.service('users').patch(user.id, { region: data.region });
// Get every connection for the user
const connections = app
.channel(`region:${oldRegion}`)
.filter(conn => conn.user.id === user.id);
// Leave the old region channel and join the new one
connections.connections.forEach((conn) => {
app.channel(`region:${oldRegion}`).leave(conn);
app.channel(`region:${data.region}`).join(conn);
});
log('Successfully changed the region', {
userId: user.id,
data,
});
return cb(null);
} catch (error) {
log('Error while changing region', {
userId: user.id,
error,
data,
});
return cb(error);
}
};
示例4:
connections.connections.forEach((conn) => {
app.channel(`region:${oldRegion}`).leave(conn);
app.channel(`region:${data.region}`).join(conn);
});
示例5:
(data: UserSettings) => app
.channel('authenticated')
.filter(connection => connection.user.id === data.id),