
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
playpeerjs
Advanced tools
WebRTC-based wrapper for creating robust peer-2-peer multiplayer systems with ease.
A WebRTC wrapper that simplifies peer-to-peer multiplayer game development by abstracting away connection handling and state synchronization.
[!TIP] WebRTC or WebSockets – change your mind anytime. Check out PlaySocketJS, the WebSocket counterpart to PlayPeer. Note: With version
^2.0.0of PlaySocket, the API is no longer almost identical to PlayPeer, so that it can take proper advantage of WebSocket perks.
PlayPeer eliminates the traditional complexity of WebRTC multiplayer implementations:

npm install playpeerjs
Note that in production, you should always try...catch these promises, such as peer.init(), to ensure your application continues to run if errors occur.
import PlayPeer from 'playpeerjs';
// Create a new instance
const peer = new PlayPeer('unique-peer-id', {{
// Provide stun and turn servers here
config: {
'iceServers': [
{ urls: "stun:your-stun-server.com" },
{ urls: "turn:your-turn-server.com" },
]
}
}});
// Set up event handlers
peer.onEvent('status', status => console.log('Status:', status));
peer.onEvent('storageUpdate', storage => console.log('Storage update received:', storage));
// Initialize the peer
await peer.init();
// Create a new room (with ptional inital storage data)
const hostId = await peer.createRoom({
players: [],
});
// Join an existing room
await peer.joinRoom('host-peer-id'); // Rejects if connection fails or times out
// Interact with the synced storage (available if in room)
const currentState = peer.getStorage;
peer.updateStorageArray('players', 'add-unique', { username: 'PeerEnjoyer4', level: 2 }); // Special method to enable safe, simultaneous storage updates for arrays
peer.updateStorage('latestPlayer', 'PeerEnjoyer4'); // Regular synced storage update
// To leave the room, destroy the instance
peer.destroy();
new PlayPeer(id: string, options?: PeerJS.Options)
Creates a new PlayPeer instance with a specified peer ID and PeerJS options.
init(): Initialize the peer connection – Returns Promise (async) which resolves with the peer idcreateRoom(initialStorage?: object, maxSize?: number): Create a new room and become host – Returns Promise (async) which resolves with the host's idjoinRoom(hostId: string): Join an existing room – Returns promise (async)destroy(): Use this to leave a room and destroy the instanceupdateStorage(key: string, value: any): Update a value in the synchronized storageupdateStorageArray(key: string, operation: 'add' | 'add-unique' | 'remove-matching' | 'update-matching', value: any, updateValue?: any): Safely update arrays in storage by adding, removing, or updating items. This is necessary for when array updates might be happening simultanously to ensure changes are being applied and not overwritten. Using add-unique instead of add ensures that this value can only be in the array once.onEvent(event: string, callback: Function): Register an event callbackstatus: Connection status updates (returns status string)error: Error events (returns error string)instanceDestroyed: Destruction event - triggered by manual .destroy() method invocation or by fatal errorsstorageUpdated: Storage state changes (returns storage object)hostMigrated: Host changes (returns host id / room code string)incomingPeerConnected: New peer connected (returns peer-id string)incomingPeerDisconnected: Peer disconnected (returns peer-id string)incomingPeerError: Peer connection error (returns peer-id string)outgoingPeerConnected: Connected to host (returns peer-id string)outgoingPeerDisconnected: Disconnected from host (returns peer-id string)outgoingPeerError: Host connection error (returns peer-id string)The id is used to distinguish the peer from other peers on the signalling server.
Using a uuid is recommended, but it is also fine to use any other random string. If you're using a public signalling server instance, including
your application's name in the id can help to prevent overlap (e.g. your-app-012345abcdef).
id: Peer's unique identifierisHost: If this peer is currently hosting or notconnectionCount: Number of active peer connections (without you)getStorage: Retrieve storage objectMIT
Please feel free to fork the repository and submit a Pull Request.
FAQs
WebRTC-based wrapper for creating robust peer-2-peer multiplayer systems with ease.
The npm package playpeerjs receives a total of 42 weekly downloads. As such, playpeerjs popularity was classified as not popular.
We found that playpeerjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.