npm install react-device-portalIt is expected that the package will be used on two different devices. Create for them two separate pages or apps. Let's call them App A and App B. Both apps will be linked by same room (e.g. 'my-test-room').
The first app will be a value provider or Input.
const AppA = () => {
const [value, setValue] = useState(0)
useDevicePortalInput('my-test-room', value.toString())
return (
<>
<h1>App A</h1>
<p>Value: {value}</p>
<button
onClick={() => {
setValue(value + 1)
}}
>
Increment
</button>
</>
)
}The other app will be a value consumer or Output. Every time input value in App A changes, the output in App B will be automatically updated.
const AppB = () => {
const { value } = useDevicePortalOutput('my-test-room')
return (
<>
<h1>App B</h1>
<p>Value: {value}</p>
</>
)
}github.com/FilipChalupa/webrtc-signaling-server
Run
npm ci
npm run devand
npm run storybook