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;
}
Connect URL: https://goinstant.net/glavin001/GoPong Secret: 8uwWrcPdsHDPgrdP9ixZNxlbhAWltCaBcr1WKRYarou6XmLsFhxj7i2_BSORIQomqNUzotODaX4S
Sample code for setting room: