digidem / mapeo-mobile

Monitor and document the world around you
GNU General Public License v3.0
95 stars 16 forks source link

Bridging layer research for Mapeo-Core-Next #1106

Closed ErikSin closed 1 year ago

ErikSin commented 1 year ago

Research different architectures for bridging layers for Mapeo-Core-Next. Document the pros and con's of each, and that will be used to inform how we integrate Mapeo-Core-Next. We will eventually prototype the different types of architecture (For each architecture protyped please create a new ticket).

To Do:

achou11 commented 1 year ago

met today to discuss high level architecture. points of discussion included:

tomasciccola commented 1 year ago

I've made rpc-reflector work on the starter project. Some caveats to take into account:

One thing that I would like to try is having events sent from the backend without any rpc call from the client. I don't know if rpc-reflector provides a way to do this or if we should directly use nodejs.channel.addListener and rn_bridge.channel.send but probably @gmaclennan knows the answer to this. I'm closing this for know (but it can be reopen if anybody feels there's more research to be done)

gmaclennan commented 1 year ago

One thing that I would like to try is having events sent from the backend without any rpc call from the client.

@tomasciccola could you expand on this a bit more? What use case are you imagining? rpc-reflector does support event emitters and subscribing to events, so that on the server you can do:

class MyApi extends EventEmitter {
  constructor() {
    super()
    setInterval(() => this.emit('ticktock'), 1000)
  }
}

and on the client you can do:

const myApi = createClient(channel)
myApi.on('ticktock', () => console.log('ticktock'))

At least, that is how it should work.

If you need other events for coordinating server startup etc, then I recommend using a separate channel of communication, e.g. outside of the rpc-reflector instance. In nodejs mobile you can do this by using different event names, e.g. the default is message where-as for the example here you use @@API_MESSAGE.

tomasciccola commented 1 year ago

the use case I'm imagining is smth like the server sending update events that don't span from a call from the client. I don't know if applies to how mapeo-core is designed; but imagine smth like

// server
this.emit('observation:update', {id, ...})

where a record is updated and we want to send the updated version to the client without the client explicitly calling for it (like a live update)... Again, I don't know if that's a use case we have; it was just a doubt that I had...