PHP, Real-Time Web
Most creator economy, virtual collaboration, and remote work applications, such as live online classes, shared whiteboards, and fans live stream meetings, operate through sessions.
A session, such as a video conference, is started. Multiple participants join the session through a link. Users the presence of other users. Messages, data, and files are exchanged between participants. And video tracks are shared.
These session-based applications have become so common, that after constructing several with the Laravel PHP framework, we designed a blueprint for their construction.
It should be emphasized that these application sessions have nothing to do with the standard Laravel session. The sessions are an application-level construction that includes multiple users.
In contrast, the standard Laravel session is created when a user logs in. Each user will still have his/her own standard session.
Here are the elements of the blueprint.
Participants join sessions through a link. These links should include the participant's identity and should be signed for security. A link should be temporary for the duration of the session.
Such signed links are constructed with Laravel signed links. Using middleware we verify the signature and bind the user and session variables of the route.
In many situations you want the session to be activated only at some point in the future, and have a quota on participants. You can use the Larvel-UrlShortener to do all this easily.
All files shared through the session should be usable for the duration of the session and disappear afterward. So these files have to be temporary.
We create such temporary files with Laravel Temporary URLs.
If you read the Laravel documentation, you see the S3 file system mentioned. Not worry. You do not need AWS. This file system can be installed on your server through Minio. Moreover, you can customize
buildTemporaryUrlsUsing to work with any disk.
As participants exchange data, which could be messages, or shared whiteboard pointer position, we use Laravel broadcasting to share these messages over channels.
Such channels should be private, and users are authenticated based on the user binding obtained when joining the session.
All these applications want users to be aware of when users join and leave the session. Laravel presence channels. Once a user is authorized to join the channel, a message is automatically broadcast to all participants. And later on, a leave message is broadcast when a user leaves the session.
While many streaming platforms and APIs are available, as this article is all on the open-source side, we recommend staying with open-source WebRTC. LiveKit is an open-source platform for live audio and video. It works by creating rooms in which participants can join and then publish video and audio tracks. Other participants can subscribe to tracks published in the room and stream the track to an HTML video and audio tag.
So we hope this blueprint will kick start your session-based app. It is all Laravel, all open-source, and all free software.