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

The ding/dong way: how to create a communication channel between Wechaty and the deepest puppet provider #112

Open
huan opened this issue Aug 17, 2020 · 0 comments
Labels
enhancement New feature or request rfc

Comments

@huan
Copy link
Member

huan commented Aug 17, 2020

Background

The Wechaty ecosystem is involved very fast in the past months, we have lots of new features and bug fixes.

It is well designed and decoupled, that's why we can support multi-language and more and more puppet protocols without any difficulty.

However, sometimes we want to call the puppet methods freely and without any limitations, for example:

  1. We need to call some puppet methods for debugging
  2. We need to provide a new puppet feature very quickly (without modifying the puppet base class and the GRPC service)
  3. We want to test some puppet specified methods
  4. etc.

The Problem

If you want to call a puppet provider from Wechaty, what you can do is:

(wechaty.puppet as any).XXXMethod()

Which XXXMethod() is the method you want to call from your puppet. By using the wechaty.puppet as any trick, we can call any method on the puppet, even the private methods.

However, this is not deep enough when we are using the Hostie Puppet.

The hostie puppet is using the GRPC for providing a deeper decouple between Wechaty and puppets, which means that the Wechaty.puppet can not reach the real puppet behind the GRPC service.

The Solution

This solution came out when I have Chongqing hot pot with @lijiarui and @qhduan.

We can use our ding() method and the dong event to build an RPC channel between the Wechaty and the deepest puppet provider.

The design of the ding/dong mechanism is:

  1. wechaty.ding(data: string) is a method that can be called with a string parameter, on the Wechaty
  2. the ding() will be called on the puppet that provides the service to this Wechaty, the deepest one behind the GRPC service
  3. the puppet behind the GRPC service then will be able to emit a dong event, with a data payload, to pass a string back
  4. the wechaty will receive a dong event, with the same data payload from the puppet.

This lets us be able to build a channel to send/receive string data between the wechaty and puppet.

Then we can use a JSON-GRPC to do any remote grpc call based on this channel.

Conclusion

After I got this idea, I think it will be the best way to add the maximum flexibility to our Wechaty system for doing anything between the Wechaty and the puppet.

Will consider building an example with JSON-RPC to demonstrate this idea.

@huan huan added enhancement New feature or request rfc labels Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rfc
Projects
None yet
Development

No branches or pull requests

1 participant