beakerbrowser / dat-node

A toolkit for writing Dat-based services in nodejs
37 stars 6 forks source link

Implement DatPeers API #6

Open RangerMauve opened 6 years ago

RangerMauve commented 6 years ago

Closes #3

It's kinda rough, but I based it on the implementation in beaker-core and added an easy interface for it.

I've tested it out with this page and it all seems to be working.

pfrazee commented 6 years ago

Looks good, would you mind adding some automated tests for it? Beaker has some you can use as a reference.

RangerMauve commented 6 years ago

Awesome! I'll try to get on that this week. :D

RangerMauve commented 6 years ago

I see the archives.test.js file is empty. Should I use ava for the tests since that's what beaker is using?

pfrazee commented 6 years ago

😅 oh right, I forgot that I haven't gotten any tests into this thing either. What a hypocrite!

Yeah would you mind? ava is what I'd want to use.

RangerMauve commented 6 years ago

Yeah, no prob! I'll just copy the tests from beaker verbatim and convert it to use the dat-node APIs instead of electron/beaker.

RangerMauve commented 6 years ago

I've copied over the tests, but something weird is happening. Would you mind looking to see if I have some glaring mistake I'm missing?

When it uses getSessionData() on the first datPeers instance, it reports "right" even though I invoke setSessionData("left") earlier.

It's like the session data is being transferred between the peers, I'm not sure how that can be happening though.

pfrazee commented 6 years ago

Sure I'll check into it. Thanks for putting the tests together!

RangerMauve commented 6 years ago

No rush! I'll take another shot at it later this week. :D

pfrazee commented 6 years ago

I did some debugging and found at least one case of arguments being in the wrong order, https://github.com/beakerbrowser/dat-node/pull/6/files#diff-e658a4aa904bdaccea0046252d2e13d3R83

That didn't solve the issues but I'd look for things like that

RangerMauve commented 6 years ago

K, looking into it a bit today. So far it seems that broadcast just isn't working. Not sure if it's a sending issue, a receiving issue, or me not relaying events properly.

RangerMauve commented 6 years ago

So, this is weird. I think it's a timing issue in the tests. When I use dat-node in a REPL, it seems to work fine. But when it runs in the tests, the sessionData isn't being set. :S

RangerMauve commented 6 years ago

K, so the first problem was that I was creating a single instance of datEphemeralExtMsg / datSessionDataExtMsg that was shared between both dat-node instances. 🤦‍♂️

Now I can get/set session data properly, but the broadcasting still isn't working. That part might be a timing issue. Gonna look into it more another day.

RangerMauve commented 6 years ago

I'm at a bit of a loss here.

When I test it out with the browser it seems to be working OK, but I'm not able to get two instances of dat node in the tests to work.

Any help would be very much appreciated.

pfrazee commented 6 years ago

@RangerMauve sure thing. Just push up your latest code and I'll dig around a bit.

RangerMauve commented 6 years ago

It's pushed. 😁