Skip to content

Commit f067400

Browse files
authored
Merge pull request #144 from dmotz/dev
IPFS update, test fixes
2 parents d3819bf + b8d0999 commit f067400

File tree

7 files changed

+106
-137
lines changed

7 files changed

+106
-137
lines changed

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"bracketSpacing": false,
77
"arrowParens": "avoid",
88
"endOfLine": "lf",
9-
"trailingComma": "none"
9+
"trailingComma": "none",
10+
"proseWrap": "always"
1011
}

README.md

Lines changed: 55 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,35 @@ on top of WebRTC:
2929
- 🏭⚡ Runs server-side
3030
- ⚛️🪝 React hooks
3131

32-
You can see what people are building with Trystero [here](https://github.com/jeremyckahn/awesome-trystero).
32+
You can see what people are building with Trystero
33+
[here](https://github.com/jeremyckahn/awesome-trystero).
3334

3435
---
3536

3637
## Contents
3738

38-
- [✨🤝✨ Trystero](#-trystero)
39-
- [Contents](#contents)
40-
- [How it works](#how-it-works)
41-
- [Get started](#get-started)
42-
- [Listen for events](#listen-for-events)
43-
- [Broadcast events](#broadcast-events)
44-
- [Audio and video](#audio-and-video)
45-
- [Advanced](#advanced)
46-
- [Binary metadata](#binary-metadata)
47-
- [Action promises](#action-promises)
48-
- [Progress updates](#progress-updates)
49-
- [Encryption](#encryption)
50-
- [React hooks](#react-hooks)
51-
- [Connection issues](#connection-issues)
52-
- [Running server-side (Node, Deno, Bun)](#running-server-side-node-deno-bun)
53-
- [Supabase setup](#supabase-setup)
54-
- [Firebase setup](#firebase-setup)
55-
- [API](#api)
56-
- [`joinRoom(config, roomId, [onJoinError])`](#joinroomconfig-roomid-onjoinerror)
57-
- [`selfId`](#selfid)
58-
- [`getRelaySockets()`](#getrelaysockets)
59-
- [`getOccupants(config, roomId)`](#getoccupantsconfig-roomid)
60-
- [Strategy comparison](#strategy-comparison)
61-
- [How to choose](#how-to-choose)
39+
- [How it works](#how-it-works)
40+
- [Get started](#get-started)
41+
- [Listen for events](#listen-for-events)
42+
- [Broadcast events](#broadcast-events)
43+
- [Audio and video](#audio-and-video)
44+
- [Advanced](#advanced)
45+
- [Binary metadata](#binary-metadata)
46+
- [Action promises](#action-promises)
47+
- [Progress updates](#progress-updates)
48+
- [Encryption](#encryption)
49+
- [React hooks](#react-hooks)
50+
- [Connection issues](#connection-issues)
51+
- [Running server-side (Node, Deno, Bun)](#running-server-side-node-deno-bun)
52+
- [Supabase setup](#supabase-setup)
53+
- [Firebase setup](#firebase-setup)
54+
- [API](#api)
55+
- [`joinRoom(config, roomId, [onJoinError])`](#joinroomconfig-roomid-onjoinerror)
56+
- [`selfId`](#selfid)
57+
- [`getRelaySockets()`](#getrelaysockets)
58+
- [`getOccupants(config, roomId)`](#getoccupantsconfig-roomid)
59+
- [Strategy comparison](#strategy-comparison)
60+
- [How to choose](#how-to-choose)
6261

6362
---
6463

@@ -126,8 +125,8 @@ const room = joinRoom(config, 'yoyodyne')
126125
```
127126

128127
The first argument is a configuration object that requires an `appId`. This
129-
should be a completely unique identifier for your app¹. The second argument
130-
is the room ID.
128+
should be a completely unique identifier for your app¹. The second argument is
129+
the room ID.
131130

132131
> Why rooms? Browsers can only handle a limited amount of WebRTC connections at
133132
> a time so it's recommended to design your app such that users are divided into
@@ -241,8 +240,8 @@ room.onPeerLeave(peerId =>
241240

242241
> Actions are smart and handle serialization and chunking for you behind the
243242
> scenes. This means you can send very large files and whatever data you send
244-
> will be received on the other side as the same type (a number as a number,
245-
> a string as a string, an object as an object, binary as binary, etc.).
243+
> will be received on the other side as the same type (a number as a number, a
244+
> string as a string, an object as an object, binary as binary, etc.).
246245
247246
## Audio and video
248247

@@ -403,8 +402,8 @@ means.
403402
Trystero functions are idempotent so they already work out of the box as React
404403
hooks.
405404

406-
Here's a simple example component where each peer syncs their favorite
407-
color to everyone else:
405+
Here's a simple example component where each peer syncs their favorite color to
406+
everyone else:
408407

409408
```jsx
410409
import {joinRoom} from 'trystero'
@@ -486,23 +485,24 @@ export const useRoom = (roomConfig, roomId) => {
486485
WebRTC is powerful but some networks simply don't allow direct P2P connections
487486
using it. If you find that certain user pairings aren't working in Trystero,
488487
you're likely encountering an issue at the network provider level. To solve this
489-
you can configure a TURN server which will act as a proxy layer for peers
490-
that aren't able to connect directly to one another.
488+
you can configure a TURN server which will act as a proxy layer for peers that
489+
aren't able to connect directly to one another.
491490

492491
1. If you can, confirm that the issue is specific to particular network
493492
conditions (e.g. user with ISP X cannot connect to a user with ISP Y). If
494493
other user pairings are working (like those between two browsers on the same
495494
machine), this likely confirms that Trystero is working correctly.
496495
2. Sign up for a TURN service or host your own. There are various hosted TURN
497-
services you can find online like [Cloudflare](https://developers.cloudflare.com/calls/turn/)
498-
(which offers a free tier with 1,000 GB traffic per month) or
496+
services you can find online like
497+
[Cloudflare](https://developers.cloudflare.com/calls/turn/) (which offers a
498+
free tier with 1,000 GB traffic per month) or
499499
[Open Relay](https://www.metered.ca/stun-turn). You can also host an open
500500
source TURN server like [coturn](https://github.com/coturn/coturn),
501501
[Pion TURN](https://github.com/pion/turn),
502502
[Violet](https://github.com/paullouisageneau/violet), or
503-
[eturnal](https://github.com/processone/eturnal). Keep in mind data will
504-
only go through the TURN server for peers that can't directly connect and
505-
will still be end-to-end encrypted.
503+
[eturnal](https://github.com/processone/eturnal). Keep in mind data will only
504+
go through the TURN server for peers that can't directly connect and will
505+
still be end-to-end encrypted.
506506
3. Once you have a TURN server, configure Trystero with it like this:
507507
```js
508508
const room = joinRoom(
@@ -549,9 +549,8 @@ To use the Supabase strategy:
549549

550550
1. Create a [Supabase](https://supabase.com) project or use an existing one
551551
2. On the dashboard, go to Project Settings -> API
552-
3. Copy the Project URL and set that as the `appId` in the Trystero config,
553-
copy the `anon public` API key and set it as `supabaseKey` in the Trystero
554-
config
552+
3. Copy the Project URL and set that as the `appId` in the Trystero config, copy
553+
the `anon public` API key and set it as `supabaseKey` in the Trystero config
555554

556555
### Firebase setup
557556

@@ -599,9 +598,9 @@ the same namespace will return the same room instance.
599598
- `config` - Configuration object containing the following keys:
600599
- `appId` - **(required)** A unique string identifying your app. When using
601600
Supabase, this should be set to your project URL (see
602-
[Supabase setup instructions](#supabase-setup)). If using
603-
Firebase, this should be the `databaseURL` from your Firebase config (also
604-
see `firebaseApp` below for an alternative way of configuring the Firebase
601+
[Supabase setup instructions](#supabase-setup)). If using Firebase, this
602+
should be the `databaseURL` from your Firebase config (also see
603+
`firebaseApp` below for an alternative way of configuring the Firebase
605604
strategy).
606605

607606
- `password` - **(optional)** A string to encrypt session descriptions via
@@ -651,15 +650,11 @@ the same namespace will return the same room instance.
651650
default). Changing this is useful if you want to run multiple apps using the
652651
same database and don't want to worry about namespace collisions.
653652

654-
- `libp2pConfig` - **(optional, 🪐 IPFS only)**
655-
[`Libp2pOptions`](https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html)
656-
where you can specify a list of static peers for bootstrapping.
657-
658653
- `manualRelayReconnection` - **(optional, 🐦 Nostr and 🌊 BitTorrent only)**
659-
Boolean (default: `false`) that when set to `true` disables
660-
automatically pausing and resuming reconnection attempts when the browser
661-
goes offline and comes back online. This is useful if you want to manage
662-
this behavior yourself.
654+
Boolean (default: `false`) that when set to `true` disables automatically
655+
pausing and resuming reconnection attempts when the browser goes offline and
656+
comes back online. This is useful if you want to manage this behavior
657+
yourself.
663658

664659
- `roomId` - A string to namespace peers and events within a room.
665660

@@ -678,8 +673,8 @@ Returns an object with the following methods:
678673

679674
Returns a map of
680675
[`RTCPeerConnection`](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection)s
681-
for the peers present in room (not including the local user). The keys of
682-
this object are the respective peers' IDs.
676+
for the peers present in room (not including the local user). The keys of this
677+
object are the respective peers' IDs.
683678

684679
- ### `addStream(stream, [targetPeers], [metadata])`
685680

@@ -803,8 +798,8 @@ Returns an object with the following methods:
803798

804799
Returns an array of three functions:
805800
1. #### Sender
806-
- Sends data to peers and returns a promise that resolves when all
807-
target peers are finished receiving data.
801+
- Sends data to peers and returns a promise that resolves when all target
802+
peers are finished receiving data.
808803

809804
- `(data, [targetPeers], [metadata], [onProgress])`
810805
- `data` - Any value to send (primitive, object, binary). Serialization
@@ -908,14 +903,14 @@ console.log(trystero.getRelaySockets())
908903
### `pauseRelayReconnection()`
909904

910905
**(🐦 Nostr, 🌊 BitTorrent only)** Normally Trystero will try to automatically
911-
reconnect to relay sockets unless `manualRelayReconnection: true` is set in
912-
the room config. Calling this function stops relay reconnection attempts until
906+
reconnect to relay sockets unless `manualRelayReconnection: true` is set in the
907+
room config. Calling this function stops relay reconnection attempts until
913908
`resumeRelayReconnection()` is called.
914909

915910
### `resumeRelayReconnection()`
916911

917-
**(🐦 Nostr, 🌊 BitTorrent, only)** Allows relay reconnection attempts to resume.
918-
(See `pauseRelayReconnection()` above).
912+
**(🐦 Nostr, 🌊 BitTorrent, only)** Allows relay reconnection attempts to
913+
resume. (See `pauseRelayReconnection()` above).
919914

920915
### `getOccupants(config, roomId)`
921916

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<body>
2424
<div id="canvas"></div>
2525
<header>
26-
<h1>🤝 Trystero<sup>0.21.5</sup></h1>
26+
<h1>🤝 Trystero<sup>0.22.0</sup></h1>
2727
<h2>Make any site multiplayer in a few lines.</h2>
2828
<h2>Serverless WebRTC matchmaking for painless P2P.</h2>
2929

package.json

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "trystero",
3-
"version": "0.21.8",
3+
"version": "0.22.0",
44
"description": "Serverless WebRTC matchmaking for painless P2P",
55
"main": "src/index.js",
66
"module": "src/index.js",
@@ -27,28 +27,26 @@
2727
"license": "MIT",
2828
"dependencies": {
2929
"@noble/secp256k1": "^3.0.0",
30-
"@supabase/supabase-js": "^2.49.8",
31-
"@waku/discovery": "^0.0.8",
32-
"@waku/sdk": "^0.0.31",
33-
"firebase": "^12.2.1",
34-
"libp2p": "^2.8.8",
35-
"mqtt": "^5.13.0"
30+
"@supabase/supabase-js": "^2.75.0",
31+
"@waku/sdk": "^0.0.35",
32+
"firebase": "^12.4.0",
33+
"mqtt": "^5.14.1"
3634
},
3735
"devDependencies": {
38-
"@eslint/js": "^9.27.0",
39-
"@playwright/test": "^1.52.0",
36+
"@eslint/js": "^9.37.0",
37+
"@playwright/test": "^1.56.0",
4038
"@rollup/plugin-commonjs": "^28.0.2",
41-
"@rollup/plugin-node-resolve": "^16.0.0",
39+
"@rollup/plugin-node-resolve": "^16.0.2",
4240
"@rollup/plugin-replace": "^6.0.2",
4341
"@rollup/plugin-terser": "^0.4.4",
44-
"chalk": "^5.6.0",
45-
"eslint": "^9.27.0",
46-
"globals": "^16.2.0",
47-
"playwright": "^1.52.0",
42+
"chalk": "^5.6.2",
43+
"eslint": "^9.37.0",
44+
"globals": "^16.4.0",
45+
"playwright": "^1.56.0",
4846
"prettier": "^3.5.2",
4947
"proxy-check": "^1.0.8",
50-
"rollup": "^4.49.0",
51-
"serve": "^14.2.4",
48+
"rollup": "^4.52.4",
49+
"serve": "^14.2.5",
5250
"stun": "^2.1.0",
5351
"ws": "^8.18.2"
5452
},

src/ipfs.d.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
declare module 'trystero/ipfs' {
22
import {BaseRoomConfig, Room} from 'trystero'
3-
import type {Libp2pOptions} from 'libp2p'
43

5-
export interface IpfsRoomConfig {
6-
libp2pConfig?: Partial<Libp2pOptions>
7-
}
8-
9-
export function joinRoom(
10-
config: BaseRoomConfig & IpfsRoomConfig,
11-
roomId: string
12-
): Room
4+
export function joinRoom(config: BaseRoomConfig, roomId: string): Room
135

146
export * from 'trystero'
157
}

src/ipfs.js

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
createDecoder,
3-
createEncoder,
4-
createLightNode,
5-
Protocols
6-
} from '@waku/sdk'
7-
import {wakuPeerExchangeDiscovery} from '@waku/discovery'
1+
import {createLightNode} from '@waku/sdk'
82
import strategy from './strategy.js'
93
import {
104
all,
@@ -15,40 +9,23 @@ import {
159
toJson
1610
} from './utils.js'
1711

18-
const pubsubTopic = '/waku/2/default-waku/proto'
19-
20-
const contentTopic = topic => `/${libName}/0/${topic}/json`
12+
const contentTopic = topic => `/${libName}-${topic}/0/msg/json`
2113

2214
const sendMessage = (node, topic, payload) =>
2315
node.lightPush.send(
24-
createEncoder({
25-
pubsubTopic,
26-
contentTopic: contentTopic(topic),
27-
ephemeral: true
28-
}),
29-
{payload: encodeBytes(payload)}
16+
node.createEncoder({contentTopic: contentTopic(topic), ephemeral: true}),
17+
{payload: encodeBytes(payload)},
18+
{autoRetry: true}
3019
)
3120

3221
export const joinRoom = strategy({
33-
init: config =>
22+
init: () =>
3423
createLightNode({
35-
defaultBootstrap: false,
36-
pubsubTopics: [pubsubTopic],
37-
bootstrapPeers: [
38-
'/dns4/waku.myrandomdemos.online/tcp/8000/wss/p2p/16Uiu2HAmKfC2QUvMVyBsVjuEzdo1hVhRddZxo69YkBuXYvuZ83sc',
39-
'/dns4/node-01.do-ams3.wakuv2.prod.status.im/tcp/8000/wss/p2p/16Uiu2HAmL5okWopX7NqZWBUKVqW8iUxCEmd5GMHLVPwCgzYzQv3e',
40-
'/dns4/node-01.gc-us-central1-a.wakuv2.prod.statusim.net/tcp/8000/wss/p2p/16Uiu2HAmVkKntsECaYfefR1V2yCR79CegLATuTPE6B9TxgxBiiiA',
41-
'/dns4/node-01.ac-cn-hongkong-c.wakuv2.prod.status.im/tcp/8000/wss/p2p/16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr24iDQpSN5Qa992BCjjwgrD',
42-
'/dns4/node-01.do-ams3.wakuv2.test.status.im/tcp/8000/wss/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ'
43-
],
44-
libp2p: {
45-
peerDiscovery: [wakuPeerExchangeDiscovery([pubsubTopic])],
46-
hideWebSocketInfo: true,
47-
...config.libp2pConfig
48-
}
24+
defaultBootstrap: true,
25+
discovery: {dns: true, peerExchange: true, peerCache: true}
4926
}).then(async node => {
5027
await node.start()
51-
await node.waitForPeers([Protocols.LightPush, Protocols.Filter])
28+
await node.waitForPeers()
5229
return node
5330
}),
5431

@@ -62,12 +39,11 @@ export const joinRoom = strategy({
6239
}
6340

6441
const unsubFns = await all(
65-
[rootTopic, selfTopic].map(topic =>
66-
node.filter.subscribe(
67-
createDecoder(contentTopic(topic), pubsubTopic),
68-
handleMsg(topic)
69-
)
70-
)
42+
[rootTopic, selfTopic].map(topic => {
43+
const decoder = node.createDecoder({contentTopic: contentTopic(topic)})
44+
node.filter.subscribe(decoder, handleMsg(topic))
45+
return () => node.filter.unsubscribe(decoder)
46+
})
7147
)
7248

7349
return () => unsubFns.forEach(f => f())

0 commit comments

Comments
 (0)