{"id":16505,"library":"protoo-client","title":"protoo-client","description":"protoo-client is the client-side JavaScript library for the protoo signaling framework, designed for building multi-party Real-Time Communication (RTC) applications. It supports both browser and Node.js environments, requiring a compatible WebSocket implementation (native `WebSocket` in browsers, or a library like `ws` in Node.js). The current stable version is 4.0.8, and the project appears to follow semantic versioning with notable breaking changes between major releases, indicating active development. It differentiates itself by offering a minimalist and extensible approach to signaling, focusing specifically on WebRTC use cases.","status":"active","version":"4.0.8","language":"javascript","source_language":"en","source_url":"https://github.com/ibc/protoo","tags":["javascript","nodejs","browser","websocket"],"install":[{"cmd":"npm install protoo-client","lang":"bash","label":"npm"},{"cmd":"yarn add protoo-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add protoo-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for Node.js environments to provide a WebSocket implementation, as protoo-client does not bundle one.","package":"ws","optional":true}],"imports":[{"note":"The core `Peer` class is a named export. Ensure you provide a WebSocket instance (native browser WebSocket or `ws` for Node.js) when instantiating.","wrong":"import Peer from 'protoo-client';","symbol":"Peer","correct":"import { Peer } from 'protoo-client';"},{"note":"While the latter might work, destructuring directly is the idiomatic CommonJS way to access named exports. ESM is preferred for new projects.","wrong":"const protooClient = require('protoo-client');\nconst Peer = protooClient.Peer;","symbol":"protoo-client in CJS","correct":"const { Peer } = require('protoo-client');"}],"quickstart":{"code":"import { Peer } from 'protoo-client';\nimport { WebSocket } from 'ws'; // Only for Node.js. In browsers, use native WebSocket.\n\nconst WEBSOCKET_URL = process.env.PROTOO_SERVER_URL || 'wss://your.protoo.server:4443';\n\nasync function connectProtoo() {\n  let ws;\n  if (typeof window === 'undefined') {\n    // Node.js environment\n    ws = new WebSocket(WEBSOCKET_URL);\n  } else {\n    // Browser environment\n    ws = new WebSocket(WEBSOCKET_URL);\n  }\n\n  const peer = new Peer(ws);\n\n  peer.on('open', () => {\n    console.log('Protoo Peer connected to server!');\n    // Example: Send an initial request\n    peer.request('hello', { message: 'Hello from client!' })\n      .then(response => console.log('Server response:', response))\n      .catch(error => console.error('Request failed:', error));\n  });\n\n  peer.on('close', () => {\n    console.log('Protoo Peer disconnected.');\n  });\n\n  peer.on('error', (error) => {\n    console.error('Protoo Peer error:', error.message);\n  });\n\n  peer.on('request', async (request, accept, reject) => {\n    console.log('Received request from server:', request.method, request.data);\n    try {\n      if (request.method === 'ping') {\n        accept({ pong: 'received' });\n      } else {\n        reject(new Error('Unknown request method'));\n      }\n    } catch (error) {\n      reject(error);\n    }\n  });\n\n  peer.on('notification', (notification) => {\n    console.log('Received notification from server:', notification.method, notification.data);\n  });\n}\n\nconnectProtoo();","lang":"typescript","description":"This quickstart demonstrates how to instantiate a protoo-client Peer, establish a WebSocket connection, and handle basic 'open', 'close', 'error', 'request', and 'notification' events. It distinguishes between Node.js and browser WebSocket usage."},"warnings":[{"fix":"Update all calls from `peer.send(method, data)` to `peer.request(method, data)`.","message":"The `peer.send()` method has been renamed to `peer.request()` in protoo-client v4. Attempting to use `send()` will result in a runtime error.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"For Node.js projects, install `ws` (`npm install ws`) and import it: `import { WebSocket } from 'ws';` then pass an instance to `new Peer(new WebSocket(url))`.","message":"When using `protoo-client` in Node.js, you must explicitly provide a WebSocket implementation, typically by installing and importing the `ws` package. Browsers provide a native `WebSocket` global.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Rename `peer.send()` to `peer.request()`. This was a breaking change in v4.","cause":"Attempting to use the deprecated `send()` method on a `Peer` instance from `protoo-client` version 4 or newer.","error":"peer.send is not a function"},{"fix":"Install the `ws` package (`npm install ws`) and import it. Then, pass an instance of `ws.WebSocket` to the `Peer` constructor, e.g., `new Peer(new WebSocket(url))`.","cause":"This error typically occurs when running `protoo-client` in a Node.js environment without providing a WebSocket implementation. The browser's native `WebSocket` is not available in Node.js.","error":"ReferenceError: WebSocket is not defined"},{"fix":"Ensure the WebSocket URL is correct, the `protoo-server` is running and accessible, and handle `peer.on('close')` and `peer.on('error')` events to detect and react to disconnections. Re-establish the `Peer` and WebSocket connection if necessary.","cause":"This error often indicates that the underlying WebSocket connection was closed unexpectedly or failed to establish, and an operation (like `peer.request()`) was attempted on a disconnected peer.","error":"Error: Peer closed"}],"ecosystem":"npm"}