@pico-mp/web
v0.1.4
Published
PicoMP Official Javascript/Typescript Web SDK (Browser)
Downloads
558
Maintainers
Readme
@pico-mp/web
Multiplayer SDK for browsers. A few functions — that's all.
npm install @pico-mp/webUsage
import { useCloud, Room } from '@pico-mp/web'
useCloud('your-api-key')
// Create a room
const roomCode = await Room.create({ maxPlayers: 4, public: true })
// Join a room (omit roomCode to auto-match into a public room)
const roomCode = await Room.join('ABCD12')
// Share state with everyone in the room
Room.setData({ phase: 'playing', scores: { alice: 0, bob: 0 } })
// Send a message to a specific player (omit target to broadcast)
Room.send({ action: 'move', x: 1, y: 2 }, targetPlayerId)
// Listen for incoming data
Room.onDataReceived = (senderId, data) => { /* ... */ }
Room.onPeerJoined = (peerId) => { /* ... */ }
Room.onPeerLeft = (peerId) => { /* ... */ }
// Leave
Room.leave()Transports
useCloud('your-api-key') // PicoMP Cloud
useLocal('http://localhost:9160') // local server
useMock() // offline / no server