Glavin001 / Glavin001/GoPong

GoInstant Platform for multiplayer

Open
#1 1 comment 0 reactions 1 assignee Claimed by @Glavin001 View on GitHub
feature
Dominant language
JavaScript
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Connect URL: https://goinstant.net/glavin001/GoPong
Secret: 8uwWrcPdsHDPgrdP9ixZNxlbhAWltCaBcr1WKRYarou6XmLsFhxj7i2_BSORIQomqNUzotODaX4S

Sample code for setting room:

``` javascript
function setRoomName() {
// if we have the go-SNAKE room in sessionStorage then just connect to
// the room and continue with the initialization.
roomName = sessionStorage.getItem(GO_SNAKE_ID);
if (roomName) {
return true;
}

// if we do not have the name in storage then check to see if the window
// location contains a query string containing the id of the room.

// creating an anchor tag and assigning the href to the window location
// will automatically parse out the URL components ... sweet.
var parser = document.createElement('a');
parser.href = window.location.toString();

var hasRoom = QUERY_REGEX.exec(parser.search);
var roomId = hasRoom && hasRoom[2];
if (roomId) {
roomName = roomId.toString();
// add the cookie to the document.
sessionStorage.setItem(GO_SNAKE_ID, roomName);

// regenerate the URI without the go-SNAKE query parameter and reload
// the page with the new URI.
var beforeRoom = hasRoom[1];
if (beforeRoom[beforeRoom.length - 1] === '&') {
beforeRoom = beforeRoom.slice(0, beforeRoom.lengh - 1);
}
var searchStr = beforeRoom + hasRoom[3];
if (searchStr.length > 0) {
searchStr = '?' + searchStr;
}

parser.search = searchStr;

// set the new location and discontinue the initialization.
window.location = parser.href;
return false;
}

// there is no room to join for this SNAKE so simply create a new
// room and set the cookie in case of future refreshes.
var id = Math.floor(Math.random() * Math.pow(2, 32));
roomName = id.toString();
sessionStorage.setItem(GO_SNAKE_ID, roomName);

return true;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.