Websockets
Ancient Brain Worlds come with
Websocket support
to allow real-time communication between different users running the same World.
User actions in one client can make changes in the World on other clients.
This allows you to write your own
real-time multi-user games.
It also allows
real-time chat between the users of your World.
AB.socketStart();
// Start socket for this World.
// Any user who runs the World joins me in the same multi-user World.
AB.socketStart ( password );
// Start socket for this World, with password (alphanumeric).
// Only users who have called AB.socketStart with the same password can join me
// (rather than all users who run the World).
AB.socketOut ( data ); // send any JS data to all other clients
// Could check socket has been set up first (socket takes time to set up):
if ( AB.socket )
if ( AB.socket.connected )
AB.socketOut ( data );
AB.socketIn = function ( data ) { ... };
// Handler for incoming data from other clients.
// World author must define this function.
AB.socketUserlist = function ( array ) { ... };
// Keep track of other users in multi-user World.
// The server triggers this to tell us the latest list of users of this World.
// This is called when we connect, and any time another user arrives or leaves.
// The array is a list of (userid, username) pairs.
// World author must define this function (what to do with array) if desired.
- Here are some Starter Worlds with Websockets. Clone and Edit these to get started:
Websocket chat 1052 runs ♦ 0 likes
By
Starter user
Created: 29 Feb 2020
Modified: 17 Sep 2023
Demo of Ancient Brain Websockets functionality. Run on multiple devices. Chat from one to the other. Websockets boxes 836 runs ♦ 0 likes
By
Starter user
Created: 29 Feb 2020
Modified: 17 Sep 2023
Demo of Websockets in 3D World. Click to change the boxes on the other user's machine, while the... Websocket buttons 231 runs ♦ 0 likes
By
Starter user
Created: 29 Feb 2020
Modified: 17 Sep 2023
Demo of Ancient Brain Websockets functionality. Run on multiple devices. Simple page uses button...
- Worlds with Websockets that have the most runs.
- JS code search of all Worlds for use of AB.socket functions.