WebSockets & Real-Time Systems with Spring · Ders

Yazıyor Göstergeleri ve Çevrimiçi Durum

Spring'de STOMP olaylarını, kalp atışlarını ve çevrimiçi durum takibini kullanarak bir sohbet uygulamasına gerçek zamanlı yazıyor göstergeleri ve çevrimiçi durumu eklemeyi öğrenin.

4. ders / 413 adım

Yazıyor Göstergeleri ve Çevrimiçi Durum, CoddyKit'te ücretsiz bir WebSockets & Real-Time Systems with Spring dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, WebSockets & Real-Time Systems with Spring öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. WebSockets & Real-Time Systems with Spring kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Beyond Messages

Great chat apps do more than deliver messages. Typing indicators and online presence make conversations feel live and responsive.

This lesson adds both features on top of your existing STOMP chat.

What Is Presence?

Presence tells users who is currently online, away, or offline. It is updated in real time as users connect and disconnect, giving the social cue that someone is available to chat.

Tracking Connections

Spring publishes SessionConnectedEvent and SessionDisconnectEvent. Listen for them to maintain a live set of online users.

@EventListener
public void onConnect(SessionConnectedEvent event) {
    String user = userFrom(event);
    onlineUsers.add(user);
    broadcastPresence(user, 'ONLINE');
}

Handling Disconnects

When a user disconnects, remove them and notify others so the presence list stays accurate.

@EventListener
public void onDisconnect(SessionDisconnectEvent event) {
    String user = userFrom(event);
    onlineUsers.remove(user);
    broadcastPresence(user, 'OFFLINE');
}

Broadcasting Presence

Send presence updates to a shared topic so every connected client can update its UI.

private void broadcastPresence(String user, String status) {
    Map<String, String> event = new HashMap<>();
    event.put('user', user);
    event.put('status', status);
    messagingTemplate.convertAndSend('/topic/presence', event);
}

A Typing Event Model

Typing indicators are lightweight events, not stored messages. Define a small payload carrying the sender, the room, and whether they started or stopped typing.

{
  "type": "TYPING",
  "room": "general",
  "sender": "alice",
  "typing": true
}

Receiving Typing Events

Map a destination for typing events and relay them to the room topic without persisting them.

@MessageMapping('/chat.typing')
public void typing(TypingEvent event) {
    messagingTemplate.convertAndSend(
        '/topic/room.' + event.getRoom() + '.typing', event);
}

Debouncing on the Client

Clients should not send a typing event for every keystroke. Debounce: send 'typing' once, then send 'stopped' after a short idle period. This reduces traffic dramatically.

let timer = null;
function onKeyPress() {
  sendTyping(true);
  clearTimeout(timer);
  timer = setTimeout(function () { sendTyping(false); }, 2000);
}

Heartbeats for Stale Sessions

Network drops do not always fire a disconnect event. Use STOMP heartbeats so the server can detect dead connections and mark those users offline, keeping presence accurate.

Scaling Presence

With multiple server instances, presence must be shared. Store online users in a central store like Redis and broadcast changes across instances so every client sees a consistent presence list.

Privacy Considerations

Presence and typing reveal user activity. Let users control visibility, and only share presence with people who should see it (for example, contacts or members of the same room), not everyone on the server.

Quick Check

Test your understanding of presence and typing indicators.

Recap

You learned to add online presence using Spring's session connect and disconnect events and typing indicators as lightweight, non-persisted STOMP events. Debouncing, heartbeats, a shared store for scaling, and privacy controls make these features production-ready.

Başlamak ücretsiz

Yapay zeka eğitmeniyle WebSockets & Real-Time Systems with Spring öğren — ücretsiz

Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.

Kurslar
12
Dersler
48

Sıkça Sorulan Sorular

“Yazıyor Göstergeleri ve Çevrimiçi Durum” dersi ücretsiz mi?

Evet — “Yazıyor Göstergeleri ve Çevrimiçi Durum” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve WebSockets & Real-Time Systems with Spring kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. WebSockets & Real-Time Systems with Spring kursu toplamda 4 dersten oluşur.

“Yazıyor Göstergeleri ve Çevrimiçi Durum” dersinde ne öğreneceğim?

Spring'de STOMP olaylarını, kalp atışlarını ve çevrimiçi durum takibini kullanarak bir sohbet uygulamasına gerçek zamanlı yazıyor göstergeleri ve çevrimiçi durumu eklemeyi öğrenin. WebSockets & Real-Time Systems with Spring ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

WebSockets & Real-Time Systems with Spring öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te WebSockets & Real-Time Systems with Spring, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“Yazıyor Göstergeleri ve Çevrimiçi Durum” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu WebSockets & Real-Time Systems with Spring dersinde kod yazıp çalıştırabilir miyim?

Evet. Her WebSockets & Real-Time Systems with Spring dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Sohbet Mesajı Modeli Tasarlama
  2. Genel Sohbet Odalarını Hayata Geçirme
  3. STOMP ile Özel Mesajlaşma
  4. Yazıyor Göstergeleri ve Çevrimiçi Durum
← WebSockets & Real-Time Systems with Spring Sayfasına Dön