Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

feat!: convert to typescript #151

Merged
merged 27 commits into from
Mar 28, 2022
Merged

feat!: convert to typescript #151

merged 27 commits into from
Mar 28, 2022

Conversation

vogdb
Copy link
Contributor

@vogdb vogdb commented Mar 9, 2022

The PR is not ready for a merge. I've pushed it to ask some questions. The questions are posted as comments at the relevant source lines.

package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
@@ -49,11 +63,11 @@ module.exports = (socket, options = {}) => {
: undefined,

// If the remote address was passed, use it - it may have the peer ID encapsulated
remoteAddr: options.remoteAddr,
remoteAddr: options.remoteAddr ?? toMultiaddr(socket.remoteAddress ?? '', socket.remotePort ?? ''),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add this conversion because remoteAddr is required in MultiaddrConnection interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just throw if options.remoteAddr or socket.remoteAddress or socket.remotePort is nullish. Having a blank multiaddr or ill-formed multiaddr is not useful here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made remoteAddr option mandatory because all usages of ToConnectionOptions specify it. Please verify.

src/listener.ts Outdated
})

const maConn = toMultiaddrConnection(channel, {
remoteAddr: ipPortToMultiaddr(req.socket.remoteAddress, req.socket.remotePort)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we throw when req.socket.remoteAddress is undefined? It can be, according to the docs https://nodejs.org/api/net.html#class-netsocket

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's necessary or if its just used for diagnostics, @vasco-santos any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made remoteAddr option mandatory because all usages of ToConnectionOptions specify it. Please verify.

src/index.ts Outdated
const log = logger('libp2p:webrtcdirect')

export interface WebRTCDirectListenerOptions extends ListenerOptions{
channelOptions?: Object
Copy link
Contributor Author

@vogdb vogdb Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the same logic as in js-libp2p-webrtc-star/webrtc-star-transport. However I didn't describe the type of channelOptions. As far as this code is concerned, Object type looked fine but let me know if you want to describe it thoroughly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to describe the shape entirely, not use Object type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look. The exact shape is described here https://www.npmjs.com/package/libp2p-webrtc-peer#api. See constructor options:

{
  initiator: false,
  channelConfig: {},
  channelName: '<random string>',
  config: { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }, { urls: 'stun:global.stun.twilio.com:3478?transport=udp' }] },
  offerOptions: {},
  answerOptions: {},
  sdpTransform: function (sdp) { return sdp },
  stream: false,
  streams: [],
  trickle: true,
  allowHalfTrickle: false,
  wrtc: {}, // RTCPeerConnection/RTCSessionDescription/RTCIceCandidate
  objectMode: false
}

I described all the keys of this object. However for config key I used a plain object. Do you want me to describe it more rigid with iceServers and urls?

src/index.ts Outdated Show resolved Hide resolved
@vogdb
Copy link
Contributor Author

vogdb commented Mar 14, 2022

@vasco-santos @wemeetagain , please look when you have a minute.

- make `ToConnectionOptions` mandatory in `toMultiaddrConnection`
- make `remoteAddr` mandatory in `ToConnectionOptions`
- Update code to use interfaces from `@libp2p/interfaces`
- Update module name to use the `@libp2p/` scope
- Use the same `@libp2p/webrtc-peer` module as `@libp2p/webrtc-star`
- Update licenses, CI and project config to match other `@libp2p/` modules

BREAKING CHANGE: this module now only exports named exports and is ESM only
@achingbrain
Copy link
Member

achingbrain commented Mar 25, 2022

I've updated this PR to use the new @libp2p/* typescript modules, including the @libp2p/webrtc-peer module that is used by @libp2p/webrtc-star - this is the bits of simple-peer that we use ported to typescript - e.g. it's just a one-to-one RTC data channel without support for audio or video since we don't use that.

It also has auto-release now, should be all set up to go.

@achingbrain achingbrain changed the title feat: convert to typescript feat!: convert to typescript Mar 25, 2022
@achingbrain
Copy link
Member

GH actions is being really flaky today, only seems to run on about 1/2 of the commits.

Copy link
Member

@mpetrunic mpetrunic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@achingbrain achingbrain merged commit 85ce5cf into libp2p:master Mar 28, 2022
github-actions bot pushed a commit that referenced this pull request Mar 28, 2022
## [1.0.0](v0.7.1...v1.0.0) (2022-03-28)

### ⚠ BREAKING CHANGES

* this module is now ESM-only

Co-authored-by: achingbrain <alex@achingbrain.net>

### Features

* convert to typescript ([#151](#151)) ([85ce5cf](85ce5cf))

### Bug Fixes

* add 'node-pre-gyp' installation to 'check' and 'test-node' actions ([#152](#152)) ([bf4a68b](bf4a68b))

### Trivial Changes

* add note about `node-pre-gyp` to readme.md ([#141](#141)) ([ab4cc82](ab4cc82)), closes [#140](#140)
* **deps-dev:** bump aegir from 35.2.1 to 36.0.0 ([#139](#139)) ([720cfad](720cfad))
* replace Travis with Github Actions ([#150](#150)) ([a73735b](a73735b))
* update project config ([13ab340](13ab340))
* update Readme ([#148](#148)) ([ba9facb](ba9facb))
@github-actions
Copy link

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants