### Install and Run Chromecast Device Emulator CLI Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Installs the Chromecast Device Emulator globally using npm and demonstrates how to start the emulator with a scenario JSON file using both the full command and shorthand. Also shows how to check the version. ```bash # Install globally npm install chromecast-device-emulator -g # Start emulator with scenario file chromecast-device-emulator start scenario.json # Or use the shorthand command cde start scenario.json # Check version cde -v # Output when running: # chromecast-device-emulator: Scenario file has been loaded. # chromecast-device-emulator: Established a websocket server at port 8008 # chromecast-device-emulator: Ready for Chromecast receiver connections.. ``` -------------------------------- ### Start Chromecast Device Emulator WebSocket Server Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Illustrates how to start the WebSocket server for the Chromecast Device Emulator using the `start` method with a callback function. The server listens on port 8008 at the `/v2/ipc` endpoint and begins replaying messages upon client connection. ```javascript const CastDeviceEmulator = require('chromecast-device-emulator'); const emulator = new CastDeviceEmulator({ silent: false }); emulator.loadScenario(require('./media-playback-scenario.json')); // Start with callback emulator.start(() => { console.log('Server started on ws://localhost:8008/v2/ipc'); console.log('Open your receiver app in Chrome to connect'); // Messages will be replayed automatically when a client connects // Output shows incoming (<<) and outgoing (>>) messages: // >> {"data":"{\"type\":\"ready\"...}","namespace":"urn:x-cast:com.google.cast.system","senderId":"SystemSender"} // << {"type":"GET_STATUS","requestId":1} }); ``` -------------------------------- ### Start Chromecast Device Emulator with Scenario File Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/docs/basic-receiver-caf.md This command starts the Chromecast Device Emulator using a previously exported scenario JSON file. The emulator will load the scenario and establish a websocket server for receiver connections. ```bash $ chrome-device-emulator start scenario.json ``` -------------------------------- ### start(callback) Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Starts the WebSocket server and begins listening for receiver app connections. The server runs on port 8008 and handles the `/v2/ipc` endpoint. When a receiver connects, the emulator automatically replays all messages from the loaded scenario at their recorded timestamps. ```APIDOC ## start(callback) Starts the WebSocket server and begins listening for receiver app connections. The server runs on port 8008 and handles the `/v2/ipc` endpoint. When a receiver connects, the emulator automatically replays all messages from the loaded scenario at their recorded timestamps. ```javascript const CastDeviceEmulator = require('chromecast-device-emulator'); const emulator = new CastDeviceEmulator({ silent: false }); emulator.loadScenario(require('./media-playback-scenario.json')); // Start with callback emulator.start(() => { console.log('Server started on ws://localhost:8008/v2/ipc'); console.log('Open your receiver app in Chrome to connect'); // Messages will be replayed automatically when a client connects // Output shows incoming (<<) and outgoing (>>) messages: // >> {"data":"{\"type\":\"ready\"...}","namespace":"urn:x-cast:com.google.cast.system","senderId":"SystemSender"} // << {"type":"GET_STATUS","requestId":1} }); ``` ``` -------------------------------- ### Install Chromecast Device Emulator CLI Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/README.md Installs the Chromecast Device Emulator globally as an executable npm package, making it available as a command-line tool for local development. ```bash npm install chromecast-device-emulator -g ``` -------------------------------- ### CLI Usage Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Commands for installing and running the Chromecast Device Emulator from the command line. ```APIDOC ## CLI Usage The CLI provides a simple command-line interface for starting the emulator with a pre-recorded scenario JSON file. Install the package globally to use the `chromecast-device-emulator` or `cde` commands. ```bash # Install globally npm install chromecast-device-emulator -g # Start emulator with scenario file chromecast-device-emulator start scenario.json # Or use the shorthand command cde start scenario.json # Check version cde -v # Output when running: # chromecast-device-emulator: Scenario file has been loaded. # chromecast-device-emulator: Established a websocket server at port 8008 # chromecast-device-emulator: Ready for Chromecast receiver connections.. ``` ``` -------------------------------- ### Example Scenario JSON File Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/README.md An example of a pre-recorded scenario JSON file used by the Chromecast Device Emulator. It contains a timeline of IPC messages with timestamps, simulating communication between a sender and receiver. ```json { "timeline": [ { "time": 5520, "ipcMessage": "{\"data\":\"{\\\"type\\\":\\\"visibilitychanged\\\"}\",\"namespace\":\"urn:x-cast:com.google.cast.system\",\"senderId\":\"SystemSender\"}" }, { "time": 5538, "ipcMessage": "{\"data\":\"{\\\"type\\\":\\\"standbychanged\\\"}\",\"namespace\":\"urn:x-cast:com.google.cast.system\",\"senderId\":\"SystemSender\"}" }, { "time": 5926, "ipcMessage": "{\"data\":\"{\\\"requestId\\\":1,\\\".type\\\":\\\"GET_STATUS\\\"}\"}" } ] } ``` -------------------------------- ### Start Chromecast Device Emulator CLI Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/README.md Starts the Chromecast Device Emulator using the CLI. It requires a pre-recorded scenario JSON file to emulate device behavior. The emulator serves on port 8008. ```bash chromecast-device-emulator start scenario.json ``` ```bash cde start scenario.json ``` -------------------------------- ### Install Chromecast Device Emulator Node API Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/README.md Installs the Chromecast Device Emulator as a development dependency for use within Node.js projects, enabling integration with test automation. ```bash npm install chromecast-device-emulator --save-dev ``` -------------------------------- ### Load Scenario JSON for Chromecast Device Emulator Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Shows how to load a pre-recorded scenario JSON file into the `CastDeviceEmulator` instance. Includes an example of the expected `timeline` structure within the scenario object and error handling for invalid schemas. ```javascript const CastDeviceEmulator = require('chromecast-device-emulator'); const emulator = new CastDeviceEmulator(); // Scenario JSON structure const scenario = { "timeline": [ { "time": 5520, // Milliseconds from connection start "ipcMessage": "{\"data\":\"{\\\"type\\\":\\\"visibilitychanged\\\"}\",\"namespace\":\"urn:x-cast:com.google.cast.system\",\"senderId\":\"SystemSender\"}" }, { "time": 5926, "ipcMessage": "{\"data\":\"{\\\"requestId\\\":1,\\\"type\\\":\\\"GET_STATUS\\\"}\",\"namespace\":\"urn:x-cast:com.google.cast.media\",\"senderId\":\"sender-123\"}" } ] }; try { emulator.loadScenario(scenario); console.log('Scenario loaded successfully'); } catch (err) { console.error('Invalid scenario schema:', err.message); } ``` -------------------------------- ### Control Chromecast Device Emulator with Node.js API Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Demonstrates how to use the `CastDeviceEmulator` class from the `chromecast-device-emulator` package in Node.js. It covers instantiation, loading a scenario, starting the WebSocket server, and stopping/closing the emulator. ```javascript const CastDeviceEmulator = require('chromecast-device-emulator'); // Create emulator instance with options const emulator = new CastDeviceEmulator({ silent: false // Set to true to suppress console logging }); // Load a pre-recorded scenario file emulator.loadScenario(require('./scenario.json')); // Start the WebSocket server emulator.start(() => { console.log('Emulator is ready for connections'); }); // When finished testing, stop and close the emulator emulator.stop(); // Stop handling events emulator.close(() => { console.log('Emulator closed'); }); ``` -------------------------------- ### Example Scenario JSON Output (JSON) Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/README.md A truncated example of the large JSON output generated when exporting a user scenario using `CDE.exportScenario()`. This JSON contains the timeline of events and IPC messages recorded during user interaction with the receiver app. ```json {"timeline":[{"time":17163,"ipcMessage":"{\"data\":\"{\\\""}]} ``` -------------------------------- ### Scenario JSON Schema Example Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Illustrates the required JSON schema for scenario files used by the Chromecast Device Emulator. The schema includes a `timeline` array with timestamped IPC messages, detailing elapsed time and message content. ```json { "timeline": [ { "time": 12250, "ipcMessage": "{\"data\":\"{\\\"applicationId\\\":\\\"7BDF108F\\\",\\\"type\\\":\\\"ready\\\",\\\"version\\\":\\\"1.29.104827\\\"}\",\\"namespace\\":\\\"urn:x-cast:com.google.cast.system\\\",\\"senderId\\\":\\\"SystemSender\\\"}" }, { "time": 12312, "ipcMessage": "{\"data\":\"{\\\"level\\\":1.0,\\\"muted\\\":false,\\\"type\\\":\\\"volumechanged\\\"}\",\\"namespace\\":\\\"urn:x-cast:com.google.cast.system\\\",\\"senderId\\\":\\\"SystemSender\\\"}" }, { "time": 12630, "ipcMessage": "{\"data\":\"{\\\"requestId\\\":1,\\\"type\\\":\\\"GET_STATUS\\\"}\",\\"namespace\\":\\\"urn:x-cast:com.google.cast.media\\\",\\"senderId\\\":\\\"sender-app-id\\\"}" }, { "time": 13951, "ipcMessage": "{\"data\":\"{\\\"requestId\\\":2,\\\"type\\\":\\\"QUEUE_LOAD\\\",\\\"items\\\":[...]}\",\\"namespace\\":\\\"urn:x-cast:com.google.cast.media\\\",\\"senderId\\\":\\\"sender-app-id\\\"}" } ] } ``` -------------------------------- ### Example Debug Output from Receiver Utilities (Console) Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/README.md This shows the expected debug messages in the browser console after successfully loading the `receiver-utils` script. These messages confirm that the necessary modules for message recording and device emulation are loaded and ready. ```text chromecast-device-emulator: receiver-utils loaded. chromecast-device-emulator: device-polyfill module loaded. chromecast-device-emulator: scenario-recorder module loaded. ``` -------------------------------- ### Use Chromecast Device Emulator Node API Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/README.md Demonstrates how to use the Chromecast Device Emulator as a Node.js API. It involves creating an emulator instance, loading a scenario, starting the emulator, performing actions, and stopping it. ```javascript var CastDeviceEmulator = require('chromecast-device-emulator'); // Create a new instance var emulator = new CastDeviceEmulator(); // Load pre-recorded scenario emulator.loadScenario(require('./scenario.json')); // Startup the emulator emulator.start(); // Server is up for receiver app // Do something... // Stop the emulator emulator.stop(); ``` -------------------------------- ### Add Receiver Utilities Script to Receiver App (HTML) Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/README.md This snippet shows how to include the `receiver-utils.min.js` script in your HTML receiver application. It must be placed before the Google Cast SDKs for the message recorder to function correctly. The example also shows the complete script inclusion with Cast APIs and Cast Media Library. ```html ``` -------------------------------- ### Automated Testing with Node API and Mocha Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Integrates the Chromecast Device Emulator with Mocha for automated testing of receiver apps. It sets up the emulator and a browser instance before tests and tears them down afterward. The test verifies media playback commands by interacting with the receiver app page and asserting the player state. ```javascript const CastDeviceEmulator = require('chromecast-device-emulator'); const { expect } = require('chai'); const puppeteer = require('puppeteer'); describe('Chromecast Receiver App', function() { let emulator; let browser; before(async function() { // Setup emulator with test scenario emulator = new CastDeviceEmulator({ silent: true }); emulator.loadScenario(require('./test-scenarios/playback-test.json')); await new Promise(resolve => emulator.start(resolve)); // Launch browser for receiver app browser = await puppeteer.launch(); }); after(async function() { await browser.close(); await new Promise(resolve => emulator.close(resolve)); }); it('should handle media playback commands', async function() { const page = await browser.newPage(); await page.goto('http://localhost:3000/receiver.html'); // Wait for emulator messages to be processed await page.waitForTimeout(15000); // Verify receiver app state const playerState = await page.evaluate(() => { return document.querySelector('cast-media-player').playerState; }); expect(playerState).to.equal('PLAYING'); }); }); ``` -------------------------------- ### Export Scenario JSON using CDE CLI (Bash) Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/README.md This command demonstrates how to export a recorded user scenario into a JSON file using the Chromecast Device Emulator's command-line interface. The exported JSON file can then be used to replay the scenario with the emulator. ```bash $ chromecast-device-emulator start scenario.json ``` -------------------------------- ### loadScenario(scenarioFile) Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Loads a pre-recorded scenario JSON file containing IPC messages to replay. The scenario file is validated against a JSON schema and must contain a `timeline` array of messages with timestamps. ```APIDOC ## loadScenario(scenarioFile) Loads a pre-recorded scenario JSON file containing IPC messages to replay. The scenario file is validated against a JSON schema and must contain a `timeline` array of messages with timestamps. ```javascript const CastDeviceEmulator = require('chromecast-device-emulator'); const emulator = new CastDeviceEmulator(); // Scenario JSON structure const scenario = { "timeline": [ { "time": 5520, // Milliseconds from connection start "ipcMessage": "{\"data\":\"{\\\"type\\\":\\\"visibilitychanged\\\"}\",\"namespace\":\"urn:x-cast:com.google.cast.system\",\"senderId\":\"SystemSender\"}" }, { "time": 5926, "ipcMessage": "{\"data\":\"{\\\"requestId\\\":1,\\\"type\\\":\\\"GET_STATUS\\\"}\",\"namespace\":\"urn:x-cast:com.google.cast.media\",\"senderId\":\"sender-123\"}" } ] }; try { emulator.loadScenario(scenario); console.log('Scenario loaded successfully'); } catch (err) { console.error('Invalid scenario schema:', err.message); } ``` ``` -------------------------------- ### Inject Receiver Utilities for Scenario Recording - HTML Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Shows how to inject the `receiver-utils.min.js` script into your receiver app's HTML. This script must be included before the Cast SDK scripts to intercept and record IPC messages for scenario generation. ```html ``` -------------------------------- ### Stop and Close Emulator Server - JavaScript Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Demonstrates how to stop the emulator from handling new WebSocket events using `stop()` and then completely close the WebSocket server using `close()`. This is useful for gracefully shutting down the emulator after testing. ```javascript const CastDeviceEmulator = require('chromecast-device-emulator'); const emulator = new CastDeviceEmulator(); emulator.loadScenario(require('./scenario.json')); emulator.start(); // Run tests... setTimeout(() => { // Stop handling events (server still running) emulator.stop(); console.log('Event handling stopped'); // Close the WebSocket server completely emulator.close(() => { console.log('WebSocket server closed'); process.exit(0); }); }, 30000); ``` -------------------------------- ### Export Recorded Scenario JSON using CDE Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/docs/basic-receiver-caf.md This command is executed in the Chrome DevTools console of the receiver app to export the recorded user scenario as a JSON file. This JSON file can then be used to replay the scenario in the emulator. ```javascript CDE.exportScenario(); ``` -------------------------------- ### Node API - CastDeviceEmulator Class Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Programmatic interface for controlling the emulator, ideal for test automation. The emulator creates a WebSocket server on port 8008 at the `/v2/ipc` path. ```APIDOC ## Node API - CastDeviceEmulator Class The `CastDeviceEmulator` class provides a programmatic interface for controlling the emulator, ideal for integration with test automation frameworks. The emulator creates a WebSocket server on port 8008 at the `/v2/ipc` path. ```javascript const CastDeviceEmulator = require('chromecast-device-emulator'); // Create emulator instance with options const emulator = new CastDeviceEmulator({ silent: false // Set to true to suppress console logging }); // Load a pre-recorded scenario file emulator.loadScenario(require('./scenario.json')); // Start the WebSocket server emulator.start(() => { console.log('Emulator is ready for connections'); }); // When finished testing, stop and close the emulator emulator.stop(); // Stop handling events emulator.close(() => { console.log('Emulator closed'); }); ``` ``` -------------------------------- ### Export Recorded Scenario - JavaScript Source: https://context7.com/ajhsu/chromecast-device-emulator/llms.txt Provides instructions on how to use the `CDE.exportScenario()` function from the Chrome DevTools console to export recorded IPC messages as a JSON scenario file. It also shows how to export without clearing the console. ```javascript // In Chrome DevTools Console (remote debugging your Cast device): // After performing user actions on the receiver app... // Export the recorded scenario CDE.exportScenario(); // Output (copy this JSON and save to a file): // {"timeline":[{"time":12250,"ipcMessage":"{\"data\":\"{\\\"type\\\":\\\"ready\\\"...}"},...]} // Export without clearing console CDE.exportScenario(false); // Save the JSON output to scenario.json, then use with emulator: // $ cde start scenario.json ``` -------------------------------- ### Include Receiver Utilities in CAF Receiver App Source: https://github.com/ajhsu/chromecast-device-emulator/blob/master/docs/basic-receiver-caf.md This snippet shows how to include the Chromecast Device Emulator's receiver utilities script in your Cast Application Framework (CAF) receiver app. This is necessary for recording messages between the sender and receiver. ```html ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.