kappa-db / workshop

let's learn how to write peer-to-peer applications in javascript!

Home Page:https://kappa-db.github.io/workshop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible solutions to exercises 8/9 onwards

aral opened this issue · comments

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

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

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

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:

  • ephemeral
  • lookup
  • announce

Great points @aral. ☀️

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. :)