shared-state-trinn
v1.4.4
Published
keeps a shared state through a p2p connection
Downloads
447
Readme
Shared state TRINN
this package allows for easy sharing of states between applications over WebRTC build on TRINN-remote-control
Installation
The package can be installed using npm:
npm i trinn-remote-control
Example
for the remote
await StateManager.setOnConnection((event, id) => {
console.log("connection: ", event, id);
})
.setId("someSharedId")
.setRemote()
.init("your api key");
init("your api key", "someSharedId", true);
const state = await StateManager.addState("someStateId", { value: 0 });
state.subscribe((value) => {
console.log(value);
});
for the controller
await StateManager.setOnConnection((event, id) => {
console.log("connection: ", event, id);
})
.setId("someSharedId")
.init("your api key");
const state = await StateManager.awaitState("someStateId");
state.set({ value: 1 });
this will initialise the state with the value 0 in the remote and then set the value to 1 in the controller