# Server & communication implementation ###### tags: `Semester2` ## Branches ## Initialize server ### Variabelen * lijst van schermen * state: "free", "CatCaster" * lijst van game objecten * lijst van controllers, die allemaal tot exact een game horen * elk game object heeft een lijst schermen en een lijst controllers ### Connections The server is connected to all clients (screens and controllers) via web sockets. D8: all screens are connected via WebRTC with each other (is dat echt nodig?): nadat de foto werd geanaliseerd, alle schermen krijgen een lijst van naburige schermen en connecteren met die. ### Routes VEROUDERD - NOT UP TO DATE When typing the url in the browser * GET `catcaster/team-02/scherm` : maken van een scherm (moet "/screen" zijn volgens opgave) * initialize een scherm * make an unique ID (hexadecimal with unique first characters) * add scherm to lijst van schermen with state "free" * make a websocket between scherm and server * krijgt een QR-code terug (node-qrcode https://github.com/soldair/node-qrcode), deze qr code bevat de url `catcaster/team-02/controller/schermID` When scanning a QR-code from a screen * GET `catcaster/team-02/controller/schermID` : maken van een controller (moet eigenlijk "/screen/{shortScreenID}" zijn volgens [S2] in opgave) * initialize een controller * add controller to lijst van controllers * add the screen ID as an attribute of the controller * make a websocket between scherm and server * if the screen is already in a game * add a cat to the scherm * initialize all webRTC between the new controller and all the screens * if the screen isn't already in a game * display the choice between single- and multi-screen * ... * [S9]: server changes screenmode via websocket When clicking on single-screen * PUT `catcaster/team-02/controller/schermID/single` : * append the game array with a new game object * add the screen to the game * add the controller to the game * change the status of the screen to "CatCaster" * initialize all webRTC between the controller and all the screen * make a websocket between screen and server When clicking on multi-screen * PUT `catcaster/team-02/controller/schermID/multi` : * request a picture of the display * append the game array with a new game object * add the screens to the game * add the controller to the game * change the status of the screens to "CatCaster" * initialize all webRTC between the controllers and all the screens * make websockets between screens and server ### Interesting links - https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API ==> socket.IO gebruiken ?? - https://socket.io/docs/v4/ # TODO - [ ] https (Karam) - [ ] WebRTC! - [ ] signaling-server - [ ] mergen met rest... QR