@snap-net/extension
v1.1.0
Published
Snap! extension that lets Snap! programs exchange messages over a local network or the internet via a WebSocket server.
Maintainers
Readme
snap-net / extension
This is the Snap!Net Extension, a loadable JavaScript extension for the Snap! visual programming environment that lets Snap! programs exchange messages over a local network or the internet via a WebSocket server.
The extension registers 10 primitives (3 server, 2 connection, 3 messaging, 2 status) and injects a "Networking" block category into the Snap! palette. It communicates with the Electron main process over IPC, which manages the WebSocket client and optional embedded server. The wire protocol is specified at https://gitlab.com/snap-net/protocol.
The extension is consumed by Snap!Out, which provides the Electron shell, IPC bridge, and WebSocket client/server.
Blocks
Server
| Block | Type | Description |
|---|---|---|
| start server on port (3030) | command | Start the embedded WebSocket server |
| stop server | command | Stop the server and disconnect all clients |
| my server address | reporter | LAN address as HOST : PORT |
Connection
| Block | Type | Description |
|---|---|---|
| connect to (host) port (port) as (nick) | command | Connect to a server with a nickname |
| disconnect | command | Disconnect from the current server |
Messaging
| Block | Type | Description |
|---|---|---|
| broadcast (event) with data (data) | command | Send to all peers |
| send (event) with data (data) to (peer) | command | Send to a specific peer |
| when I receive (event) msg from sender | hat | Fires on matching incoming message; msg and sender are upvars |
Status
| Block | Type | Description |
|---|---|---|
| peers | reporter | List of connected peer nicknames (including self) |
| last network error | reporter | Most recent error message, or empty string |
Building
The extension is bundled into a single IIFE file for browser loading:
npm run buildOutput: dist/snap-net-extension.js
Testing
npm testLicense
The Snap!Net extension is free software. You may redistribute and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
