plugin-contrib icon indicating copy to clipboard operation
plugin-contrib copied to clipboard

timeout when get room payload

Open jcai opened this issue 5 years ago • 7 comments

https://github.com/wechaty/wechaty-plugin-contrib/blob/05cfec3606480d2f2a544ac4e742a967bcaec2b4/src/contrib/room-connector/one-to-many-room-connector.ts#L105

If it's timeout to get room payload.the RoomConnector doesn't work!

jcai avatar Jun 19 '20 06:06 jcai

Yes! If we can not get the room payload, which means the room does not exist (from the program perspective), it will not be able to work anymore.

Please feel free to submit a PR to improve it to be more robust if you have any good idea, thanks!

huan avatar Jun 19 '20 08:06 huan

I think we should use a recursive method to fetch all rooms.I had implemented the feature in Scala-wechaty. see https://github.com/wechaty/scala-wechaty/blob/3119df7f5bcb244bc8f9e6c5c4cd52faa04cf435/wechaty/src/main/scala/wechaty/plugins/RoomConnector.scala#L48

jcai avatar Jun 19 '20 14:06 jcai

Thanks for the sharing! Will take a look into it later.

huan avatar Jun 19 '20 16:06 huan

maybe, shold waiting for all rooms to be ready, then send a message? example code like :


return function OneToManyRoomConnectorPlugin (wechaty: Wechaty) {
    log.verbose('WechatyPluginContrib', 'OneToManyRoomConnectorPlugin(%s) installing ...', wechaty)

    let manyRoomList : Room[]

    function waitingRoom(id: string): Promise<Room> {
        return new Promise((resolve, reject) => {
            const room = wechaty.Room.load(id)
            if (room.isReady()) {
                return resolve(room)
            }
            const timeoutTimer = setTimeout(() => {
                finish()
                return reject('timeout')
            }, timeout);
            const readyTimer = setInterval(() => {
                if (room.isReady()) {
                    finish()
                    return resolve(room)
                }
            }, 100)
            const finish = () => {
                clearTimeout(timeoutTimer)
                clearInterval(readyTimer)
            }
        })
    }

    wechaty.once('message', async onceMsg => {
      log.verbose('WechatyPluginContrib', 'OneToManyRoomConnectorPlugin(%s) once(message) installing ...', wechaty)

      if (!manyRoomList) {
        const waitingRooms = config.many.map(id => waitingRoom(id)) // should make sure all rooms ready?
        manyRoomList = Promise.all(waitingRooms)  // await loadRoom(wechaty, config.many)
      }

      matchAndForward(onceMsg, manyRoomList)
      wechaty.on('message', message => matchAndForward(message, manyRoomList))
    })
  }

chs97 avatar Jun 30 '20 06:06 chs97

@chs97 When we need to say in a room, that room does not require to be ready-ed.

The following code should work without any problem:

const room = wechaty.Room.load('your_room_id@chatroom')
// The following code will work without any problem no matter whether the room is ready-ed or not
await room.say('hello')

huan avatar Jun 30 '20 07:06 huan

@chs97 When we need to say in a room, that room does not require to be ready-ed.

The following code should work without any problem:

const room = wechaty.Room.load('your_room_id@chatroom')
// The following code will work without any problem no matter whether the room is ready-ed or not
await room.say('hello')

if room payload can't get successful, the message will send fail? and then, the roomConnector can't work actually? waiting for all rooms ready is a good choice?

chs97 avatar Jun 30 '20 07:06 chs97

@chs97

No. Whether the message can be sent successfully does not depend on the payload.

You can send a message successfully without load any payload because the underlying Puppet API of the messageSend() only needs the room-id.

huan avatar Jun 30 '20 08:06 huan