shinyoshiaki / werift-webrtc

WebRTC Implementation for TypeScript (Node.js), includes ICE/DTLS/SCTP/RTP/SRTP/WEBM/MP4
MIT License
463 stars 29 forks source link

Running the library client side without node server rendering #369

Closed bh90210 closed 6 months ago

bh90210 commented 6 months ago

Helloo, another day another problem.

I am using the library with nextjs with static site generator and I get this error

Unhandled Runtime Error

TypeError: crypto__WEBPACK_IMPORTED_MODULE_2___default().generateKeyPairSync is not a function
Source

pages/transfer/[[...token]].tsx (94:34) @ createOffer

  92 |      });
  93 |
> 94 |      pc.setLocalDescription(await pc.createOffer());
     |                                     ^
  95 |      const sdp = JSON.stringify(pc.localDescription);
  96 |
  97 |      const offerInfo = new OfferInfo();

and if I hunt down the problem it leads me to -> https://github.com/shinyoshiaki/werift-webrtc/blob/f63f2c661d866e8b054dc873e44c36614e4eb8e4/packages/webrtc/src/peerConnection.ts#L247 -> https://github.com/shinyoshiaki/werift-webrtc/blob/f63f2c661d866e8b054dc873e44c36614e4eb8e4/packages/webrtc/src/peerConnection.ts#L1311 -> https://github.com/shinyoshiaki/werift-webrtc/blob/f63f2c661d866e8b054dc873e44c36614e4eb8e4/packages/webrtc/src/transport/dtls.ts#L77 -> https://github.com/shinyoshiaki/werift-webrtc/blob/f63f2c661d866e8b054dc873e44c36614e4eb8e4/packages/dtls/src/context/cipher.ts#L109 where you make use of import nodeCrypto, { createSign } from "crypto"; node's crypto package. Of course the crypto is used elsewhere so my question is more general.

Is there a way to not use node but instead make use of https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API? I am trying to use the library on the browser (client side) with no server side rendering at all. I got this from https://stackoverflow.com/questions/62084998/typeerror-crypto-webpack-imported-module-5-generatekeypairsync-is-not-a-func

koush commented 6 months ago

This library is not for browsers. Use browser RTCPeerConnection.

werift is a WebRTC Implementation for TypeScript (Node.js), includes ICE/DTLS/SCTP/RTP.