kappa-db / workshop

let's learn how to write peer-to-peer applications in javascript!
https://kappa-db.github.io/workshop
71 stars 26 forks source link

Possible solutions to exercises 8/9 onwards #14

Closed aral closed 5 years ago

aral commented 5 years ago

It wasn’t immediately clear to me how to wire up the discovery swarm to the multifeed example in exercises 8 and 9.

The workshop currently doesn’t provide a solution for that and the topic is not picked up again until the game example, which uses kappa-core.

In case it helps, here’s one possible working solution that I came up with: https://github.com/aral/kappa-architecture-workshop-work-files/blob/master/multi-chat.js

Please feel free to modify/include it if you like.

The trickiest bit for me was realising that you had to wait until the multi.writer callback to join the swarm. If you don’t, the local feed does not get included in the replication and, on first run, replication doesn’t happen. (It does on subsequent attempts).

aral commented 5 years ago

And here’s another version that uses hyperswarm and kappa-core that could be integrated as a continuous exercise that maintains a functional chat app:

https://github.com/aral/kappa-architecture-workshop-work-files/blob/master/kappa-chat.js

aral commented 5 years ago

A possible solution to Exercise 13: https://github.com/aral/kappa-architecture-workshop-work-files/blob/master/kappa-chat-interface.js

Again, feel free to adapt, include, or ignore as you like :)

aral commented 5 years ago

A possible solution to Exercises 15-17 (the chat with player characters and movement):

https://source.ind.ie/aral/kappa-chat

Note: There seems to be an issue connecting to remote nodes:

  1. Run one local node
  2. Run a remote node (WAN/Internet)

They do not find each other via hyperswarm.

  1. Open a second local node.

Second local node finds the remote node immediately and the original local node usually connects a little while afterwards.

Might be due to the settings I’m passing to the hyperswarm constructor (none) and the join method (lookup: true, announce:true) as I don’t really understand how those properties interact and what they do concretely:

hackergrrl commented 5 years ago

Great points @aral. :sunny:

I've pushed some changes that clarify how to hook up discovery-swarm and multifeed together: both the solutions and the problem hints.

I don't have any advice on using hyperswarm though -- I'm still using discovery-swarm in my own stuff. :)