forked from Shiloh/remnantchat
feat: join peer room
This commit is contained in:
parent
583c808f4e
commit
519e27b5c2
11
package-lock.json
generated
11
package-lock.json
generated
@ -26,7 +26,7 @@
|
|||||||
"react-router-dom": "^6.3.0",
|
"react-router-dom": "^6.3.0",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"sass": "^1.54.3",
|
"sass": "^1.54.3",
|
||||||
"trystero": "^0.11.1",
|
"trystero": "github:jeremyckahn/trystero#bugfix/fully-qualified-module-resolution",
|
||||||
"typeface-public-sans": "^1.1.13",
|
"typeface-public-sans": "^1.1.13",
|
||||||
"typeface-roboto": "^1.1.13",
|
"typeface-roboto": "^1.1.13",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
@ -21963,8 +21963,8 @@
|
|||||||
},
|
},
|
||||||
"node_modules/trystero": {
|
"node_modules/trystero": {
|
||||||
"version": "0.11.1",
|
"version": "0.11.1",
|
||||||
"resolved": "https://registry.npmjs.org/trystero/-/trystero-0.11.1.tgz",
|
"resolved": "git+ssh://git@github.com/jeremyckahn/trystero.git#91e9f722302597e232e96932424f3ed47d0d0171",
|
||||||
"integrity": "sha512-4enMGKePEeR6WtZbWp9aGf8PkLq5K25q9+tHBIn36egxX+1enAxnXdg+6/YYhI3kcr1PDyBrMYKeZZ5H+J/2NQ==",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"firebase": "^9.6.5",
|
"firebase": "^9.6.5",
|
||||||
"ipfs-core": "0.9.0",
|
"ipfs-core": "0.9.0",
|
||||||
@ -39551,9 +39551,8 @@
|
|||||||
"integrity": "sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA=="
|
"integrity": "sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA=="
|
||||||
},
|
},
|
||||||
"trystero": {
|
"trystero": {
|
||||||
"version": "0.11.1",
|
"version": "git+ssh://git@github.com/jeremyckahn/trystero.git#91e9f722302597e232e96932424f3ed47d0d0171",
|
||||||
"resolved": "https://registry.npmjs.org/trystero/-/trystero-0.11.1.tgz",
|
"from": "trystero@jeremyckahn/trystero#bugfix/fully-qualified-module-resolution",
|
||||||
"integrity": "sha512-4enMGKePEeR6WtZbWp9aGf8PkLq5K25q9+tHBIn36egxX+1enAxnXdg+6/YYhI3kcr1PDyBrMYKeZZ5H+J/2NQ==",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"firebase": "^9.6.5",
|
"firebase": "^9.6.5",
|
||||||
"ipfs-core": "0.9.0",
|
"ipfs-core": "0.9.0",
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
"react-router-dom": "^6.3.0",
|
"react-router-dom": "^6.3.0",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"sass": "^1.54.3",
|
"sass": "^1.54.3",
|
||||||
"trystero": "^0.11.1",
|
"trystero": "github:jeremyckahn/trystero#bugfix/fully-qualified-module-resolution",
|
||||||
"typeface-public-sans": "^1.1.13",
|
"typeface-public-sans": "^1.1.13",
|
||||||
"typeface-roboto": "^1.1.13",
|
"typeface-roboto": "^1.1.13",
|
||||||
"typescript": "^4.7.4",
|
"typescript": "^4.7.4",
|
||||||
@ -75,5 +75,10 @@
|
|||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"pretty-quick": "^3.1.3",
|
"pretty-quick": "^3.1.3",
|
||||||
"tailwindcss": "^3.1.8"
|
"tailwindcss": "^3.1.8"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"transformIgnorePatterns": [
|
||||||
|
"node_modules/(?!trystero)/"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,28 @@
|
|||||||
|
import { useEffect } from 'react'
|
||||||
import { useParams } from 'react-router-dom'
|
import { useParams } from 'react-router-dom'
|
||||||
|
|
||||||
export function Room() {
|
import { PeerRoom } from '../../services/PeerRoom'
|
||||||
|
|
||||||
|
interface RoomProps {
|
||||||
|
peerRoom?: PeerRoom
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Room({ peerRoom = new PeerRoom() }: RoomProps) {
|
||||||
const params = useParams()
|
const params = useParams()
|
||||||
|
|
||||||
const { roomId } = params
|
const { roomId } = params
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (roomId) {
|
||||||
|
peerRoom.joinRoom(roomId)
|
||||||
|
} else {
|
||||||
|
console.error('roomId not specified')
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
peerRoom.leaveRoom()
|
||||||
|
}
|
||||||
|
}, [peerRoom, roomId])
|
||||||
|
|
||||||
return <>Room ID: {roomId}</>
|
return <>Room ID: {roomId}</>
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,12 @@ const darkTheme = createTheme({
|
|||||||
|
|
||||||
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)
|
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)
|
||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<ThemeProvider theme={darkTheme}>
|
||||||
<ThemeProvider theme={darkTheme}>
|
<CssBaseline />
|
||||||
<CssBaseline />
|
<Router>
|
||||||
<Router>
|
<Bootstrap />
|
||||||
<Bootstrap />
|
</Router>
|
||||||
</Router>
|
</ThemeProvider>
|
||||||
</ThemeProvider>
|
|
||||||
</React.StrictMode>
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// If you want to start measuring performance in your app, pass a function
|
// If you want to start measuring performance in your app, pass a function
|
||||||
|
4
src/react-app-env.d.ts
vendored
4
src/react-app-env.d.ts
vendored
@ -1 +1,5 @@
|
|||||||
/// <reference types="react-scripts" />
|
/// <reference types="react-scripts" />
|
||||||
|
|
||||||
|
declare module 'trystero' {
|
||||||
|
export function joinRoom(config: any, ns: any): any
|
||||||
|
}
|
||||||
|
15
src/services/PeerRoom/PeerRoom.ts
Normal file
15
src/services/PeerRoom/PeerRoom.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { joinRoom } from 'trystero'
|
||||||
|
|
||||||
|
export class PeerRoom {
|
||||||
|
room: any
|
||||||
|
|
||||||
|
joinRoom(roomId: string) {
|
||||||
|
this.room = joinRoom({ appId: process.env.REACT_APP_NAME }, roomId)
|
||||||
|
}
|
||||||
|
|
||||||
|
leaveRoom() {
|
||||||
|
if (this.room) {
|
||||||
|
this.room.leave()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
src/services/PeerRoom/index.ts
Normal file
1
src/services/PeerRoom/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './PeerRoom'
|
Loading…
Reference in New Issue
Block a user