{"library":"reactotron-core-contract","title":"Reactotron Core Contract","description":"Reactotron Core Contract (reactotron-core-contract) is a TypeScript-first package that defines the canonical interfaces and types for the WebSocket messages exchanged between the Reactotron desktop application (the server) and various client-side libraries (like reactotron-react-native or reactotron-react-js). Introduced with Reactotron 3.0, its primary purpose is to ensure strong type safety and compatibility across the entire Reactotron ecosystem, both for internal package consistency and for external plugin development. It formalizes the communication protocol, making it easier to build robust custom plugins and maintain reliable connections. The package is part of the larger Reactotron monorepo, currently at version 0.3.2, and its release cadence is tied to the evolution of the main Reactotron project, typically released when changes accumulate or align with other Reactotron component updates.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install reactotron-core-contract"],"cli":null},"imports":["import { ClientMessage } from 'reactotron-core-contract'","import { ServerMessage } from 'reactotron-core-contract'","import { ClientCommand } from 'reactotron-core-contract'","import { Reactotron } from 'reactotron-core-contract'","import { Host } from 'reactotron-core-contract'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { ClientCommand, ServerCommand, ClientMessage, ServerMessage, Reactotron } from 'reactotron-core-contract';\n\n// Example of a custom client command type definition\ntype MyCustomCommand = ClientCommand<'my.custom.command', { data: string, timestamp: number }>;\n\n// Example of a custom server message type definition\ntype MyServerStatusMessage = ServerMessage<'server.status', { uptime: number, connections: number }>;\n\n// A dummy function illustrating how you might use these types\nfunction processClientCommand(command: ClientCommand | MyCustomCommand): void {\n  if (command.type === 'my.custom.command') {\n    console.log(`Received custom command: ${command.type} with data: ${command.payload.data}`);\n  } else {\n    console.log(`Received standard command: ${command.type}`);\n  }\n}\n\nfunction sendServerMessage(reactotron: Reactotron, message: ServerMessage | MyServerStatusMessage): void {\n  // In a real scenario, this would send over a WebSocket\n  console.log(`Sending message from server: ${message.type}`);\n}\n\n// Simulate a Reactotron instance for type checking\nconst mockReactotron: Reactotron = {\n  host: 'localhost',\n  port: 9090,\n  version: '3.x.x',\n  // ... other Reactotron properties (omitted for brevity)\n};\n\nprocessClientCommand({ type: 'log', payload: { level: 'debug', message: 'Hello from client' }, important: false });\nprocessClientCommand({ type: 'my.custom.command', payload: { data: 'Special data', timestamp: Date.now() }, important: true });\nsendServerMessage(mockReactotron, { type: 'server.status', payload: { uptime: 1200, connections: 5 } });\n","lang":"typescript","description":"Demonstrates importing core contract types like `ClientCommand`, `ServerCommand`, `ClientMessage`, and `ServerMessage`, and how to define custom commands or messages adhering to these contracts for type safety.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}