Skip to content

Ratchet

Theis Møller Nørby Jensen edited this page Dec 3, 2024 · 2 revisions

Ratchet

Ratchet is a PHP library for creating bidirectional applications between clients and servers. As of 3-12-2024, Ratchet was used for proof of concept to give an idea of how teachers and students can connect to a quiz and for the teacher to start and skip to the next question. However the current implementation (3-12-2024) is rough and requires a bit of manual labor to get it working.

Location

The WebSocket server can be found in ./server/moodle/websocket/websocket.php

Design

The WebSocket server is its own class containing a constructor and methods for handling different requests/messages.

Objects

Ratchet uses SplObjectStorage for storing connections, the SplObjectStorage is a specialized array that uses object hashes to identify data, this means that not only can it store the connections it can also store additional data pertaining to a certain user, like a student/teachers id along with the quiz they have connected to.

Methods

Ratchet's MessageComponentInterface requires an implementation for onClose(), onError(), onOpen(), and onMessage().

onClose() handles the closing of a connection whenever a client requests to close their connection.

onError() handles any error that may occur with the connection, like losing the connection, abruptly changing pages without closing, and so on. This also closes the connection.

onOpen() handles the initial connections and seperates teachers and students based on the information send in the initial request. onOpen() also starts the process of opening a room for a quiz.

onMessage() handles any request/message that comes after a student/teacher have made their initial connection. This will handle teachers request for starting a quiz, skipping to the next question, and closing a quiz. It also handles request by the students such as answering a question.