The backend server for phUNO
phDOS uses web sockets to communicate with clients.
{
type: 'update' | 'redirect'
store: svelteStoreName, // if update
data: anyData, // if update
url: '/', // if redirect
message: `Yikes, you were kicked from the room by the host.`, // if redirect
}
entry.ts
: start serversrc
socket.ts
: starts HTTP server, accepts sockets, sends incoming requests to routesroutes/
: contains each routeregister.ts
: adds the client to the Map of socketsdisconnect.ts
: not currently in use
types.ts
: custom Typescript typeslib
generateSecret.ts
: generate random secret stringgetCode.ts
: get an unused code for a new roommakeDeck.ts
: make an empty deck of cardsvalidateNickname.ts
: verify nickname is in proper format
Each socket have the .json()
and .updates()
methods to make sending store updates cleaner. The updateAll
function uses .updates()
on all the sockets connected to a room. The publicizePlayers
function in the same file takes a room and spits out a client safe (no secrets) version to send to clients.
In cloned repository, run
deno run --allow-net --watch --unstable entry.ts