GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - code-game-project/javascript-client: This is the JavaScript Client for CodeGame. It works in Node.js and most Browsers.

This repository was archived by the owner on Jul 22, 2026. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

50 Commits
50 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
test.tsconfig.json
test.tsconfig.json
 
 
tsconfig.json
tsconfig.json
 
 
versions.json
versions.json
 
 

Repository files navigation

JavaScript-Client

CodeGame Specification Version

This is the JavaScript (and TypeScript) client library for CodeGame.

Installation

npm install @code-game-project/client

Usage

// import the `createSocket` function
import { createSocket, Verbosity } from '@code-game-project/client';

// Node.js only: Get the command line arguments (`node your-script.js cg.example.com joe 1234-5678`)
let [host, username, gameId, joinSecret] = process.argv.slice(2)

// Browser only: Get the query parameters (`http://localhost:8080/?host=cg.example.com&username=joe&game_id=1234-5678`)
const params = new URLSearchParams(window.location.search);
const host = params.get('host');
const username = params.get('username');
let gameId = params.get('game_id');
let joinSecret = params.get('join_secret');

// create a new `Socket` with the 'debug' logging level
const socket = createSocket(host, Verbosity.DEBUG);

// listen for some event
socket.on('some_event', (data) => {
	// send a command in response
	socket.send('an_event', {
		some: 'data'
	});
});

// declare an anonymous asynchronous function or use top-level await
(async () => {
	try {
		// try to restore the session
		await socket.restoreSession(username);
	} catch (err) {
		// create a new public game if no game ID was specified
		if (!gameId) ({ gameId, joinSecret } = (await socket.create(true, true)));
		// join the game
		await socket.join(gameId, username);
	}
})();

License

MIT License

Copyright (c) 2022 CodeGame Contributors (https://github.com/orgs/code-game-project/people)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

This is the JavaScript Client for CodeGame. It works in Node.js and most Browsers.

www.npmjs.com/package/@code-game-project/client

Topics

browserclientjavascriptnodejstypescript

Resources

Readme
MIT license
Activity
Custom properties

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.