Skip to content

Commit 09c33cc

Browse files
authored
fix: update project config (libp2p#65)
Updates project config using the `aegir check-project` command. * Updates CI files ahead of turning on unified CI * Resets project version to 0 (otherwise first version published will be 2.0.0) * Renames project to publish under @libp2p namespace * Standardises readme * Remove unused dependencies * Use chai from aegir * Fix formatting in example
1 parent 43c70bc commit 09c33cc

24 files changed

+295
-173
lines changed

.aegir.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ export default {
33
config: {
44
platform: 'node'
55
},
6-
bundlesizeMax: '31KB'
6+
bundlesizeMax: '117KB'
77
}
88
}

.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ updates:
66
interval: daily
77
time: "10:00"
88
open-pull-requests-limit: 10
9+
commit-message:
10+
prefix: "deps"
11+
prefix-development: "deps(dev)"

.github/workflows/automerge.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# File managed by web3-bot. DO NOT EDIT.
2-
# See https://github.com/protocol/.github/ for details.
3-
41
name: Automerge
52
on: [ pull_request ]
63

.github/workflows/js-test-and-release.yml

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,45 @@ on:
44
branches:
55
- main # with #262 - ${{{ github.default_branch }}}
66
pull_request:
7-
branches:
8-
- main # with #262 - ${{{ github.default_branch }}}
9-
- develop
107

118
jobs:
129

1310
check:
1411
runs-on: ubuntu-latest
1512
steps:
1613
- uses: actions/checkout@v3
17-
- uses: actions/setup-node@v2
14+
- uses: actions/setup-node@v3
1815
with:
1916
node-version: lts/*
2017
- uses: ipfs/aegir/actions/cache-node-modules@master
2118
- run: npm run --if-present lint
2219
- run: npm run --if-present dep-check
2320

21+
test-node:
22+
needs: check
23+
runs-on: ${{ matrix.os }}
24+
strategy:
25+
matrix:
26+
os: [windows-latest, ubuntu-latest, macos-latest]
27+
node: [lts/*]
28+
fail-fast: true
29+
steps:
30+
- uses: actions/checkout@v3
31+
- uses: actions/setup-node@v3
32+
with:
33+
node-version: ${{ matrix.node }}
34+
- uses: ipfs/aegir/actions/cache-node-modules@master
35+
- run: npm run --if-present test:node
36+
- uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
37+
with:
38+
flags: node
39+
2440
test-chrome:
2541
needs: check
2642
runs-on: ubuntu-latest
2743
steps:
2844
- uses: actions/checkout@v3
29-
- uses: actions/setup-node@v2
45+
- uses: actions/setup-node@v3
3046
with:
3147
node-version: lts/*
3248
- uses: ipfs/aegir/actions/cache-node-modules@master
@@ -35,12 +51,26 @@ jobs:
3551
with:
3652
flags: chrome
3753

54+
test-chrome-webworker:
55+
needs: check
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v3
59+
- uses: actions/setup-node@v3
60+
with:
61+
node-version: lts/*
62+
- uses: ipfs/aegir/actions/cache-node-modules@master
63+
- run: npm run --if-present test:chrome-webworker
64+
- uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
65+
with:
66+
flags: chrome-webworker
67+
3868
test-firefox:
3969
needs: check
4070
runs-on: ubuntu-latest
4171
steps:
4272
- uses: actions/checkout@v3
43-
- uses: actions/setup-node@v2
73+
- uses: actions/setup-node@v3
4474
with:
4575
node-version: lts/*
4676
- uses: ipfs/aegir/actions/cache-node-modules@master
@@ -49,15 +79,57 @@ jobs:
4979
with:
5080
flags: firefox
5181

82+
test-firefox-webworker:
83+
needs: check
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v3
87+
- uses: actions/setup-node@v3
88+
with:
89+
node-version: lts/*
90+
- uses: ipfs/aegir/actions/cache-node-modules@master
91+
- run: npm run --if-present test:firefox-webworker
92+
- uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
93+
with:
94+
flags: firefox-webworker
95+
96+
test-electron-main:
97+
needs: check
98+
runs-on: ubuntu-latest
99+
steps:
100+
- uses: actions/checkout@v3
101+
- uses: actions/setup-node@v3
102+
with:
103+
node-version: lts/*
104+
- uses: ipfs/aegir/actions/cache-node-modules@master
105+
- run: npx xvfb-maybe npm run --if-present test:electron-main
106+
- uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
107+
with:
108+
flags: electron-main
109+
110+
test-electron-renderer:
111+
needs: check
112+
runs-on: ubuntu-latest
113+
steps:
114+
- uses: actions/checkout@v3
115+
- uses: actions/setup-node@v3
116+
with:
117+
node-version: lts/*
118+
- uses: ipfs/aegir/actions/cache-node-modules@master
119+
- run: npx xvfb-maybe npm run --if-present test:electron-renderer
120+
- uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
121+
with:
122+
flags: electron-renderer
123+
52124
release:
53-
needs: [test-chrome, test-firefox]
125+
needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-electron-main, test-electron-renderer]
54126
runs-on: ubuntu-latest
55-
if: github.event_name == 'push' && github.ref == 'refs/heads/master' # with #262 - 'refs/heads/${{{ github.default_branch }}}'
127+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' # with #262 - 'refs/heads/${{{ github.default_branch }}}'
56128
steps:
57129
- uses: actions/checkout@v3
58130
with:
59131
fetch-depth: 0
60-
- uses: actions/setup-node@v2
132+
- uses: actions/setup-node@v3
61133
with:
62134
node-version: lts/*
63135
- uses: ipfs/aegir/actions/cache-node-modules@master

.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

.prettierrc

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,43 @@
11
# @libp2p/webrtc <!-- omit in toc -->
22

33
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4-
[![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
54
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
6-
[![codecov](https://img.shields.io/codecov/c/github/little-bear-labs/js-libp2p-webrtc.svg?style=flat-square)](https://codecov.io/gh/little-bear-labs/js-libp2p-webrtc)
7-
[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/little-bear-labs/js-libp2p-webrtc/actions/workflows/js-test-and-release.yml)
5+
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-webrtc.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-webrtc)
6+
[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-webrtc/test%20&%20maybe%20release/main?style=flat-square)](https://github.com/libp2p/js-libp2p-webrtc/actions/workflows/js-test-and-release.yml)
87

9-
> The browser implementation of the WebRTC module for libp2p.
8+
> A libp2p transport using WebRTC connections
109
1110
## Table of contents <!-- omit in toc -->
1211

1312
- [Install](#install)
13+
- [Browser `<script>` tag](#browser-script-tag)
1414
- [Usage](#usage)
1515
- [Examples](#examples)
1616
- [Interfaces](#interfaces)
1717
- [Transport](#transport)
1818
- [Connection](#connection)
19-
- [Contribute](#contribute)
19+
- [Development](#development)
2020
- [Build](#build)
2121
- [Protocol Buffers](#protocol-buffers)
2222
- [Test](#test)
2323
- [Lint](#lint)
2424
- [Clean](#clean)
2525
- [Check Dependencies](#check-dependencies)
26-
- [Build a Release](#build-a-release)
2726
- [License](#license)
28-
- [Contribution](#contribution)
27+
- [Contribute](#contribute)
2928

3029
## Install
3130

32-
```shell
33-
npm i @libp2p/webrtc
31+
```console
32+
$ npm i @libp2p/webrtc
33+
```
34+
35+
### Browser `<script>` tag
36+
37+
Loading this module through a script tag will make it's exports available as `Libp2pWebrtc` in the global namespace.
38+
39+
```html
40+
<script src="https://unpkg.com/@libp2p/webrtc/dist/index.min.js"></script>
3441
```
3542

3643
## Usage
@@ -52,13 +59,14 @@ const node = await createLibp2p({
5259
await node.start()
5360

5461
const ma = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ')
55-
const stream = await node.dialProtocol(ma, ['/my-protocol/1.0.0'])
62+
const stream = await node.dialProtocol(ma, ['/my-protocol/1.0.0'])
5663
const message = `Hello js-libp2p-webrtc\n`
5764
const response = await pipe([fromString(message)], stream, async (source) => await first(source))
5865
const responseDecoded = toString(response.slice(0, response.length))
5966
```
6067

6168
## Examples
69+
6270
Examples can be found in the [examples folder](examples/README.md).
6371

6472
## Interfaces
@@ -106,7 +114,7 @@ interface MultiaddrConnection extends Duplex<Uint8Array> {
106114
class WebRTCMultiaddrConnection implements MultiaddrConnection { }
107115
```
108116

109-
## Contribute
117+
## Development
110118

111119
Contributions are welcome! The libp2p implementation in JavaScript is a work in progress. As such, there's a few things you can do right now to help out:
112120

@@ -119,9 +127,10 @@ Please be aware that all interactions related to libp2p are subject to the IPFS
119127

120128
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
121129

122-
This module leans heavily on (Aegir)[https://github.com/ipfs/aegir] for most of the `package.json` scripts.
130+
This module leans heavily on (Aegir)\[<https://github.com/ipfs/aegir>] for most of the `package.json` scripts.
123131

124132
### Build
133+
125134
The build script is a wrapper to `aegir build`. To build this package:
126135

127136
```shell
@@ -142,7 +151,7 @@ To run all tests:
142151
npm test
143152
```
144153

145-
To run tests for Chome only:
154+
To run tests for Chrome only:
146155

147156
```shell
148157
npm run test:chrome
@@ -155,8 +164,9 @@ npm run test:firefox
155164
```
156165

157166
### Lint
167+
158168
Aegir is also used to lint the code, which follows the [Standard](https://github.com/standard/standard) JS linter.
159-
The VS Code plugin for this standard is located at https://marketplace.visualstudio.com/items?itemName=standard.vscode-standard.
169+
The VS Code plugin for this standard is located at <https://marketplace.visualstudio.com/items?itemName=standard.vscode-standard>.
160170
To lint this repo:
161171

162172
```shell
@@ -181,18 +191,13 @@ npm run clean
181191
npm run deps-check
182192
```
183193

184-
### Build a Release
185-
186-
```shell
187-
npm run release
188-
```
189194
## License
190195

191196
Licensed under either of
192197

193198
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
194199
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
195200

196-
## Contribution
201+
## Contribute
197202

198-
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
203+
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

examples/browser-to-server/index.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@ import { pipe } from "it-pipe";
66
import { fromString, toString } from "uint8arrays";
77
import { webRTC } from 'js-libp2p-webrtc'
88

9-
let stream;
10-
const output = document.getElementById('output')
11-
const sendSection = document.getElementById('send-section')
12-
const appendOutput = (line) => output.innerText += `${line}\n`
13-
const clean = (line) => line.replaceAll('\n', '')
9+
let stream;
10+
const output = document.getElementById('output')
11+
const sendSection = document.getElementById('send-section')
12+
const appendOutput = (line) => output.innerText += `${line}\n`
13+
const clean = (line) => line.replaceAll('\n', '')
1414

15-
const node = await createLibp2p({
16-
transports: [webRTC()],
17-
connectionEncryption: [() => new Noise()],
18-
});
19-
20-
await node.start()
15+
const node = await createLibp2p({
16+
transports: [webRTC()],
17+
connectionEncryption: [() => new Noise()],
18+
});
2119

22-
node.connectionManager.addEventListener('peer:connect', (connection) => {
23-
appendOutput(`Peer connected '${node.getConnections().map(c => c.remoteAddr.toString())}'`)
24-
sendSection.style.display = 'block'
25-
})
26-
27-
window.connect.onclick = async () => {
28-
const ma = multiaddr(window.peer.value)
29-
appendOutput(`Dialing ${ma}`)
30-
stream = await node.dialProtocol(ma, ['/echo/1.0.0'])
31-
}
32-
33-
window.send.onclick = async () => {
34-
const message = `${window.message.value}\n`
35-
appendOutput(`Sending message '${clean(message)}'`)
36-
const response = await pipe([fromString(message)], stream, async (source) => await first(source))
37-
const responseDecoded = toString(response.slice(0, response.length));
38-
appendOutput(`Received message '${clean(responseDecoded)}'`)
39-
}
20+
await node.start()
21+
22+
node.connectionManager.addEventListener('peer:connect', (connection) => {
23+
appendOutput(`Peer connected '${node.getConnections().map(c => c.remoteAddr.toString())}'`)
24+
sendSection.style.display = 'block'
25+
})
26+
27+
window.connect.onclick = async () => {
28+
const ma = multiaddr(window.peer.value)
29+
appendOutput(`Dialing ${ma}`)
30+
stream = await node.dialProtocol(ma, ['/echo/1.0.0'])
31+
}
32+
33+
window.send.onclick = async () => {
34+
const message = `${window.message.value}\n`
35+
appendOutput(`Sending message '${clean(message)}'`)
36+
const response = await pipe([fromString(message)], stream, async (source) => await first(source))
37+
const responseDecoded = toString(response.slice(0, response.length));
38+
appendOutput(`Received message '${clean(responseDecoded)}'`)
39+
}

0 commit comments

Comments
 (0)