wechaty / puppet-service

Wechaty Puppet Provider for providing/consuming the Wechaty Puppet Service
https://paka.dev/npm/wechaty-puppet-service
Apache License 2.0
72 stars 18 forks source link

[RFC] Support customize private host for wechaty-puppet-service server #123

Open windmemory opened 3 years ago

windmemory commented 3 years ago

I am wondering how does wechaty-puppet-serivce server register its host address? Is it possible that we can manually change the host address to a private ip address? So the client can connect to the server within private network to save some traffic, and make the system more secure?

huan commented 3 years ago

Thanks for creating this feature request.

I believe it's a scenario we should support.

A RFC will be welcome to start writing the request down in details and designing it.

windmemory commented 3 years ago

Since the current design for wechaty-puppet-service is using a websocket to register the server, how about we add one more parameter when we initialize the connection? I checked the code that create the connection with api.chatie.io, here is the code:

    if (!this.options.apihost) {
      throw new Error('no apihost')
    }
    let endpoint = 'wss://' + this.options.apihost + '/v0/websocket'

    if (!/api\.chatie\.io/.test(this.options.apihost)) {
      endpoint = 'ws://' + this.options.apihost + '/v0/websocket'
    }

    const ws = this.ws = new WebSocket(endpoint, this.protocol, { headers })

If we put a customize host into the header, this information will be passed to the discovery server, then the discovery server could use this customize ip.