Package Exports
- tahi
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (tahi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
tahi
A shared peer-to-peer state for multiple users connected by WebRTC.
demo
use
- Install
yarn add tahi
ornpm install --save tahi
// Using PeerJS
import { createStore } from 'tahi';
import Peer from 'peerjs';
const store = createStore({
reducer: (state, action) => {
// Return next state
},
preloadedState: {}, // Optional: The initial state of your store
});
const peer = new Peer();
peer.on('open', (id) => {
store.setId(id); // A unique ID for each connected user
});
peer.on('connection', (connection) => {
store.addPeer(connection.peer, connection);
});
const connection = peer.connect('<other_users_peerjs_id>');
connection.on('open', () => {
store.addPeer(connection.peer, connection);
});
const unsubscribe = store.subscribe(() => {
// Occurs for all connected users when 'SOME_ACTION_TYPE' is dispatched
const nextState = store.getState(); // The new state
});
store.dispatch({
payload: 'some data of whatever kind',
type: 'SOME_ACTION_TYPE',
});
todo
- Make this list
- Make example with PeerJS
- Make example with Vanilla WebRTC
- Make documentation
- Make compatible with redux middleware