Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timeout when get room payload #11

Open
jcai opened this issue Jun 19, 2020 · 7 comments
Open

timeout when get room payload #11

jcai opened this issue Jun 19, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@jcai
Copy link

jcai commented Jun 19, 2020

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!

@huan
Copy link
Member

huan commented Jun 19, 2020

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 huan added the enhancement New feature or request label Jun 19, 2020
@jcai
Copy link
Author

jcai commented Jun 19, 2020

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

@huan
Copy link
Member

huan commented Jun 19, 2020

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

@chs97
Copy link
Contributor

chs97 commented Jun 30, 2020

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))
    })
  }

@huan
Copy link
Member

huan commented Jun 30, 2020

@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')

@chs97
Copy link
Contributor

chs97 commented Jun 30, 2020

@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?

@huan
Copy link
Member

huan commented Jun 30, 2020

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants