ok fine i'll just use the template lol

master
Jordan Orelli 5 years ago
commit 69f661dc63

1
.gitignore vendored

@ -0,0 +1 @@
node_modules

@ -0,0 +1 @@
web: node server.js

@ -0,0 +1,237 @@
[Home]() | [Reference](docs/REFERENCE.md) | [Development Notes](docs/NOTES.md)
# p5.multiplayer
This repository contains a set of template files for building a multi-device, multiplayer game where multiple clients can connect to a specified host page. The clients and hosts are built using *[p5.js](https://p5js.org)*, and they communicate with each other through a *[node.js](https://nodejs.org/en/download/)* server via *[socket.io](https://socket.io/)* messages.
* [Getting Started](#getting-started)
* [Examples](#examples)
* [Using the Template Files](#using-the-template-files)
* [How does it work?](#how-does-it-work)
* [Local](#local)
* [Local Area Network (LAN)](#local-area-network-lan)
* [Remote Server](#remote-server)
* [Using p5.multiplayer with a Remote Server](#using-p5multiplayer-with-a-remote-server)
* [Using with Glitch](#using-with-glitch)
* [What is Glitch?](#what-is-glitch)
* [Quickstart](#glitch-quickstart)
* [Installation](#glitch-installation)
* [Using with Heroku](#using-with-heroku)
* [What is Heroku?](#what-is-heroku)
* [Installation](#heroku-installation)
* [Custom Hosts](#custom-hosts)
* [Using an HTTPS Server](#using-an-https-server)
* [Reference](docs/REFERENCE.md)
* [Support](#support)
![An example image of the base project in action. It shows a host window on the left side of a screen populated by two colored squares, each matching client controller windows on the right side of the screen.](data/example.png)
## Getting Started
[[Back to top]](#p5multiplayer)
1. Clone this GitHub repository on your local machine.
2. If you don't already have *node.js* installed on your machine, go [here](https://nodejs.org/en/download/) and download the version appropriate for your operating system.
3. Open a terminal window and navigate to the project directory.
4. Run the command `npm install`.
5. Next, run the command `node server.js` to start a *node.js* server.
6. Open a browser and go to `http://127.0.0.1:3000/host.html`. This will open up a host page. Make note of the URL displayed in the bottom left corner of the screen.
7. Open a second browser and go to the URL displayed on your host page. It will look something like `http://127.0.0.1:3000/?=roomId`, where `roomId` is a randomly generated name. This screen will load a controller that let's you control the movement of a colored square on the host page.
8. (OPTIONAL) The included *node.js* server cleverly lets you specify a custom room ID (think of it as a semi-private game room). You can specify your own room ID by opening a host page using `http://127.0.0.1:8080/host.html?=roomId`, where `roomId` is a string of your choice.
## Using the Template Files
[[Back to top]](#p5multiplayer)
The `host.js`, `host.html`, `index.js`, and `index.html` files located within the `public` directory are a basic game example and should have everything you need to start building your own browser-based game.
They make use of two existing *[p5.js](https://p5js.org)* libraries: *[p5.touchgui](https://github.com/L05/p5.touchgui)*, which enables easy creation of mouse and touchscreen GUI elements, and *[p5.play](https://molleindustria.github.io/p5.play/)*, which enables easy creation of 2D sprite games within *p5.js*.
If you'd like to start with a completely blank template, however, please navigate to the `template` directory. You'll see comments indicating where to add your game logic and other related code bits that will customize the project to your own specifications. Once you've modified these to your liking, you can copy them into the `public` directory, overwriting the existing files of the same names.
## Examples
* [Live demo hosted on Glitch](https://p5-multiplayer.glitch.me/host.html). *Note: Once the page opens, go to the link at the bottom screen in a second browser.*
* [Example video of the template in action with Unity.](https://vimeo.com/274410221)
## How does it work?
[[Back to top]](#p5multiplayer)
*p5.multiplayer* functions by using a *node.js* server to relay data messages between a "host" and any "clients" that connect to it. The messages are sent using socket.io as the messaging protocol.
*p5.multiplayer* can be used in three possible configurations:
#### Localhost (Same computer)
[[Back to top]](#p5multiplayer)
This type of configuration works great for testing. You can run your *node.js* server on your local machine and test the "host" and "client" pages in separate browswer windows.
<img src="data/p5.multiplayer_localhost.png" alt="Diagram of p5.multiplayer running solely on a local computer." width="600">
#### Local Area Network (LAN)
[[Back to top]](#p5multiplayer)
You can set up a multiplayer game or interactive installation on a local area network (LAN) that will enable multiple devices to connect to your machine. You'll need to know your machine's IP address and use that as your `serverIp` in order for this to work (how to find your IP address on [MacOS](https://www.macworld.co.uk/how-to/mac/ip-address-3676112/) / [Windows](https://support.microsoft.com/en-us/help/4026518/windows-10-find-your-ip-address)).
In your `host.js` and `index.js` files, set `const local = true`. Then change `const serverIp = 'yourIpAddress';` so that `yourIpAddress` matches your IP address.
Please be aware that your machine may be vulnerable whenever you allow other devices to connect to it.
<img src="data/p5.multiplayer_lan.png" alt="Diagram of p5.multiplayer running on a local area network (LAN)" width="600">
#### Remote Server
[[Back to top]](#p5multiplayer)
This type of configuration is great for making sure as many devices as possible are able to connect to your server. In this case, the *node.js* server is hosted on a remote server and uses [Express](https://expressjs.com/) to serve the "host" and "client" pages to connected devices. The increased connectivity afforded by using a remote server comes at the cost of latency, which may or may not be noticeable depending on server, network speed of each connected device, and user interaction design.
Please see the [directions below](#using-p5multiplayer-with-a-remote-server) for information on how to set this up.
<img src="data/p5.multiplayer_remote.png" alt="Diagram of p5.multiplayer running on a remote server." width="600">
## Using p5.multiplayer with a Remote Server
### Using with Glitch
#### What is Glitch?
[[Back to top]](#p5multiplayer)
[Glitch](https://glitch.com) is an approachable platform for creating web apps that let's users easily share, reuse, and repurpose code. You can use the service to create a dedicated URL for your game server instead of hosting it locally on your own machine. This will enable users to connect to a set URL from any device's browser as long as the device is connected to the internet, regardless of whether via ethernet, Wi-Fi, LTE, etc.
**Pros:**
* Can be accessed from any internet connected device.
* Dedicated URL for your own server.
* Free as long as you're within the platform [restrictions](https://glitch.com/help/restrictions/).
**Cons:**
* Not as fast as a local connection (i.e. your own computer, wireless router, etc.).
* Project are put to sleep after a relatively short period of time (see platform [restrictions](https://glitch.com/help/restrictions/)).
* Projects are subject to a connection limit per hour (see platform [restrictions](https://glitch.com/help/restrictions/)).
* You must create a Glitch account.
* A little bit extra setup (but hopefully the below steps make that easier!).
#### Glitch Quickstart
[[Back to top]](#p5multiplayer)
It's really quick and easy to get up and running with [Glitch](https://glitch.com).
1. Create a free [Glitch](https://glitch.com) account if you don't already have one.
2. Go to [this link](https://glitch.com/~p5-multiplayer), which is a Glitch project containing all of the code from this repository and is already modified to work with Glitch.
3. Open your new project. Glitch will give your project a random name; please rename it at this time (unless you really like the randomly chosen name).
4. 6. In your `host.js` and `index.js` files, change `const serverIp = 'https://p5-multiplayer.glitch.me';` so that what was `p5-multiplayer` now matches your Glitch project name. If you're not sure of what the URL should be, click *Show > In a New Window* at the top of the screen and a new browser window will open with the URL you should use.
#### Glitch Installation
[[Back to top]](#p5multiplayer)
1. Create a free [Glitch](https://glitch.com) account if you don't already have one.
2. Once logged in, click *New Project > Clone from Git Repo*.
3. Copy this repository URL `https://github.com/L05/p5.multiplayer` and paste it where instructed to *Paste the full URL of your repository*.
4. You will be taken to an editor screen. If not, make sure to *Edit your project*.
5. Once in the editor, use the sidebar to go to the project's `public` directory.
6. In your `host.js` and `index.js` files, set `const local = false` as you will be running these using a remote server. Then change `const serverIp = 'https://yourprojectname.glitch.me';` so that `yourprojectname` matches your Glitch project name. If you're not sure of what the URL should be, click *Show > In a New Window* at the top of the screen and a new browser window will open with the URL you should use.
7. Click *Show > In a New Window* to open a new browser window and add `host.html` at the end of the URL. It will look something like `https://yourprojectname.glitch.me/host.html`. You should see a "host" screen with *# players* in the top left of the window and a URL displayed in the bottom left corner. Make note of this URL.
8. In a second browser window, go to the aforementioned URL. You should see a "client" screen displaying a simple controller that lets you control a colored square in your "host" screen.
### Using with Heroku
#### What is Heroku?
[[Back to top]](#p5multiplayer)
[Heroku](https://heroku.com) is a cloud platform as a service that you can use to create a dedicated URL for your game server instead of hosting it locally on your own machine. This will enable users to connect to a set URL from any device's browser as long as the device is connected to the internet, regardless of whether via ethernet, Wi-Fi, LTE, etc.
**Pros:**
* Can be accessed from any internet connected device.
* Dedicated, persistent URL for your own server.
* Free as long as you're within the platform [limits](https://devcenter.heroku.com/articles/limits).
**Cons:**
* Not as fast as a local connection (i.e. your own computer, wireless router, etc.).
* You must create a Heroku account.
* Project are put to sleep after a period of time (see platform [limits](https://devcenter.heroku.com/articles/limits)).
* Projects are subject to a connection limit per hour (see platform [limits](https://devcenter.heroku.com/articles/limits)).
* A little bit extra setup (but hopefully the below steps make that easier!).
#### Heroku Installation
[[Back to top]](#p5multiplayer)
1. Make sure to first follow at least steps 1 through 4 in [Getting Started](#getting-started).
2. Create a free [Heroku](https://heroku.com) account if you don't already have one.
3. Open a terminal window and navigate to the project directory.
4. Create a Heroku app by running the command `heroku create yourservername`, replacing `yourservername` with a server name of your choice.
5. Go to the project's `public` directory and in your `host.js` and `index.js` files, set `const local = false` as you will be running these using a remote server. Then change `const serverIp = 'https://yourservername.herokuapp.com';` to match your Heroku server address.
6. Commit these updates. In the terminal, run the command `git add -a -m "Updating for Heroku deployment"`.
7. Next, in the terminal run the command `git push heroku master`. This will push your code to the remote Heroku server.
8. Open a browser window and go to `https://yourservername.herokuapp.com/host.html`, replacing `yourservername` with the server name you selected in step 4. You should see a "host" screen with *# players* in the top left of the window and a URL displayed in the bottom left corner. Make note of this URL.
9. In a second browser window, go to the aforementioned URL. You should see a "client" screen displaying a simple controller that lets you control a colored square in your "host" screen.
## Custom Hosts
[[Back to top]](#p5multiplayer)
*p5.multiplayer* can be used with custom hosts as long as they implement the core functionality of `setupHost()` and `sendData()` present in [p5.multiplayer.js](public/lib/p5.multiplayer.js).
For example, the host should emit a `'join'` event with `{name: 'host', roomId: roomId}` as data, and the host should register handlers for `'hostconnect'`, `'clientConnect'`, `'clientDisconnect'`, and `'receiveData'`.
Any additional game logic, rendering, etc. can be included beyond that.
An [Unreal Engine](https://unrealengine.com) based custom host example and template is currently in development and will be shared as soon as it is available.
<img src="data/p5.multiplayer_custom_host.png" alt="Diagram of p5.multiplayer running on a remote server with a custom host." width="600">
## Using an HTTPS Server
[[Back to top]](#p5multiplayer)
If needed, you can run a secure HTTPS server instead of an HTTP server ([learn more about the difference here](https://www.cloudflare.com/learning/ssl/why-is-http-not-secure/)), and some applications may only work with HTTPS. For instance, TouchDesigner currently only supports [Socket IO connections over HTTPS](http://derivative.ca/Forum/viewtopic.php?f=4&t=19894). As a note, this section is generally more applicable to local or self-administered server configurations; Glitch and Heroku automatically set up HTTPS for you when using their services to run a remote server.
In order to use an HTTPS server, you'll need an SSL certificate. To do this, open a terminal window and navigate to the project's root directory (where `server.js` and `secureServer.js` are located).
Next, follow these instructions from [nodejs.org](https://nodejs.org/en/knowledge/HTTP/servers/how-to-create-a-HTTPS-server/):
*We need to start out with a word about SSL certificates. Speaking generally, there are two kinds of certificates: those signed by a 'Certificate Authority', or CA, and 'self-signed certificates'. A Certificate Authority is a trusted source for an SSL certificate, and using a certificate from a CA allows your users to be trust the identity of your website. In most cases, you would want to use a CA-signed certificate in a production environment - for testing purposes, however, a self-signed certicate will do just fine.*
*To generate a self-signed certificate, run the following in your shell:*
```
openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
rm csr.pem
```
*This should leave you with two files, `cert.pem` (the certificate) and `key.pem` (the private key). Put these files in the same directory as your Node.js server file. This is all you need for a SSL connection.*
Once you have generated an SSL certificate, you'll follow the same instructions outlined in [Getting Started](#getting-started), but instead of running `node server.js` in Step 5, you'll instead run `node secureServer.js`.
Please note that some browsers may block or issue a warning when pointed to an HTTPS server with a self-signed SSL certificate. For more information on this, [please read here](https://devcenter.heroku.com/articles/ssl-certificate-self).
## Support
[[Back to top]](#p5multiplayer)
Please use *p5.multiplayer* and let me know if you have any feedback!
* Do you **use it in a project**? What works and doesn't work?
* Do you **teach it in a class**? What works and doesn't work?
Any questions pertaining to this project may be communicated via Issues on the [p5.multiplayer GitHub repository](https://github.com/L05/p5.multiplayer). Simply create a new Issue and either assign or tag me in the conversation with [@L05](https://github.com/L05).

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

File diff suppressed because one or more lines are too long

@ -0,0 +1,16 @@
[Home](../README.md) | [Reference](REFERENCE.md) | [Development Notes]()
# Development Notes
## TODOs
* ~~Add ability for host to send data to all clients in room~~
* Add ability for host to send data to specific client
* Encapsulate p5.multiplayer as a class?
* ~~Expand example "game" to include bidirectional communication~~
* ~~Expand example "game" to include a button action~~
* Expand example "game" to be an actual game? (LOL)
* Build example Unreal host template
* Build example TouchDesigner host template
* ~~Add documentation about bidirectional communication to reference~~
* ~~Add documentation section about custom hosts~~

@ -0,0 +1,414 @@
[Home](../README.md) | [Reference]() | [Development Notes](NOTES.md)
# Reference
[Client](#client)
* [setupClient()](#setupclient)
* [sendData()](#senddata-client)
* [isClientConnected()](#isclientconnected)
* [Callbacks](#client-callbacks)
* [onReceiveData()](#onreceivedata-client)
[Host](#host)
* [setupHost()](#setuphost)
* [sendData()](#senddata-host)
* [isHostConnected()](#ishostconnected)
* [displayAddress()](#displayaddress)
* [Callbacks](#host-callbacks)
* [onClientConnect()](#onclientconnect)
* [onClientDisconnect()](#onclientdisconnect)
* [onReceiveData()](#onreceivedata-host)
-----
## Client
-----
#### setupClient()
[[Back to top]](#reference)
##### Example
```javascript
// Network settings
const serverIp = '127.0.0.1';
const serverPort = '3000';
const local = true; // true if running locally, false
// if running on remote server
function setup() {
createCanvas(windowWidth, windowHeight);
setupClient();
}
```
##### Description
Sets up client to connect to server and send messages to host.
##### Syntax
```javascript
setupClient()
```
##### Parameters
`None`
##### Returns
`None`
-----
#### sendData() - *Client*
[[Back to top]](#reference)
##### Example
```javascript
sendData('playerColor', {
r: red(playerColor)/255,
g: green(playerColor)/255,
b: blue(playerColor)/255
});
```
```javascript
let myData = {
val1: 0,
val2: 128,
val3: true
}
sendData('myDataType', myData);
```
##### Description
Sends JavaScript object message of specified data type from client to host.
##### Syntax
```javascript
sendData(datatype, data)
```
##### Parameters
`datatype` String: data type of message
`data` Object: a JavaScript object containing user-defined values
##### Returns
`None`
-----
#### isClientConnected()
[[Back to top]](#reference)
##### Example
```javascript
function draw() {
background(0);
if(isClientConnected(display=true)) {
// Client draw here. ---->
// <----
}
}
```
##### Description
Checks to see if the client is successfully connected to the server and returns Boolean result. If `display=true`, connectivity support instructions are displayed on the screen.
##### Syntax
```javascript
isClientConnected(display)
```
##### Parameters
`display` Boolean: displays connectivity support instructions if `true` (default is `false`)
##### Returns
Boolean: `true` if client is connected, `false` otherwise
-----
### Client Callbacks
User-defined callbacks for handling data received from hosts. These **must** be present in your `index.js` sketch.
-----
#### onReceiveData() - *Client*
[[Back to top]](#reference)
##### Example
```javascript
function onReceiveData (data) {
// Input data processing here. --->
console.log(data);
// <---
/* Example:
if (data.type === 'myDataType') {
processMyData(data);
}
Use `data.type` to get the message type sent by host.
*/
}
```
##### Description
Callback for when data is received from a host. Must be defined in `index.js` sketch. `data` parameter provides all data sent from host and always includes:
* `.id` String: unique ID of host
* `.type` String: data type of message
##### Syntax
```javascript
onReceiveData (data)
```
##### Parameters
`data` Object: contains all data sent from client
##### Returns
`None`
-----
## Host
-----
#### setupHost()
[[Back to top]](#reference)
##### Example
```javascript
// Network settings
const serverIp = '127.0.0.1';
const serverPort = '3000';
const local = true; // true if running locally, false
// if running on remote server
function setup() {
createCanvas(windowWidth, windowHeight);
setupHost();
}
```
##### Description
Sets up host to connect to server and receive messages from clients.
##### Syntax
```javascript
setupHost()
```
##### Parameters
`None`
##### Returns
`None`
-----
#### sendData() - *Host*
[[Back to top]](#reference)
##### Example
```javascript
function mousePressed() {
sendData('timestamp', { timestamp: millis() });
}
```
```javascript
let myData = {
val1: 0,
val2: 128,
val3: true
}
sendData('myDataType', myData);
```
##### Description
Sends JavaScript object message of specified data type from host to all connected clients.
##### Syntax
```javascript
sendData(datatype, data)
```
##### Parameters
`datatype` String: data type of message
`data` Object: a JavaScript object containing user-defined values
##### Returns
`None`
-----
#### isHostConnected()
[[Back to top]](#reference)
##### Example
```javascript
function draw () {
background(15);
if(isHostConnected(display=true)) {
// Host/Game draw here. --->
// <----
// Display server address
displayAddress();
}
}
```
##### Description
Checks to see if the host is successfully connected to the server and returns Boolean result. If `display=true`, connectivity status is displayed on the screen.
##### Syntax
```javascript
isHostConnected(display)
```
##### Parameters
`display` Boolean: displays connectivity status if `true` (default is `false`)
##### Returns
Boolean: `true` if host is connected, `false` otherwise
-----
#### displayAddress()
[[Back to top]](#reference)
##### Example
```javascript
function draw () {
background(15);
if(isHostConnected(display=true)) {
// Host/Game draw here. --->
// <----
// Display server address
displayAddress();
}
}
```
##### Description
Displays the server address in the lower left of the canvas.
##### Syntax
```javascript
displayAddress()
```
##### Parameters
`None`
##### Returns
`None`
-----
### Host Callbacks
User-defined callbacks for handling client connections and disconnections and data received from clients. These **must** be present in your `host.js` sketch.
-----
#### onClientConnect()
[[Back to top]](#reference)
##### Example
```javascript
function onClientConnect (data) {
// Client connect logic here. --->
print(data.id + ' has connected.');
// <----
}
```
##### Description
Callback for when new client connects to server. Must be defined in `host.js` sketch. `data` parameter provides:
* `.id` String: unique ID of client
##### Syntax
```javascript
onClientConnect (data)
```
##### Parameters
`data` Object: contains client connection data
##### Returns
`None`
-----
#### onClientDisconnect()
[[Back to top]](#reference)
##### Example
```javascript
function onClientDisconnect (data) {
// Client connect logic here. --->
print(data.id + ' has disconnected.');
// <----
}
```
##### Description
Callback for when client disconnects from server. Must be defined in `host.js` sketch. `data` parameter provides:
* `.id` String: unique ID of client
##### Syntax
```javascript
onClientDisconnect (data)
```
##### Parameters
`data` Object: contains client connection data
##### Returns
`None`
-----
#### onReceiveData() - *Host*
[[Back to top]](#reference)
##### Example
```javascript
function onReceiveData (data) {
// Input data processing here. --->
console.log(data);
// <---
/* Example:
if (data.type === 'myDataType') {
processMyData(data);
}
Use `data.type` to get the message type sent by client.
*/
}
```
##### Description
Callback for when data is received from a client. Must be defined in `host.js` sketch. `data` parameter provides all data sent from client and always includes:
* `.id` String: unique ID of client
* `.type` String: data type of message
##### Syntax
```javascript
onReceiveData (data)
```
##### Parameters
`data` Object: contains all data sent from client
##### Returns
`None`

656
package-lock.json generated

@ -0,0 +1,656 @@
{
"name": "p5.multiplayer",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"accepts": {
"version": "1.3.7",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
"integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==",
"requires": {
"mime-types": "~2.1.24",
"negotiator": "0.6.2"
}
},
"after": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz",
"integrity": "sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8="
},
"array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
},
"arraybuffer.slice": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz",
"integrity": "sha512-wGUIVQXuehL5TCqQun8OW81jGzAWycqzFF8lFp+GOM5BXLYj3bKNsYC4daB7n6XjCqxQA/qgTJ+8ANR3acjrog=="
},
"async-limiter": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz",
"integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ=="
},
"backo2": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz",
"integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc="
},
"base64-arraybuffer": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz",
"integrity": "sha1-c5JncZI7Whl0etZmqlzUv5xunOg="
},
"base64id": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/base64id/-/base64id-1.0.0.tgz",
"integrity": "sha1-R2iMuZu2gE8OBtPnY7HDLlfY5rY="
},
"better-assert": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz",
"integrity": "sha1-QIZrnhueC1W0gYlDEeaPr/rrxSI=",
"requires": {
"callsite": "1.0.0"
}
},
"blob": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/blob/-/blob-0.0.5.tgz",
"integrity": "sha512-gaqbzQPqOoamawKg0LGVd7SzLgXS+JH61oWprSLH+P+abTczqJbhTR8CmJ2u9/bUYNmHTGJx/UEmn6doAvvuig=="
},
"body-parser": {
"version": "1.19.0",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
"integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==",
"requires": {
"bytes": "3.1.0",
"content-type": "~1.0.4",
"debug": "2.6.9",
"depd": "~1.1.2",
"http-errors": "1.7.2",
"iconv-lite": "0.4.24",
"on-finished": "~2.3.0",
"qs": "6.7.0",
"raw-body": "2.4.0",
"type-is": "~1.6.17"
}
},
"bytes": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
},
"callsite": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz",
"integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA="
},
"component-bind": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz",
"integrity": "sha1-AMYIq33Nk4l8AAllGx06jh5zu9E="
},
"component-emitter": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz",
"integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY="
},
"component-inherit": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/component-inherit/-/component-inherit-0.0.3.tgz",
"integrity": "sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM="
},
"content-disposition": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz",
"integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==",
"requires": {
"safe-buffer": "5.1.2"
}
},
"content-type": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
},
"cookie": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz",
"integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg=="
},
"cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
},
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
},
"destroy": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
},
"encodeurl": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
"integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k="
},
"engine.io": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-3.3.2.tgz",
"integrity": "sha512-AsaA9KG7cWPXWHp5FvHdDWY3AMWeZ8x+2pUVLcn71qE5AtAzgGbxuclOytygskw8XGmiQafTmnI9Bix3uihu2w==",
"requires": {
"accepts": "~1.3.4",
"base64id": "1.0.0",
"cookie": "0.3.1",
"debug": "~3.1.0",
"engine.io-parser": "~2.1.0",
"ws": "~6.1.0"
},
"dependencies": {
"cookie": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz",
"integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s="
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
}
}
},
"engine.io-client": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-3.3.2.tgz",
"integrity": "sha512-y0CPINnhMvPuwtqXfsGuWE8BB66+B6wTtCofQDRecMQPYX3MYUZXFNKDhdrSe3EVjgOu4V3rxdeqN/Tr91IgbQ==",
"requires": {
"component-emitter": "1.2.1",
"component-inherit": "0.0.3",
"debug": "~3.1.0",
"engine.io-parser": "~2.1.1",
"has-cors": "1.1.0",
"indexof": "0.0.1",
"parseqs": "0.0.5",
"parseuri": "0.0.5",
"ws": "~6.1.0",
"xmlhttprequest-ssl": "~1.5.4",
"yeast": "0.1.2"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
}
}
},
"engine.io-parser": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-2.1.3.tgz",
"integrity": "sha512-6HXPre2O4Houl7c4g7Ic/XzPnHBvaEmN90vtRO9uLmwtRqQmTOw0QMevL1TOfL2Cpu1VzsaTmMotQgMdkzGkVA==",
"requires": {
"after": "0.8.2",
"arraybuffer.slice": "~0.0.7",
"base64-arraybuffer": "0.1.5",
"blob": "0.0.5",
"has-binary2": "~1.0.2"
}
},
"escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
},
"etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
},
"express": {
"version": "4.17.1",
"resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz",
"integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==",
"requires": {
"accepts": "~1.3.7",
"array-flatten": "1.1.1",
"body-parser": "1.19.0",
"content-disposition": "0.5.3",
"content-type": "~1.0.4",
"cookie": "0.4.0",
"cookie-signature": "1.0.6",
"debug": "2.6.9",
"depd": "~1.1.2",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"finalhandler": "~1.1.2",
"fresh": "0.5.2",
"merge-descriptors": "1.0.1",
"methods": "~1.1.2",
"on-finished": "~2.3.0",
"parseurl": "~1.3.3",
"path-to-regexp": "0.1.7",
"proxy-addr": "~2.0.5",
"qs": "6.7.0",
"range-parser": "~1.2.1",
"safe-buffer": "5.1.2",
"send": "0.17.1",
"serve-static": "1.14.1",
"setprototypeof": "1.1.1",
"statuses": "~1.5.0",
"type-is": "~1.6.18",
"utils-merge": "1.0.1",
"vary": "~1.1.2"
}
},
"finalhandler": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
"integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==",
"requires": {
"debug": "2.6.9",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"on-finished": "~2.3.0",
"parseurl": "~1.3.3",
"statuses": "~1.5.0",
"unpipe": "~1.0.0"
}
},
"forwarded": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
},
"fresh": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
},
"has-binary2": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has-binary2/-/has-binary2-1.0.3.tgz",
"integrity": "sha512-G1LWKhDSvhGeAQ8mPVQlqNcOB2sJdwATtZKl2pDKKHfpf/rYj24lkinxf69blJbnsvtqqNU+L3SL50vzZhXOnw==",
"requires": {
"isarray": "2.0.1"
}
},
"has-cors": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz",
"integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk="
},
"http-errors": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
"integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==",
"requires": {
"depd": "~1.1.2",
"inherits": "2.0.3",
"setprototypeof": "1.1.1",
"statuses": ">= 1.5.0 < 2",
"toidentifier": "1.0.0"
}
},
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
}
},
"indexof": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz",
"integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10="
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"ipaddr.js": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz",
"integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA=="
},
"isarray": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz",
"integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4="
},
"media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
},
"merge-descriptors": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
"integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E="
},
"methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
"integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4="
},
"mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg=="
},
"mime-db": {
"version": "1.40.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz",
"integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA=="
},
"mime-types": {
"version": "2.1.24",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.24.tgz",
"integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==",
"requires": {
"mime-db": "1.40.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"negotiator": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
},
"object-component": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz",
"integrity": "sha1-8MaapQ78lbhmwYb0AKM3acsvEpE="
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
"requires": {
"ee-first": "1.1.1"
}
},
"parseqs": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/parseqs/-/parseqs-0.0.5.tgz",
"integrity": "sha1-1SCKNzjkZ2bikbouoXNoSSGouJ0=",
"requires": {
"better-assert": "~1.0.0"
}
},
"parseuri": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/parseuri/-/parseuri-0.0.5.tgz",
"integrity": "sha1-gCBKUNTbt3m/3G6+J3jZDkvOMgo=",
"requires": {
"better-assert": "~1.0.0"
}
},
"parseurl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="
},
"path-to-regexp": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
"proxy-addr": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz",
"integrity": "sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ==",
"requires": {
"forwarded": "~0.1.2",
"ipaddr.js": "1.9.0"
}
},
"qs": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ=="
},
"range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg=="
},
"raw-body": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz",
"integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==",
"requires": {
"bytes": "3.1.0",
"http-errors": "1.7.2",
"iconv-lite": "0.4.24",
"unpipe": "1.0.0"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"send": {
"version": "0.17.1",
"resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz",
"integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==",
"requires": {
"debug": "2.6.9",
"depd": "~1.1.2",
"destroy": "~1.0.4",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"fresh": "0.5.2",
"http-errors": "~1.7.2",
"mime": "1.6.0",
"ms": "2.1.1",
"on-finished": "~2.3.0",
"range-parser": "~1.2.1",
"statuses": "~1.5.0"
},
"dependencies": {
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
}
}
},
"serve-static": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz",
"integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==",
"requires": {
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"parseurl": "~1.3.3",
"send": "0.17.1"
}
},
"setprototypeof": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
},
"socket.io": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-2.2.0.tgz",
"integrity": "sha512-wxXrIuZ8AILcn+f1B4ez4hJTPG24iNgxBBDaJfT6MsyOhVYiTXWexGoPkd87ktJG8kQEcL/NBvRi64+9k4Kc0w==",
"requires": {
"debug": "~4.1.0",
"engine.io": "~3.3.1",
"has-binary2": "~1.0.2",
"socket.io-adapter": "~1.1.0",
"socket.io-client": "2.2.0",
"socket.io-parser": "~3.3.0"
},
"dependencies": {
"debug": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
"requires": {
"ms": "^2.1.1"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}
}
},
"socket.io-adapter": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-1.1.1.tgz",
"integrity": "sha1-KoBeihTWNyEk3ZFZrUUC+MsH8Gs="
},
"socket.io-client": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-2.2.0.tgz",
"integrity": "sha512-56ZrkTDbdTLmBIyfFYesgOxsjcLnwAKoN4CiPyTVkMQj3zTUh0QAx3GbvIvLpFEOvQWu92yyWICxB0u7wkVbYA==",
"requires": {
"backo2": "1.0.2",
"base64-arraybuffer": "0.1.5",
"component-bind": "1.0.0",
"component-emitter": "1.2.1",
"debug": "~3.1.0",
"engine.io-client": "~3.3.1",
"has-binary2": "~1.0.2",
"has-cors": "1.1.0",
"indexof": "0.0.1",
"object-component": "0.0.3",
"parseqs": "0.0.5",
"parseuri": "0.0.5",
"socket.io-parser": "~3.3.0",
"to-array": "0.1.4"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
}
}
},
"socket.io-parser": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-3.3.0.tgz",
"integrity": "sha512-hczmV6bDgdaEbVqhAeVMM/jfUfzuEZHsQg6eOmLgJht6G3mPKMxYm75w2+qhAQZ+4X+1+ATZ+QFKeOZD5riHng==",
"requires": {
"component-emitter": "1.2.1",
"debug": "~3.1.0",
"isarray": "2.0.1"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
}
}
},
"statuses": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
},
"to-array": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz",
"integrity": "sha1-F+bBH3PdTz10zaek/zI46a2b+JA="
},
"toidentifier": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
},
"type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
"requires": {
"media-typer": "0.3.0",
"mime-types": "~2.1.24"
}
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
},
"utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
},
"vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
},
"ws": {
"version": "6.1.4",
"resolved": "https://registry.npmjs.org/ws/-/ws-6.1.4.tgz",
"integrity": "sha512-eqZfL+NE/YQc1/ZynhojeV8q+H050oR8AZ2uIev7RU10svA9ZnJUddHcOUZTJLinZ9yEfdA2kSATS2qZK5fhJA==",
"requires": {
"async-limiter": "~1.0.0"
}
},
"xmlhttprequest-ssl": {
"version": "1.5.5",
"resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz",
"integrity": "sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4="
},
"yeast": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz",
"integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk="
}
}
}

@ -0,0 +1,19 @@
{
"name": "p5.multiplayer",
"version": "1.0.0",
"description": "p5.multiplayer example and template",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.4",
"socket.io": "^2.2.0"
},
"engines": {
"node": "10.x"
}
}

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<!-- <meta name="viewport" content="user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1,width=device-width"> -->
<!-- socket.io -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
<!-- p5 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.sound.min.js"></script>
<!-- p5.touchgui -->
<script src="https://unpkg.com/p5.touchgui@0.5.2/lib/p5.touchgui.js"></script>
<!-- p5.play -->
<script src="lib/p5.play.js"></script>
<!-- p5.multiplayer-->
<script src="lib/p5.multiplayer.js"></script>
<!-- p5 sketch -->
<script src="host.js"></script>
<style> body {padding: 0; margin: 0;} </style>
</head>
<body>
</body>
</html>

@ -0,0 +1,314 @@
/*
p5.multiplayer - HOST
This 'host' sketch is intended to be run in desktop browsers.
It connects to a node server via socket.io, from which it receives
rerouted input data from all connected 'clients'.
Navigate to the project's 'public' directory.
Run http-server -c-1 to start server. This will default to port 8080.
Run http-server -c-1 -p80 to start server on open port 80.
*/
////////////
// Network Settings
// const serverIp = 'https://yourservername.herokuapp.com';
// const serverIp = 'https://yourprojectname.glitch.me';
const serverIp = 'http://cdm.jordanorelli.com:3000';
const serverPort = '3000';
const local = false; // true if running locally, false
// if running on remote server
// Global variables here. ---->
const velScale = 10;
const debug = true;
let game;
// <----
function preload() {
setupHost();
}
function setup () {
createCanvas(windowWidth, windowHeight);
// Host/Game setup here. ---->
game = new Game(width, height);
// <----
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function draw () {
background(15);
if(isHostConnected(display=true)) {
// Host/Game draw here. --->
// Display player IDs in top left corner
game.printPlayerIds(5, 20);
// Update and draw game objects
game.draw();
// <----
// Display server address
displayAddress();
}
}
function onClientConnect (data) {
// Client connect logic here. --->
console.log(data.id + ' has connected.');
if (!game.checkId(data.id)) {
game.add(data.id,
random(0.25*width, 0.75*width),
random(0.25*height, 0.75*height),
60, 60
);
}
// <----
}
function onClientDisconnect (data) {
// Client disconnect logic here. --->
if (game.checkId(data.id)) {
game.remove(data.id);
}
// <----
}
function onReceiveData (data) {
// Input data processing here. --->
console.log(data);
if (data.type === 'joystick') {
processJoystick(data);
}
else if (data.type === 'button') {
processButton(data);
}
else if (data.type === 'playerColor') {
game.setColor(data.id, data.r*255, data.g*255, data.b*255);
}
// <----
/* Example:
if (data.type === 'myDataType') {
processMyData(data);
}
Use `data.type` to get the message type sent by client.
*/
}
// This is included for testing purposes to demonstrate that
// messages can be sent from a host back to all connected clients
function mousePressed() {
sendData('timestamp', { timestamp: millis() });
}
////////////
// Input processing
function processJoystick (data) {
game.setVelocity(data.id, data.joystickX*velScale, -data.joystickY*velScale);
if (debug) {
console.log(data.id + ': {' +
data.joystickX + ',' +
data.joystickY + '}');
}
}
function processButton (data) {
game.players[data.id].val = data.button;
game.createRipple(data.id, 300, 1000);
if (debug) {
console.log(data.id + ': ' +
data.button);
}
}
////////////
// Game
// This simple placeholder game makes use of p5.play
class Game {
constructor (w, h) {
this.w = w;
this.h = h;
this.players = {};
this.numPlayers = 0;
this.id = 0;
this.colliders = new Group();
this.ripples = new Ripples();
}
add (id, x, y, w, h) {
this.players[id] = createSprite(x, y, w, h);
this.players[id].id = "p"+this.id;
this.players[id].setCollider("rectangle", 0, 0, w, h);
this.players[id].color = color(255, 255, 255);
this.players[id].shapeColor = color(255, 255, 255);
this.players[id].scale = 1;
this.players[id].mass = 1;
this.colliders.add(this.players[id]);
print(this.players[id].id + " added.");
this.id++;
this.numPlayers++;
}
draw() {
this.checkBounds();
this.ripples.draw();
drawSprites();
}
createRipple(id, r, duration) {
this.ripples.add(
this.players[id].position.x,
this.players[id].position.y,
r,
duration,
this.players[id].color);
}
setColor (id, r, g, b) {
this.players[id].color = color(r, g, b);
this.players[id].shapeColor = color(r, g, b);
print(this.players[id].id + " color added.");
}
remove (id) {
this.colliders.remove(this.players[id]);
this.players[id].remove();
delete this.players[id];
this.numPlayers--;
}
checkId (id) {
if (id in this.players) { return true; }
else { return false; }
}
printPlayerIds (x, y) {
push();
noStroke();
fill(255);
textSize(16);
text("# players: " + this.numPlayers, x, y);
y = y + 16;
fill(200);
for (let id in this.players) {
text(this.players[id].id, x, y);
y += 16;
}
pop();
}
setVelocity(id, velx, vely) {
this.players[id].velocity.x = velx;
this.players[id].velocity.y = vely;
}
checkBounds() {
for (let id in this.players) {
if (this.players[id].position.x < 0) {
this.players[id].position.x = this.w - 1;
}
if (this.players[id].position.x > this.w) {
this.players[id].position.x = 1;
}
if (this.players[id].position.y < 0) {
this.players[id].position.y = this.h - 1;
}
if (this.players[id].position.y > this.h) {
this.players[id].position.y = 1;
}
}
}
}
// A simple pair of classes for generating ripples
class Ripples {
constructor() {
this.ripples = [];
}
add(x, y, r, duration, rcolor) {
this.ripples.push(new Ripple(x, y, r, duration, rcolor));
}
draw() {
for (let i = 0; i < this.ripples.length; i++) {
// Draw each ripple in the array
if(this.ripples[i].draw()) {
// If the ripple is finished (returns true), remove it
this.ripples.splice(i, 1);
}
}
}
}
class Ripple {
constructor(x, y, r, duration, rcolor) {
this.x = x;
this.y = y;
this.r = r;
// If rcolor is not defined, default to white
if (rcolor == null) {
rcolor = color(255);
}
this.stroke = rcolor;
this.strokeWeight = 3;
this.duration = duration; // in milliseconds
this.startTime = millis();
this.endTime = this.startTime + this.duration;
}
draw() {
let progress = (this.endTime - millis())/this.duration;
let r = this.r*(1 - progress);
push();
stroke(red(this.stroke),
green(this.stroke),
blue(this.stroke),
255*progress);
strokeWeight(this.strokeWeight);
fill(0, 0);
ellipse(this.x, this.y, r);
pop();
if (millis() > this.endTime) {
return true;
}
return false;
}
}

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1,width=device-width">
<!-- socket.io -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
<!-- p5 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.sound.min.js"></script>
<!-- p5.touchgui -->
<script src="https://unpkg.com/p5.touchgui@0.5.2/lib/p5.touchgui.js"></script>
<!-- p5.multiplayer-->
<script src="lib/p5.multiplayer.js"></script>
<!-- p5 sketch -->
<script src="index.js"></script>
<style> body {padding: 0; margin: 0;} </style>
</head>
<body>
</body>
</html>

@ -0,0 +1,205 @@
/*
p5.multiplayer - CLIENT
This 'client' sketch is intended to be run in either mobile or
desktop browsers. It sends a basic joystick and button input data
to a node server via socket.io. This data is then rerouted to a
'host' sketch, which displays all connected 'clients'.
Navigate to the project's 'public' directory.
Run http-server -c-1 to start server. This will default to port 8080.
Run http-server -c-1 -p80 to start server on open port 80.
*/
////////////
// Network Settings
// const serverIp = 'https://yourservername.herokuapp.com';
// const serverIp = 'https://yourprojectname.glitch.me';
const serverIp = 'http://cdm.jordanorelli.com:3000';
const serverPort = '3000';
const local = false; // true if running locally, false
// if running on remote server
// Global variables here. ---->
// Initialize GUI related variables
let gui = null;
let button = null;
let joystick = null;
let joystickRes = 4;
let thisJ = {x: 0, y: 0};
let prevJ = {x: 0, y: 0};
// Initialize Game related variables
let playerColor;
let playerColorDim;
// <----
function preload() {
setupClient();
}
function setup() {
createCanvas(windowWidth, windowHeight);
// Client setup here. ---->
gui = createGui();
setPlayerColors();
setupUI();
// <----
// Send any initial setup data to your host here.
/*
Example:
sendData('myDataType', {
val1: 0,
val2: 128,
val3: true
});
Use `type` to classify message types for host.
*/
sendData('playerColor', {
r: red(playerColor)/255,
g: green(playerColor)/255,
b: blue(playerColor)/255
});
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function draw() {
background(0);
if(isClientConnected(display=true)) {
// Client draw here. ---->
drawGui();
// <---
}
}
// Messages can be sent from a host to all connected clients
function onReceiveData (data) {
// Input data processing here. --->
if (data.type === 'timestamp') {
print(data.timestamp);
}
// <----
/* Example:
if (data.type === 'myDataType') {
processMyData(data);
}
Use `data.type` to get the message type sent by host.
*/
}
////////////
// GUI setup
function setPlayerColors() {
let hue = random(0, 360);
colorMode(HSB);
playerColor = color(hue, 100, 100);
playerColorDim = color(hue, 100, 75);
colorMode(RGB);
}
function setupUI() {
// Temp variables for calculating GUI object positions
let jX, jY, jW, jH, bX, bY, bW, bH;
// Rudimentary calculation based on portrait or landscape
if (width < height) {
jX = 0.05*width;
jY = 0.05*height;
jW = 0.9*width;
jH = 0.9*width;
bX = 0.05*windowWidth;
bY = 0.75*windowHeight;
bW = 0.9*windowWidth;
bH = 0.2*windowHeight;
}
else {
jX = 0.05*width;
jY = 0.05*height;
jW = 0.9*height;
jH = 0.9*height;
bX = 0.75*windowWidth;
bY = 0.05*windowHeight;
bW = 0.2*windowWidth;
bH = 0.9*windowHeight;
}
// Create joystick and button, stylize with player colors
joystick = createJoystick("Joystick", jX, jY, jW, jH);
joystick.setStyle({
handleRadius: joystick.w*0.2,
fillBg: color(0),
fillBgHover: color(0),
fillBgActive: color(0),
strokeBg: playerColor,
strokeBgHover: playerColor,
strokeBgActive: playerColor,
fillHandle: playerColorDim,
fillHandleHover: playerColorDim,
fillHandleActive: playerColor,
strokeHandleHover: color(255),
strokeHandleActive: color(255)
});
joystick.onChange = onJoystickChange;
button = createButton("Interact", bX, bY, bW, bH);
button.setStyle({
textSize: 40,
fillBg: playerColorDim,
fillBgHover: playerColorDim,
fillBgActive: playerColor
});
button.onPress = onButtonPress;
}
////////////
// Input processing
function onJoystickChange() {
thisJ.x = floor(joystick.val.x*joystickRes)/joystickRes;
thisJ.y = floor(joystick.val.y*joystickRes)/joystickRes;
if (thisJ.x != prevJ.x || thisJ.y != prevJ.y) {
let data = {
joystickX: thisJ.x,
joystickY: thisJ.y
}
sendData('joystick', data);
}
prevJ.x = thisJ.x;
prevJ.y = thisJ.y;
}
function onButtonPress() {
let data = {
button: button.val
}
sendData('button', data);
}
/// Add these lines below sketch to prevent scrolling on mobile
function touchMoved() {
// do some stuff
return false;
}

@ -0,0 +1 @@
<?php include_once ("home.html") ?>

@ -0,0 +1,150 @@
////////////
// COMMON
// Initialize Network related variables
let socket;
let roomId = null;
let id = null;
// Process URL
// Used to process the room ID. In order to specify a room ID,
// include ?=uniqueName, where uniqueName is replaced with the
// desired unique room ID.
function _processUrl() {
const parameters = location.search.substring(1).split("&");
const temp = parameters[0].split("=");
roomId = unescape(temp[1]);
console.log("id: " + roomId);
}
// Send data from client to host via server
function sendData(datatype, data) {
data.type = datatype;
data.roomId = roomId;
socket.emit('sendData', data);
}
// Displays a message while attempting connection
function _displayWaiting() {
push();
fill(200);
textAlign(CENTER, CENTER);
textSize(20);
text("Attempting connection...", width/2, height/2-10);
pop();
}
////////////
// HOST
// Initialize Network related variables
let hostConnected = false;
function setupHost() {
_processUrl();
let addr = serverIp;
if (local) { addr = serverIp + ':' + serverPort; }
socket = io.connect(addr);
socket.emit('join', {name: 'host', roomId: roomId});
socket.on('id', function(data) {
id = data;
console.log("id: " + id);
});
socket.on('hostConnect', onHostConnect);
socket.on('clientConnect', onClientConnect);
socket.on('clientDisconnect', onClientDisconnect);
socket.on('receiveData', onReceiveData);
}
function isHostConnected(display=false) {
if (!hostConnected) {
if (display) { _displayWaiting(); }
return false;
}
return true;
}
function onHostConnect (data) {
console.log("Host connected to server.");
hostConnected = true;
if (roomId === null || roomId === 'undefined') {
roomId = data.roomId;
}
}
// Displays server address in lower left of screen
function displayAddress() {
push();
fill(255);
textSize(50);
text(serverIp+"/?="+roomId, 10, height-50);
pop();
}
////////////
// CLIENT
// Initialize Network related variables
let waiting = true;
let connected = false;
function setupClient() {
_processUrl();
// Socket.io - open a connection to the web server on specified port
let addr = serverIp;
if (local) { addr = serverIp + ':' + serverPort; }
socket = io.connect(addr);
socket.emit('join', {name: 'client', roomId: roomId});
socket.on('id', function(data) {
id = data;
console.log("id: " + id);
});
socket.on('found', function(data) {
connected = data.status;
waiting = false;
console.log("connected: " + connected);
})
socket.emit('clientConnect', {
roomId: roomId
});
socket.on('receiveData', onReceiveData);
}
function isClientConnected(display=false) {
if (waiting) {
if (display) { _displayWaiting(); }
return false;
}
else if (!connected) {
if (display) { _displayInstructions(); }
return false;
}
return true;
}
// Displays a message instructing player to look at host screen
// for correct link.
function _displayInstructions() {
push();
fill(200);
textAlign(CENTER, CENTER);
textSize(20);
text("Please enter the link at the", width/2, height/2-10);
text("bottom of the host screen.", width/2, height/2+10);
pop();
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,86 @@
////////////////////////////////////////
////////////////////////////////////////
// Requires utilities.js.
class Rotation {
constructor() {
this.rot = createVector(0, 0, 0);
this.rotX = 0;
this.rotY = 0;
this.rotZ = 0;
this.offsetZ = 0;
this.rotZRef = 0;
this.rotationThreshold = 0;
this.debug = false;
}
setDebug(debug) {
this.debug = debug;
}
// Initialize rotation variables
initRotation() {
this.rot.x = rotationX;
this.rot.y = rotationY;
this.rot.z = cycle(rotationZ - this.offsetZ, 0, 360);
}
update() {
this.rot.x = rotationX;
this.rot.y = rotationY;
this.rot.z = cycle(rotationZ - this.offsetZ, 0, 360);
}
// Getters for retrieving rotation
get() {
return this.rot;
}
// Check if change in rotation is above threshold in all three axes.
isChanging() {
if (this.checkX() || this.checkY() || this.checkZ()) {
return true;
} else {
return false;
}
}
isChangingX() {
if (abs(rotationX-pRotationX)>this.rotationThreshold) {
return true;
} else {
return false;
}
}
isChangingY() {
if (abs(rotationY-pRotationY)>this.rotationThreshold) {
return true;
} else {
return false;
}
}
isChangingZ() {
if (abs(rotationZ-pRotationZ)>this.rotationThreshold) {
return true;
} else {
return false;
}
}
// Check to see if device is laying flat
isFlat() {
if (rotationX < 1 && rotationX > -1 && rotationY < 1 && rotationY > -1) {
return true;
} else {
return false;
}
}
// Set the rotation threshold
setRotationThreshold(threshold) {
this.rotationThreshold = threshold;
}
}

@ -0,0 +1,37 @@
// Function that is similar to clamp but loops between a min and max value
function cycle(value, minimum, maximum) {
const difference = maximum - minimum;
if (value > maximum) {
return (value - maximum) % difference + minimum;
} else if (value < minimum) {
return maximum - (minimum - value) % difference;
} else {
return value;
}
}
// A utility function to calculate area of triangle
// formed by (x1, y1) (x2, y2) and (x3, y3)
function triangleArea(x1, y1, x2, y2, x3, y3) {
return abs((x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2))/2.0);
}
// A function to check whether point P(x, y) inside
// the triangle formed by A(x1, y1), B(x2, y2) and C(x3, y3)
function isInsideTriangle(x, y, x1, y1, x2, y2, x3, y3) {
/* Calculate area of triangle ABC */
const A = triangleArea (x1, y1, x2, y2, x3, y3);
/* Calculate area of triangle PBC */
const A1 = triangleArea (x, y, x2, y2, x3, y3);
/* Calculate area of triangle PAC */
const A2 = triangleArea (x1, y1, x, y, x3, y3);
/* Calculate area of triangle PAB */
const A3 = triangleArea (x1, y1, x2, y2, x, y);
/* Check if sum of A1, A2 and A3 is same as A */
return (A == A1 + A2 + A3);
}

@ -0,0 +1,254 @@
// Create dictionaries for tracking hosts, clients, and rooms
let hosts = {};
let clients = {};
let rooms = {};
////////////
// Required for secure server
const fs = require('fs');
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
// Setup express web server and listen on port 3000
let express = require('express');
let app = express();
let port = Number(process.env.PORT || 3000);
let server = require('https').createServer(options, app);
server.listen(port);
app.use(express.static('public'));
console.log("My socket server is running on port " + port);
////////////
// Start socket.io
let socket = require('socket.io');
// Connect it to the web server
let io = socket(server);
////////////
// Setup a connection
io.sockets.on('connection', newConnection);
function newConnection(socket) {
// Inform incoming connection of its ID
console.log('\n' + socket.id + ' is attempting connection...');
socket.emit('id', socket.id);
socket.on('test', function (data) {
console.log('TEST');
});
// Process a request to join.
socket.on('join', function (data) {
// If request is from a client...
if (data.name == 'client') {
console.log("Verifying client...");
// If the roomId field is not null
if (data.roomId != null) {
// Search existing roomIds for a match
console.log("Searching for existing room ID...");
if (rooms[data.roomId] != null) {
// Add client to room with all connected clients
socket.join(data.name);
// Add client and corresponding data to clients dictionary
// by socket ID
clients[socket.id] = {
type: data.name,
roomId: data.roomId
}
// Add client to its own room and to host room by room ID
socket.join([socket.id, data.roomId]);
console.log('Client added to room '+data.roomId+'.\tNumber of clients: ' + Object.keys(clients).length);
// Send match confirmation back to client
socket.emit("found", {status: true});
}
else {
// Notify client of failure to match
socket.emit("found", {status: false});
}
}
}
else if (data.name == 'host') {
// If the attempted connection is from a host...
// Store a transmitted room ID if it exists, otherwise
// generate a random gemstone name as room ID.
let roomId = null;
if (data.roomId === null || data.roomId === 'undefined') {
roomId = makeIdFromList();
}
else {
roomId = data.roomId;
}
// Add client and corresponding data to devices dictionary
// by socket ID
let hostData = {
type: data.name,
roomId: roomId
};
hosts[socket.id] = hostData;
rooms[roomId] = socket.id;
// Add host to "host" room, its own room by room ID, and to a room
// with its clients by room ID.
socket.join([data.name, 'host:'+hostData.roomId, hostData.roomId]);
// Send clients room ID back to host
socket.emit("hostConnect", hostData);
console.log('Host added with room ID of ' + hostData.roomId + '.\tNumber of hosts: ' + Object.keys(hosts).length);
}
else {
console.log('warning: data type not recognized.')
}
})
//// Process device disconnects.
socket.on('disconnect', function () {
console.log('\n' + socket.id + ' has been disconnected!');
if (clients[socket.id] != null) {
// If the device is a client, delete it
delete clients[socket.id];
console.log('Client removed.\tNumber of clients: ' + Object.keys(clients).length);
// Notify hosts that client has disconnected.
socket.in('host').emit('clientDisconnect', {id: socket.id});
}
else if (hosts[socket.id] != null) {
// If the device is a host, delete it
let roomId = hosts[socket.id].roomId;
delete hosts[socket.id];
console.log('Host with ID ' + roomId + ' removed.\tHumber of hosts: ' + Object.keys(hosts).length);
// Remove corresponding room
let key = getKeyByValue(rooms, socket.id);
if (key != null) {
delete rooms[key];
}
// TODO: add handling for all clients connected to host when host
// is disconnected.
}
})
//// Process client connects.
socket.on('clientConnect', onClientConnect);
function onClientConnect(data) {
if (rooms[data.roomId] != null) {
console.log('clientConnect message received from ' + socket.id + ' for room ' + data.roomId + ".");
socket.in('host:'+data.roomId).emit('clientConnect', {id: socket.id, roomId: data.roomId});
}
}
//// Reroute data sent between clients and hosts
socket.on('sendData', sendData);
function sendData(data) {
let packet = {...data};
packet.id = socket.id;
// If room ID is valid...
if (rooms[data.roomId] != null) {
if (clients[socket.id] != null) {
// And if device is a client, send to corresponding host
socket.in('host:'+data.roomId).emit('receiveData', packet);
}
else if (hosts[socket.id] != null) {
// And if device is a host, send to corresponding clients
socket.broadcast.in(data.roomId).emit('receiveData', packet);
}
}
}
}
////////////
// Utility Functions
function searchRoomId(roomId_, array_) {
for (let i = 0; i < array_.length; i++) {
if (array_[i].roomId == roomId_) {
return {
item: array_[i],
index: i
};
}
}
}
function getKeyByValue(object, value) {
return Object.keys(object).find(key => object[key] === value);
}
////////////
// Gemstone room ID generator
const roomNames =
["agate",
"amber",
"amethyst",
"barite",
"beryl",
"bloodstone",
"coral",
"crystal",
"diamond",
"emerald",
"fluorite",
"garnet",
"goldstone",
"jade",
"jasper",
"moonstone",
"onyx",
"opal",
"pearl",
"peridot",
"quahog",
"quartz",
"ruby",
"sapphire",
"sardonyx",
"sunstone",
"tigereye",
"topaz",
"turquoise",
"zircon"]
const roomIds = randomNoRepeats(roomNames);
function randomNoRepeats(array) {
let copy = array.slice(0);
return function() {
if (copy.length < 1) { copy = array.slice(0); }
let index = Math.floor(Math.random() * copy.length);
let item = copy[index];
copy.splice(index, 1);
return {id: item, length: copy.length};
};
}
function makeIdFromList() {
for (let i = 0; i < roomNames.length; i++) {
let text = roomIds().id;
let room = searchRoomId(text, hosts);
if (room == null) {
return text;
}
}
console.log(hosts.length + " hosts detected. No names available.");
return null;
}

@ -0,0 +1,241 @@
// Create dictionaries for tracking hosts, clients, and rooms
let hosts = {};
let clients = {};
let rooms = {};
////////////
// Setup express web server and listen on port 3000
let express = require('express');
let app = express();
let port=Number(process.env.PORT || 3000);
let server = app.listen(port);
app.use(express.static('public'));
console.log("My socket server is running on port " + port);
////////////
// Start socket.io
let socket = require('socket.io');
// Connect it to the web server
let io = socket(server);
////////////
// Setup a connection
io.sockets.on('connection', newConnection);
function newConnection(socket) {
// Inform incoming connection of its ID
console.log('\n' + socket.id + ' is attempting connection...');
socket.emit('id', socket.id);
// Process a request to join.
socket.on('join', function (data) {
// If request is from a client...
if (data.name == 'client') {
console.log("Verifying client...");
// If the roomId field is not null
if (data.roomId != null) {
// Search existing roomIds for a match
console.log("Searching for existing room ID...");
if (rooms[data.roomId] != null) {
// Add client to room with all connected clients
socket.join(data.name);
// Add client and corresponding data to clients dictionary
// by socket ID
clients[socket.id] = {
type: data.name,
roomId: data.roomId
}
// Add client to its own room and to host room by room ID
socket.join([socket.id, data.roomId]);
console.log('Client added to room '+data.roomId+'.\tNumber of clients: ' + Object.keys(clients).length);
// Send match confirmation back to client
socket.emit("found", {status: true});
}
else {
// Notify client of failure to match
socket.emit("found", {status: false});
}
}
}
else if (data.name == 'host') {
// If the attempted connection is from a host...
// Store a transmitted room ID if it exists, otherwise
// generate a random gemstone name as room ID.
let roomId = null;
if (data.roomId === null || data.roomId === 'undefined') {
roomId = makeIdFromList();
}
else {
roomId = data.roomId;
}
// Add client and corresponding data to devices dictionary
// by socket ID
let hostData = {
type: data.name,
roomId: roomId
};
hosts[socket.id] = hostData;
rooms[roomId] = socket.id;
// Add host to "host" room, its own room by room ID, and to a room
// with its clients by room ID.
socket.join([data.name, 'host:'+hostData.roomId, hostData.roomId]);
// Send clients room ID back to host
socket.emit("hostConnect", hostData);
console.log('Host added with room ID of ' + hostData.roomId + '.\tNumber of hosts: ' + Object.keys(hosts).length);
}
else {
console.log('warning: data type not recognized.')
}
})
//// Process device disconnects.
socket.on('disconnect', function () {
console.log('\n' + socket.id + ' has been disconnected!');
if (clients[socket.id] != null) {
// If the device is a client, delete it
delete clients[socket.id];
console.log('Client removed.\tNumber of clients: ' + Object.keys(clients).length);
// Notify hosts that client has disconnected.
socket.in('host').emit('clientDisconnect', {id: socket.id});
}
else if (hosts[socket.id] != null) {
// If the device is a host, delete it
let roomId = hosts[socket.id].roomId;
delete hosts[socket.id];
console.log('Host with ID ' + roomId + ' removed.\tHumber of hosts: ' + Object.keys(hosts).length);
// Remove corresponding room
let key = getKeyByValue(rooms, socket.id);
if (key != null) {
delete rooms[key];
}
// TODO: add handling for all clients connected to host when host
// is disconnected.
}
})
//// Process client connects.
socket.on('clientConnect', onClientConnect);
function onClientConnect(data) {
if (rooms[data.roomId] != null) {
console.log('clientConnect message received from ' + socket.id + ' for room ' + data.roomId + ".");
socket.in('host:'+data.roomId).emit('clientConnect', {id: socket.id, roomId: data.roomId});
}
}
//// Reroute data sent between clients and hosts
socket.on('sendData', sendData);
function sendData(data) {
let packet = {...data};
packet.id = socket.id;
// If room ID is valid...
if (rooms[data.roomId] != null) {
if (clients[socket.id] != null) {
// And if device is a client, send to corresponding host
socket.in('host:'+data.roomId).emit('receiveData', packet);
}
else if (hosts[socket.id] != null) {
// And if device is a host, send to corresponding clients
socket.broadcast.in(data.roomId).emit('receiveData', packet);
}
}
}
}
////////////
// Utility Functions
function searchRoomId(roomId_, array_) {
for (let i = 0; i < array_.length; i++) {
if (array_[i].roomId == roomId_) {
return {
item: array_[i],
index: i
};
}
}
}
function getKeyByValue(object, value) {
return Object.keys(object).find(key => object[key] === value);
}
////////////
// Gemstone room ID generator
const roomNames =
["agate",
"amber",
"amethyst",
"barite",
"beryl",
"bloodstone",
"coral",
"crystal",
"diamond",
"emerald",
"fluorite",
"garnet",
"goldstone",
"jade",
"jasper",
"moonstone",
"onyx",
"opal",
"pearl",
"peridot",
"quahog",
"quartz",
"ruby",
"sapphire",
"sardonyx",
"sunstone",
"tigereye",
"topaz",
"turquoise",
"zircon"]
const roomIds = randomNoRepeats(roomNames);
function randomNoRepeats(array) {
let copy = array.slice(0);
return function() {
if (copy.length < 1) { copy = array.slice(0); }
let index = Math.floor(Math.random() * copy.length);
let item = copy[index];
copy.splice(index, 1);
return {id: item, length: copy.length};
};
}
function makeIdFromList() {
for (let i = 0; i < roomNames.length; i++) {
let text = roomIds().id;
let room = searchRoomId(text, hosts);
if (room == null) {
return text;
}
}
console.log(hosts.length + " hosts detected. No names available.");
return null;
}

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<!-- <meta name="viewport" content="user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1,width=device-width"> -->
<!-- socket.io -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
<!-- p5 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.sound.min.js"></script>
<!-- p5.touchgui -->
<script src="https://unpkg.com/p5.touchgui@0.5.2/lib/p5.touchgui.js"></script>
<!-- p5.multiplayer-->
<script src="lib/p5.multiplayer.js"></script>
<!-- p5 sketch -->
<script src="host.js"></script>
<style> body {padding: 0; margin: 0;} </style>
</head>
<body>
</body>
</html>

@ -0,0 +1,86 @@
/*
p5.multiplayer - HOST
This 'host' sketch is intended to be run in desktop browsers.
It connects to a node server via socket.io, from which it receives
rerouted input data from all connected 'clients'.
Navigate to the project's 'public' directory.
Run http-server -c-1 to start server. This will default to port 8080.
Run http-server -c-1 -p80 to start server on open port 80.
*/
////////////
// Network Settings
// const serverIp = 'https://yourservername.herokuapp.com';
// const serverIp = 'https://yourprojectname.glitch.me';
const serverIp = '127.0.0.1';
const serverPort = '3000';
const local = true; // true if running locally, false
// if running on remote server
// Global variables here. ---->
// <----
function preload() {
setupHost();
}
function setup () {
createCanvas(windowWidth, windowHeight);
// Host/Game setup here. ---->
// <----
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function draw () {
background(15);
if(isHostConnected(display=true)) {
// Host/Game draw here. --->
// <----
// Display server address
displayAddress();
}
}
function onClientConnect (data) {
// Client connect logic here. --->
console.log(data.id + ' has connected.');
// <----
}
function onClientDisconnect (data) {
// Client disconnect logic here. --->
console.log(data.id + ' has disconnected.');
// <----
}
function onReceiveData (data) {
// Input data processing here. --->
console.log(data);
// <---
/* Example:
if (data.type === 'myDataType') {
processMyData(data);
}
Use `data.type` to get the message type sent by client.
*/
}

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1,width=device-width">
<!-- socket.io -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
<!-- p5 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.sound.min.js"></script>
<!-- p5.touchgui -->
<script src="https://unpkg.com/p5.touchgui@0.5.2/lib/p5.touchgui.js"></script>
<!-- p5.multiplayer-->
<script src="lib/p5.multiplayer.js"></script>
<!-- p5 sketch -->
<script src="index.js"></script>
<style> body {padding: 0; margin: 0;} </style>
</head>
<body>
</body>
</html>

@ -0,0 +1,87 @@
/*
p5.multiplayer - CLIENT
This 'client' sketch is intended to be run in either mobile or
desktop browsers. It sends a basic joystick and button input data
to a node server via socket.io. This data is then rerouted to a
'host' sketch, which displays all connected 'clients'.
Navigate to the project's 'public' directory.
Run http-server -c-1 to start server. This will default to port 8080.
Run http-server -c-1 -p80 to start server on open port 80.
*/
////////////
// Network Settings
// const serverIp = 'https://yourservername.herokuapp.com';
// const serverIp = 'https://yourprojectname.glitch.me';
const serverIp = '127.0.0.1';
const serverPort = '3000';
const local = true; // true if running locally, false
// if running on remote server
// Global variables here. ---->
// <----
function preload() {
setupClient();
}
function setup() {
createCanvas(windowWidth, windowHeight);
// Client setup here. ---->
// <----
// Send any initial setup data to your host here.
/*
Example:
sendData('myDataType', {
val1: 0,
val2: 128,
val3: true
});
Use `type` to classify message types for host.
*/
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function draw() {
background(0);
if(isClientConnected(display=true)) {
// Client draw here. ---->
// <----
}
}
// Messages can be sent from a host to all connected clients
function onReceiveData (data) {
// Input data processing here. --->
console.log(data);
// <----
/* Example:
if (data.type === 'myDataType') {
processMyData(data);
}
Use `data.type` to get the message type sent by host.
*/
}
/// Add these lines below sketch to prevent scrolling on mobile
function touchMoved() {
// do some stuff
return false;
}

@ -0,0 +1 @@
<?php include_once ("home.html") ?>

@ -0,0 +1,150 @@
////////////
// COMMON
// Initialize Network related variables
let socket;
let roomId = null;
let id = null;
// Process URL
// Used to process the room ID. In order to specify a room ID,
// include ?=uniqueName, where uniqueName is replaced with the
// desired unique room ID.
function _processUrl() {
const parameters = location.search.substring(1).split("&");
const temp = parameters[0].split("=");
roomId = unescape(temp[1]);
console.log("id: " + roomId);
}
// Send data from client to host via server
function sendData(datatype, data) {
data.type = datatype;
data.roomId = roomId;
socket.emit('sendData', data);
}
// Displays a message while attempting connection
function _displayWaiting() {
push();
fill(200);
textAlign(CENTER, CENTER);
textSize(20);
text("Attempting connection...", width/2, height/2-10);
pop();
}
////////////
// HOST
// Initialize Network related variables
let hostConnected = false;
function setupHost() {
_processUrl();
let addr = serverIp;
if (local) { addr = serverIp + ':' + serverPort; }
socket = io.connect(addr);
socket.emit('join', {name: 'host', roomId: roomId});
socket.on('id', function(data) {
id = data;
console.log("id: " + id);
});
socket.on('hostConnect', onHostConnect);
socket.on('clientConnect', onClientConnect);
socket.on('clientDisconnect', onClientDisconnect);
socket.on('receiveData', onReceiveData);
}
function isHostConnected(display=false) {
if (!hostConnected) {
if (display) { _displayWaiting(); }
return false;
}
return true;
}
function onHostConnect (data) {
console.log("Host connected to server.");
hostConnected = true;
if (roomId === null || roomId === 'undefined') {
roomId = data.roomId;
}
}
// Displays server address in lower left of screen
function displayAddress() {
push();
fill(255);
textSize(50);
text(serverIp+"/?="+roomId, 10, height-50);
pop();
}
////////////
// CLIENT
// Initialize Network related variables
let waiting = true;
let connected = false;
function setupClient() {
_processUrl();
// Socket.io - open a connection to the web server on specified port
let addr = serverIp;
if (local) { addr = serverIp + ':' + serverPort; }
socket = io.connect(addr);
socket.emit('join', {name: 'client', roomId: roomId});
socket.on('id', function(data) {
id = data;
console.log("id: " + id);
});
socket.on('found', function(data) {
connected = data.status;
waiting = false;
console.log("connected: " + connected);
})
socket.emit('clientConnect', {
roomId: roomId
});
socket.on('receiveData', onReceiveData);
}
function isClientConnected(display=false) {
if (waiting) {
if (display) { _displayWaiting(); }
return false;
}
else if (!connected) {
if (display) { _displayInstructions(); }
return false;
}
return true;
}
// Displays a message instructing player to look at host screen
// for correct link.
function _displayInstructions() {
push();
fill(200);
textAlign(CENTER, CENTER);
textSize(20);
text("Please enter the link at the", width/2, height/2-10);
text("bottom of the host screen.", width/2, height/2+10);
pop();
}
Loading…
Cancel
Save