This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const crypto = require('crypto'); | |
const static = require('node-static'); | |
const file = new static.Server('./'); | |
const server = http.createServer((req, res) => { | |
req.addListener('end', () => file.serve(req, res)).resume(); | |
}); | |
server.on('upgrade', function (req, socket) { | |
if (req.headers['upgrade'] !== 'websocket') { | |
socket.end('HTTP/1.1 400 Bad Request'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//code from the lambda function | |
const request = require("request"); | |
const axios = require("axios"); | |
const ABLY_API_KEY = "<YOUR-ABLY-API-KEY>"; | |
let textData = ""; | |
let originalData; | |
let originalMessagePayload; | |
const publishMessageToAbly = async (textData, originalData, msgTimestamp) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Allocate somewhere to store the final message data | |
const data = Buffer.alloc(payloadLength); | |
// Only unmask the data if the masking bit was set to 1 | |
if (isMasked) { | |
// Loop through the source buffer one byte at a time, keeping track of which | |
// byte in the masking key to use in the next XOR calculation | |
for (let i = 0, j = 0; i < payloadLength; ++i, j = i % 4) { | |
// Extract the correct byte mask from the masking key | |
const shift = j == 3 ? 0 : (3 - j) << 3; | |
const mask = (shift == 0 ? maskingKey : (maskingKey >>> shift)) & 0xFF; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Establish a WebSocket connection to the echo server | |
const ws = new WebSocket('wss://echo.websocket.org'); | |
// Add a listener that will be triggered when the WebSocket is ready to use | |
ws.addEventListener('open', () => { | |
const message = 'Hello!'; | |
console.log('Sending:', message); | |
// Send the message to the WebSocket server | |
ws.send(message); | |
}); | |
// Add a listener in order to process WebSocket messages received from the server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nickname = ""; | |
let nicknameInput = document.getElementById("nickname"); | |
function setNickname() { | |
localStorage.clear() | |
nickname = nicknameInput.value; | |
localStorage.setItem("nickname", nickname); | |
} | |
if(nicknameInput){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let winner = localStorage.getItem("winner"); | |
let firstRunnerUp = localStorage.getItem("firstRunnerUp"); | |
let secondRunnerUp = localStorage.getItem("secondRunnerUp"); | |
let totalPlayers = localStorage.getItem("totalPlayers"); | |
document.getElementById("winner-announcement").innerHTML = | |
winner + " won the game!"; | |
if (firstRunnerUp) { | |
document.getElementById("first-runnerup").innerHTML = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let winner = localStorage.getItem("winner"); | |
let firstRunnerUp = localStorage.getItem("firstRunnerUp"); | |
let secondRunnerUp = localStorage.getItem("secondRunnerUp"); | |
let totalPlayers = localStorage.getItem("totalPlayers"); | |
document.getElementById("winner-announcement").innerHTML = | |
winner + " won the game!"; | |
if (firstRunnerUp) { | |
document.getElementById("first-runnerup").innerHTML = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Space Invaders</title> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<meta name="description" content="Multiplayer space invaders" /> | |
<link | |
id="favicon" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Space Invaders</title> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<meta name="description" content="Multiplayer space invaders" /> | |
<link | |
id="favicon" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Space Invaders</title> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<meta name="description" content="Multiplayer space invaders" /> | |
<link | |
id="favicon" |
NewerOlder