https://github.com/fourkitchens/scrummy-server
♠️♣️♥️♦️
https://github.com/fourkitchens/scrummy-server
Last synced: 8 months ago
JSON representation
♠️♣️♥️♦️
- Host: GitHub
- URL: https://github.com/fourkitchens/scrummy-server
- Owner: fourkitchens
- Created: 2016-05-26T00:51:28.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-18T05:00:28.000Z (over 9 years ago)
- Last Synced: 2025-03-03T22:33:39.765Z (over 1 year ago)
- Language: JavaScript
- Homepage: http://playscrummy.com
- Size: 89.8 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# scrummy-server
[](https://fourkitchens.com/)
[](https://travis-ci.org/fourkitchens/scrummy-server/)
[](https://codecov.io/gh/fourkitchens/scrummy-server)
[](https://codeclimate.com/github/fourkitchens/scrummy-server)
[](https://david-dm.org/fourkitchens/scrummy-server)
[](https://david-dm.org/dev/fourkitchens/scrummy-server#info=devDependencies&view=table)
## Getting started
### Prerequisites
- Node 6.x
### Installing
- clone this repository
- install dependencies: `$ npm i`
- start the server: `$ npm start`
## Running the tests
### Tests
- run the tests: `$ npm t`
- generate and view test coverage: `$ npm run view-coverage`
- lint code: `$ npm run lint-code`
- lint writing: `$ npm run lint-writing`
## Usage
This example code ran in Chrome; your mileage may vary.
### Sending messages
```js
const myScrummyClient = new WebSocket('ws://localhost:8080');
myScrummyClient.send(JSON.stringify({
type: 'signIn',
nickname: 'tsmith512',
}));
```
### Receiving messages
```js
const myScrummyClient = new WebSocket('ws://localhost:8080');
myScrummyClient.onmessage = response => {
console.log(JSON.parse(response.data));
};
```
## Scrummy
**Kind**: global class
* [Scrummy](#Scrummy)
* [new Scrummy()](#new_Scrummy_new)
* _instance_
* [.shutdown()](#Scrummy+shutdown) ⇒ undefined
* _static_
* [.dispatch(type, data, ws)](#Scrummy.dispatch) ⇒ type
* [.getGame(gameId)](#Scrummy.getGame) ⇒ type
* [.handleError(message, ws)](#Scrummy.handleError) ⇒ undefined
* [.signIn(data, ws)](#Scrummy.signIn) ⇒ undefined
* [.placeVote(data, ws)](#Scrummy.placeVote) ⇒ undefined
* [.reset(data)](#Scrummy.reset) ⇒ undefined
* [.reveal(data)](#Scrummy.reveal) ⇒ undefined
* [.disconnect(data)](#Scrummy.disconnect) ⇒ undefined
* [.revokeVote(data)](#Scrummy.revokeVote) ⇒ undefined
### new Scrummy()
constructor
Creates a new Scrummy server.
Starts a websocket server on the port specified in config, creates an empty bucket for
storing game related data, specifies which methods are available for invocation via websocket
message, and sets up websocket message handling.
Sets up listeners for messages once a connection to the websocket server exists.
If the message type is one of the exposed methods, said method executes with the parsed
message and the websocket as arguments. Otherwise, the message gets rejected.
### scrummy.shutdown() ⇒ undefined
shutdown - Shuts down the websocket server.
**Kind**: instance method of [Scrummy](#Scrummy)
### Scrummy.dispatch(type, data, ws) ⇒ type
dispatch - description
**Kind**: static method of [Scrummy](#Scrummy)
**Returns**: type - description
| Param | Type | Description |
| --- | --- | --- |
| type | type | description |
| data | type | description |
| ws | type | description |
### Scrummy.getGame(gameId) ⇒ type
getGame - description
**Kind**: static method of [Scrummy](#Scrummy)
**Returns**: type - description
| Param | Type | Description |
| --- | --- | --- |
| gameId | type | description |
### Scrummy.handleError(message, ws) ⇒ undefined
handleError - Sends an error to the client
**Kind**: static method of [Scrummy](#Scrummy)
| Param | Type | Description |
| --- | --- | --- |
| message | String | The error message to send |
| ws | Object | The client to send the message to |
### Scrummy.signIn(data, ws) ⇒ undefined
signIn - Signs a user in if they have provided a valid username
**Kind**: static method of [Scrummy](#Scrummy)
| Param | Type | Description |
| --- | --- | --- |
| data | Object | The signIn message from the client |
| ws | Object | The websocket to respond to |
### Scrummy.placeVote(data, ws) ⇒ undefined
placeVote - Places a vote on behalf of a client if the vote and game are valid
**Kind**: static method of [Scrummy](#Scrummy)
| Param | Type | Description |
| --- | --- | --- |
| data | Object | The signIn message from the client |
| ws | Object | The websocket to respond to |
### Scrummy.reset(data) ⇒ undefined
reset - Resets the given game
**Kind**: static method of [Scrummy](#Scrummy)
| Param | Type | Description |
| --- | --- | --- |
| data | Object | The message from the client |
### Scrummy.reveal(data) ⇒ undefined
reveal - Broadcasts a reveal event to the appropriate game
**Kind**: static method of [Scrummy](#Scrummy)
| Param | Type | Description |
| --- | --- | --- |
| data | Object | The message from the client |
### Scrummy.disconnect(data) ⇒ undefined
disconnect - Disconnects a client from the given game
**Kind**: static method of [Scrummy](#Scrummy)
| Param | Type | Description |
| --- | --- | --- |
| data | Object | The message from the client |
### Scrummy.revokeVote(data) ⇒ undefined
revokeVote - Revokes a vote and broadcasts change
**Kind**: static method of [Scrummy](#Scrummy)
| Param | Type | Description |
| --- | --- | --- |
| data | Object | The message from the client |
## Contributors
 |  |  | 
--- | --- | --- | ---
[Four Kitchens](https://github.com/fourkitchens) | [Taylor](https://github.com/tsmith512) | [Flip](https://github.com/flipactual) | [Luke](https://github.com/infiniteluke)
## License
MIT @ [Four Kitchens](https://github.com/fourkitchens)