当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ServerApp.channel方法代码示例

本文整理汇总了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);

  });
开发者ID:TF2PickupNET,项目名称:TF2Pickup,代码行数:8,代码来源:configure-channels.ts

示例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 });
    }
  };
开发者ID:TF2PickupNET,项目名称:TF2Pickup,代码行数:33,代码来源:on-logout.ts

示例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);
    }
  };
开发者ID:TF2PickupNET,项目名称:TF2Pickup,代码行数:40,代码来源:on-change-region.ts

示例4:

 connections.connections.forEach((conn) => {
   app.channel(`region:${oldRegion}`).leave(conn);
   app.channel(`region:${data.region}`).join(conn);
 });
开发者ID:TF2PickupNET,项目名称:TF2Pickup,代码行数:4,代码来源:on-change-region.ts

示例5:

 (data: UserSettings) => app
   .channel('authenticated')
   .filter(connection => connection.user.id === data.id),
开发者ID:TF2PickupNET,项目名称:TF2Pickup,代码行数:3,代码来源:index.ts


注:本文中的@feathersjs/feathers.ServerApp.channel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。