Code Explainers

Code explainers tagged #real-time

python
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
 
app = FastAPI()
 

Building a WebSocket chat with FastAPI

websockets broadcast connection-management
Intermediate 9 steps
ruby
class ChatChannel < ApplicationCable::Channel
  periodically :sweep_stale_typists, every: 3.seconds
 
  def subscribed

How a typing indicator works in Rails ActionCable

websockets presence cache-expiry
Intermediate 9 steps
typescript
import { Controller, Param, Sse, MessageEvent } from '@nestjs/common';
import { Observable, interval, merge } from 'rxjs';
import { filter, map, takeWhile } from 'rxjs/operators';
import { JobService } from './job.service';

Streaming job progress with SSE in NestJS

server-sent-events reactive-streams rxjs
Intermediate 8 steps
ruby
class ToastBroadcaster
  include ActionView::RecordIdentifier
 
  def self.broadcast_to(user, message:, type: :notice)

How Turbo Stream toasts broadcast in Rails

turbo-streams service-object real-time
Intermediate 6 steps
php
<?php
 
namespace App\Http\Controllers;
 

Broadcasting typing indicators in Laravel

websockets authorization presence-channels
Intermediate 9 steps
php
<?php
 
namespace App\Http\Controllers;
 

Server-Sent Events in Laravel

server-sent-events streaming long-polling
Advanced 9 steps
java
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
 

Real-time chat over STOMP WebSockets in Spring

websockets stomp messaging
Intermediate 8 steps
typescript
import {
  WebSocketGateway,
  WebSocketServer,
  SubscribeMessage,

Building a real-time chat gateway in NestJS

websockets real-time socket.io
Intermediate 8 steps
php
<?php
 
namespace App\Http\Controllers;
 

Streaming job progress with SSE in Laravel

server-sent-events streaming polling
Advanced 8 steps
php
<?php
 
namespace App\Events;
 

How a broadcast event works in Laravel

broadcasting websockets events
Intermediate 5 steps
ruby
class Comment < ApplicationRecord
  belongs_to :post
  belongs_to :author, class_name: "User"
 

Live-updating comments with Turbo in Rails

turbo-streams callbacks associations
Intermediate 8 steps