Skip to content
This repository was archived by the owner on Jul 22, 2026. It is now read-only.

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` functionimport{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`)constparams=newURLSearchParams(window.location.search);consthost=params.get('host');constusername=params.get('username');letgameId=params.get('game_id');letjoinSecret=params.get('join_secret');// create a new `Socket` with the 'debug' logging levelconstsocket=createSocket(host,Verbosity.DEBUG);// listen for some eventsocket.on('some_event',(data)=>{// send a command in responsesocket.send('an_event',{some: 'data'});});// declare an anonymous asynchronous function or use top-level await(async()=>{try{// try to restore the sessionawaitsocket.restoreSession(username);}catch(err){// create a new public game if no game ID was specifiedif(!gameId)({ gameId, joinSecret }=(awaitsocket.create(true,true)));// join the gameawaitsocket.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.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages