-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc2b271
commit 1a18531
Showing
2 changed files
with
87 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,108 @@ | ||
<p align="center"> | ||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a> | ||
</p> | ||
|
||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 | ||
[circleci-url]: https://circleci.com/gh/nestjs/nest | ||
|
||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p> | ||
<p align="center"> | ||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a> | ||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a> | ||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a> | ||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a> | ||
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a> | ||
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a> | ||
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a> | ||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a> | ||
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a> | ||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a> | ||
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a> | ||
</p> | ||
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer) | ||
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)--> | ||
|
||
## Description | ||
|
||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. | ||
# Tic Tac Toe WebSocket API | ||
|
||
## Overview | ||
|
||
The Tic Tac Toe WebSocket API facilitates real-time interaction in a Tic Tac Toe game through WebSockets, allowing for live updates and interactive gameplay without the need for continuous polling. | ||
|
||
![Demo GIF](./assets/demo.gif) | ||
|
||
## Technologies Used | ||
|
||
- **NestJS version:** 10.3.8 | ||
- **Socket.IO version:** 4.7.5 | ||
- Important: To ensure compatibility, the Socket.IO client version must match the server version. You can use the following CDN for the client: | ||
```html | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.7.5/socket.io.js"></script> | ||
<link rel="stylesheet" href="./style.css"> | ||
``` | ||
- Alternatively, you can install it via npm: | ||
```bash | ||
npm install [email protected] | ||
``` | ||
|
||
## Installation | ||
|
||
Clone the repository and navigate into the directory: | ||
|
||
```bash | ||
$ npm install | ||
git clone https://github.com/masechkacat/tic-tac-toe-server.git | ||
cd tic-tac-toe-server | ||
``` | ||
|
||
## Running the app | ||
|
||
### Install dependencies: | ||
```bash | ||
npm instal | ||
``` | ||
Set the CORS_ORIGIN in your environment variables to specify the URL of the client from which requests are made (it is recommended to keep CORS enabled for production): | ||
```bash | ||
# development | ||
$ npm run start | ||
CORS_ORIGIN="http://example.com" | ||
``` | ||
## Running the Server | ||
To start the server in different environments: | ||
```bash | ||
# Development | ||
npm run start | ||
|
||
# watch mode | ||
$ npm run start:dev | ||
# Watch mode | ||
npm run start:dev | ||
|
||
# production mode | ||
$ npm run start:prod | ||
# Production mode | ||
npm run start:prod | ||
``` | ||
## Testing | ||
Run unit tests with: | ||
```bash | ||
npm run test | ||
``` | ||
Tests are written for both the game service and the gateway. | ||
|
||
## Test | ||
## Documentation | ||
The server's API is documented using AsyncAPI. Documentation is auto-generated by script `.github/workflows/asyncapi-docs.yml` and published via GitHub Actions to: [Tic Tac Toe WebSocket API 1.0.0](https://masechkacat.github.io/tic-tac-toe-server/) | ||
|
||
```bash | ||
# unit tests | ||
$ npm run test | ||
You can also view the documentation locally using the [AsyncAPI Viewer](https://studio.asyncapi.com/) by loading the asyncapi.yaml file from the repository. | ||
|
||
# e2e tests | ||
$ npm run test:e2e | ||
## Example Client | ||
A simple client implementation is deployed at [client URL]() | ||
|
||
# test coverage | ||
$ npm run test:cov | ||
``` | ||
## Server Usage Information | ||
|
||
- **Development Server:** [Tic Tac Toe Multiplayer](https://tic-tac-toe-server-a5g5.onrender.com) | ||
- **Protocol:** *WebSocket (ws)* | ||
|
||
## WebSocket Channels and Messages | ||
|
||
### General Channel Access | ||
|
||
- **Path:** `/` | ||
|
||
### Subscriptions | ||
|
||
Users can subscribe to receive updates which include the game state and other messages: | ||
|
||
- **Game Updates** | ||
- **Description:** Receive current game status, including board state and current player turn. | ||
- **Payload:** Includes `status`, `board`, `currentPlayer`, and `playerIds`. | ||
|
||
- **Messages** | ||
- **Description:** Receive general messages from the server. | ||
- **Payload:** Includes `text` which provides information or feedback. | ||
|
||
- **Game Over** | ||
- **Description:** Notifies when the game ends, either by winning or draw. | ||
- **Payload:** Includes `text` which declares the game result. | ||
|
||
- **Errors** | ||
- **Description:** Error messages in case of invalid moves or server issues. | ||
- **Payload:** Includes `message` detailing the error encountered. | ||
|
||
## Support | ||
### Publishing | ||
|
||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). | ||
Users can send moves to the server: | ||
|
||
## Stay in touch | ||
- **Move** | ||
- **Description:** Send player moves to the server. | ||
- **Payload:** `index` indicating the position on the board (0-8). | ||
|
||
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) | ||
- Website - [https://nestjs.com](https://nestjs.com/) | ||
- Twitter - [@nestframework](https://twitter.com/nestframework) | ||
|
||
## License | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.