Skip to content

feat: migrate WebRTC signaling from WebSocket to Ably pub/sub#138

Merged
robbie-anam merged 2 commits intoalphafrom
robbie/feat_ably_connections
Jul 16, 2025
Merged

feat: migrate WebRTC signaling from WebSocket to Ably pub/sub#138
robbie-anam merged 2 commits intoalphafrom
robbie/feat_ably_connections

Conversation

@robbie-anam
Copy link
Contributor

Summary

This PR migrates the WebRTC signaling infrastructure from a custom WebSocket implementation to Ably's pub/sub messaging platform.

Changes

  • Replace custom WebSocket SignallingClient with Ably Realtime implementation
  • Remove heartbeat logic as Ably handles connection health automatically
  • Update ClientConfigResponse to use ablyToken and ablyChannel
  • Hardcode Ably channel rewind parameter to 100 messages
  • Defer connection initialization to connect() method for better resource management
  • Add proper error handling for uninitialized connections
  • Remove message buffering in favor of explicit connection errors
  • Add Ably SDK v2.9.0 dependency

Benefits

  • Improved reliability with Ably's managed infrastructure
  • Automatic reconnection handling
  • Message persistence with rewind capability
  • Simplified codebase without manual heartbeat management
  • Better resource management with deferred connections

Testing

  • Verify WebRTC connection establishment works
  • Test reconnection scenarios
  • Confirm error handling for premature method calls
  • Validate message delivery and ordering

🤖 Generated with Claude Code

@robbie-anam robbie-anam requested a review from Copilot July 16, 2025 16:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates the WebRTC signaling infrastructure from a custom WebSocket implementation to Ably's pub/sub messaging platform, improving reliability and simplifying connection management.

  • Replaces custom WebSocket SignallingClient with Ably Realtime implementation
  • Removes manual heartbeat logic in favor of Ably's automatic connection health management
  • Updates configuration interface to use Ably tokens and channels instead of WebSocket URLs

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/types/signalling/index.ts Removes SignallingURLOptions export as it's no longer needed
src/types/signalling/SignallingClientOptions.ts Replaces WebSocket configuration with Ably token and channel name
src/types/coreApi/StartSessionResponse.ts Updates ClientConfigResponse to provide Ably credentials instead of heartbeat settings
src/modules/SignallingClient.ts Complete rewrite to use Ably Realtime instead of WebSocket with deferred connection initialization
src/AnamClient.ts Updates session initialization to use new Ably-based configuration
package.json Adds Ably SDK v2.9.0 dependency


// Get the channel with hardcoded rewind parameter of 100
this.channel = this.realtime.channels.get(this.channelName, {
params: { rewind: '100' },
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded rewind parameter of '100' should be made configurable or at least documented with a comment explaining why this specific value was chosen.

Suggested change
params: { rewind: '100' },
params: { rewind: String(this.rewind) }, // Use configurable rewind value

Copilot uses AI. Check for mistakes.
}

const offerMessagePayload = {
connectionDescription: localDescription,
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment about renaming userUid to sessionId on the server was removed, but the field name mismatch still exists. Consider adding back the TODO comment or creating a proper tracking item for this inconsistency.

Suggested change
connectionDescription: localDescription,
connectionDescription: localDescription,
// TODO: Rename `userUid` to `sessionId` on the server to resolve this naming inconsistency.

Copilot uses AI. Check for mistakes.
this.socket.onclose = this.onClose.bind(this);
this.socket.onerror = this.onError.bind(this);
return this.socket;
public connect(): void {
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The connect() method return type changed from WebSocket to void, which is a breaking change. Consider documenting this breaking change or providing a migration guide for consumers who might have been using the returned WebSocket.

Copilot uses AI. Check for mistakes.
robbie-anam and others added 2 commits July 16, 2025 09:17
- Replace custom WebSocket SignallingClient with Ably Realtime implementation
- Remove heartbeat logic as Ably handles connection health automatically
- Update ClientConfigResponse to use ablyToken and ablyChannel
- Hardcode Ably channel rewind parameter to 100 messages
- Defer connection initialization to connect() method for better resource management
- Add proper error handling for uninitialized connections
- Remove message buffering in favor of explicit connection errors
- Add Ably SDK v2.9.0 dependency

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
@robbie-anam robbie-anam force-pushed the robbie/feat_ably_connections branch from 0eca5b3 to bfba952 Compare July 16, 2025 16:17
Copy link
Contributor Author

@robbie-anam robbie-anam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robbie-anam robbie-anam merged commit fadc7fa into alpha Jul 16, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants