weixin_39709367
weixin_39709367
2020-12-01 19:49

Comment: Channels (api/channels.md)

Deleting channels

What about unused, empty channels?

My app's channels can multiply very fast, keeping less than 10 connections and getting useless at the end of a brief session. I haven't noticed any method to delete a channel. Even though a channel's footprint may be as small as its name, this is bothering me. I have created a service to track connections/channels and it just displays too many useless channels!

What do you think?

Thank you.

该提问来源于开源项目:feathersjs/docs

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

6条回答

  • weixin_39987985 weixin_39987985 5月前

    Clearing them out wouldn't be that hard (you have to import the Symbol that is used as the key though):

    js
    const { keys } = require('/transport-commons').channels;
    const { CHANNELS } = keys;
    
    app.channels.forEach(name => {
      if(app.channel(name).length === 0) {
        delete app[CHANNELS][name];
      }
    });
    

    The challenge is when to run this. Technically every time .leave is called but since a channel doesn't know about the app and channel doesn't know about its name it's a little tricky.

    点赞 评论 复制链接分享
  • weixin_39709367 weixin_39709367 5月前

    Thanks for the quick (and clear) answer!

    点赞 评论 复制链接分享
  • weixin_39987985 weixin_39987985 5月前

    I think it's a good point that empty channels should be deleted. I think I can make that happen by also turning the channel objects into event emitters and listening to an empty event on which it will be deleted from the CHANNEL object.

    点赞 评论 复制链接分享
  • weixin_39709367 weixin_39709367 5月前

    Sounds great! Is it something you plan to implement in Feathers core in a next future?

    点赞 评论 复制链接分享
  • weixin_39987985 weixin_39987985 5月前

    It turned out to be fairly simple actually. The pull request is at https://github.com/feathersjs/transport-commons/pull/75

    点赞 评论 复制链接分享
  • weixin_39691233 weixin_39691233 5月前

    Hi, I have a question similar to this discussion: Is there any way or event that tells when a client is disconnected on socket from the server ? There is app.on('connection') event but is there any similar like app.on('disconnect'). I know there is a logout event but sometimes users will be offline for other reasons e.g. no internet

    点赞 评论 复制链接分享

相关推荐