xcx-browser-channel

Xcratch Browser Channel Extension

This extension allows Xcratch projects to communicate with each other over a browser-based channel. It utilizes BroadcastChannel for secure and efficient cross-project communication.

✨ What You Can Do With This Extension

Play example to look at what you can do with “Browser Channel” extension.

game project: cat-fight-bc

controller project: microbit-controller

This projects demonstrates how to use the Browser Channel extension to create a simple two-player game. The game is a cat fight where each player controls a cat sprite. One player can control the cat sprite using the arrow keys, while the other player can control the cat sprite using micro:bit connected in the controller project. The game uses the Browser Channel extension to allow the two players to communicate with each other. The controller project sends messages to the game project to control the cat sprite. The game project listens for messages from the controller project and updates the cat sprite accordingly.

Block Functionality Overview:

This extension facilitates communication by allowing scripts to:

Block Categories:

The extension’s blocks are grouped into logical categories, outlined below:

1. Channel Management:

2. Data Access:

3. Event Handling:

4. Event Information:

How to Use in Xcratch

This extension can be used with other extension in Xcratch.

  1. Open Xcratch Editor
  2. Click ‘Add Extension’ button
  3. Select ‘Extension Loader’ extension
  4. Type the module URL in the input field
    https://yokobond.github.io/xcx-browser-channel/dist/xcxBrowserChannel.mjs
    
  5. Click ‘OK’ button
  6. Now you can use the blocks of this extension

Development

Install Dependencies

npm install

Setup Development Environment

Change vmSrcOrg to your local scratch-vm directory in ./scripts/setup-dev.js then run setup-dev script to setup development environment.

npm run setup-dev

Bundle into a Module

Run build script to bundle this extension into a module file which could be loaded on Xcratch.

npm run build

Watch and Bundle

Run watch script to watch the changes of source files and bundle automatically.

npm run watch

Test

Run test script to test this extension.

npm run test

🏠 Home Page

Open this page from https://yokobond.github.io/xcx-browser-channel/

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.