Comments (2)
The problem is that conditional that checks for window
makes TypeScript think it could be undefined and not able to be destructured. Is that client check necessary if you're using 'use client'
?
In any case, makeAction()
isn't really a hook, just a normal function, so you can call it conditionally wherever you'd like.
from trystero.
Next.JS 13/14 renders everything completely on the server by default.
use client
does opt out of React Server Components but you can still get Server Side Rendering and client-side hydration with Next.JS.
So if I use the following code:
"use client"
import {joinRoom} from 'trystero'
import {useEffect, useRef} from 'react'
export const useRoom = (roomConfig, roomId) => {
const roomRef = useRef(joinRoom(roomConfig, roomId))
useEffect(() => {
roomRef.current = joinRoom(roomConfig, roomId)
return () => roomRef.current.leave()
}, [roomConfig, roomId])
return roomRef.current
}
I'll get the following error from trystero
:
node_modules/simple-peer-light/index.js (98:0) @ new Peer
⨯ unhandledRejection: Error: No WebRTC support: Specify `opts.wrtc` option in this environment
at new Peer (webpack-internal:///(ssr)/./node_modules/simple-peer-light/index.js:102:11)
at initPeer (webpack-internal:///(ssr)/./node_modules/trystero/src/utils.js:26:16)
at eval (webpack-internal:///(ssr)/./node_modules/trystero/src/torrent.js:64:75)
at Array.map (<anonymous>)
at makeOffers (webpack-internal:///(ssr)/./node_modules/trystero/src/torrent.js:63:10)
at makeOfferPool (webpack-internal:///(ssr)/./node_modules/trystero/src/torrent.js:73:31)
at announceAll (webpack-internal:///(ssr)/./node_modules/trystero/src/torrent.js:235:17) {
code: 'ERR_WEBRTC_SUPPORT'
So directly calling joinRoom
in the useRef
doesn't work with Next.JS. I could make a new issue if you consider this a bug.
Anyway, being able to call makeAction
conditionally solves this problem. Thanks for the tip!
from trystero.
Related Issues (20)
- [Question] `trackerRedundancy` maximum of 3 HOT 2
- Uncaught Error: Service database is not available HOT 3
- question: project status HOT 7
- Demo is not working for me HOT 6
- What is needed to self-host with custom BT trackers? HOT 1
- Does Trystero only support wss:// trackers? HOT 2
- Does the tracker need to pre-host a torrent for Trystero to work? HOT 1
- [Feature Request] - Make joinRoom and makeAction suitable for use as React Hooks. HOT 2
- [Question]: Detecting incorrect passwords HOT 1
- Can all peers see each others IP addresses? HOT 2
- Callbacks and leave() seem unreliable? HOT 2
- Firebase - Service database is not available HOT 2
- Unable to import trystero HOT 4
- stripped zoom example
- WebRTC connection takes 5~10 seconds and multiple ICE TURN servers fail HOT 7
- Add nostr support? HOT 8
- Mentioned your project HOT 1
- IPFS configuration/example? HOT 2
- using a tracker swarm module for redundancy and fall backs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trystero.