twittermatrix icon indicating copy to clipboard operation
twittermatrix copied to clipboard

Fix: Replace dead PubNub Twitter stream with live WebSocket data source

Open konard opened this issue 2 months ago โ€ข 0 comments

๐Ÿ”ง Fix: Replace Dead PubNub Twitter Stream with Live WebSocket Data

๐Ÿ“‹ Issue Reference

Fixes #8

๐Ÿ” Problem Analysis

The application stopped working because the PubNub Twitter stream (pubnub-twitter channel) is no longer functional. This is due to:

  1. Twitter API Changes (Feb 2023): Twitter/X ended free API access in February 2023, moving to a paid tier-only model
  2. PubNub Demo Stream: The PubNub Twitter stream was a demo service that relied on Twitter's free API, which is no longer available
  3. Impact: Both index.html and messages.html were unable to receive real-time data, rendering the matrix visualization non-functional

โœ… Solution Implemented

Replaced the deprecated PubNub Twitter stream with a free, actively maintained WebSocket stream from Quixio's real-time-data-sources:

WebSocket URL: wss://ai-chat-wss-demo-realtimedatasources-prod.deployments.quix.io/timeseries

Data Source: Real-time AI-generated customer support chat conversations (using Llama2 AI agents)

๐Ÿ“ Changes Made

1. index.html

  • โœ… Removed PubNub SDK dependency
  • โœ… Replaced PUBNUB.init() with native WebSocket API
  • โœ… Updated message handling to parse WebSocket JSON format
  • โœ… Added reconnection logic (auto-reload after 5 seconds on disconnect)
  • โœ… Maintained original visual effect and character rendering

2. messages.html

  • โœ… Removed PubNub SDK dependency
  • โœ… Replaced PUBNUB.init() with native WebSocket API
  • โœ… Updated message queue from twitterMessages to chatMessages
  • โœ… Added reconnection logic (auto-reload after 5 seconds on disconnect)
  • โœ… Maintained all original features (speed adjustment, mouse interaction, clickable columns)
  • โœ… Preserved language filtering capability

๐ŸŽฏ Benefits

  1. Working Data Stream: Application now receives real-time data again
  2. No External Dependencies: Removed PubNub SDK, using native WebSocket API
  3. Free & Reliable: Quixio provides a free public stream for demos
  4. Better Resilience: Added automatic reconnection on disconnect
  5. Same Visual Experience: Users see the same Matrix-style falling text effect

๐Ÿงช Testing

Created test utilities in experiments/ folder:

  • test_websocket.html - Simple WebSocket connection test
  • test_server.py - Local HTTP server for testing

To test locally:

cd /path/to/repo
python3 experiments/test_server.py
# Open http://localhost:8000/index.html or http://localhost:8000/messages.html

๐Ÿ“Š Technical Details

WebSocket Message Format:

{
  "timestamps": [1234567890],
  "stringValues": {
    "chat": ["Customer message text here"],
    "conversation_id": ["conv_123"],
    "role": ["customer"]
  }
}

The implementation extracts chat text from stringValues and converts it to Unicode symbols using the existing getSymbols() function, maintaining compatibility with the original visualization logic.

๐Ÿš€ Deployment

No special deployment steps required. The changes work with any static file hosting since WebSocket connections are made client-side.


๐Ÿค– Generated with Claude Code

Co-Authored-By: Claude [email protected]

konard avatar Oct 17 '25 15:10 konard