Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
// app.js
|
2024-11-14 02:09:58 -05:00
|
|
|
import Hyperswarm from 'hyperswarm';
|
|
|
|
import crypto from 'hypercore-crypto';
|
|
|
|
import b4a from 'b4a';
|
|
|
|
|
|
|
|
let swarm;
|
2024-11-14 03:44:12 -05:00
|
|
|
let stationKey = crypto.randomBytes(32); // Default random key for the station
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
let currentDeviceId = null; // To store the selected audio input device ID
|
|
|
|
let isBroadcasting = false;
|
|
|
|
let localStream; // For broadcaster's audio stream
|
|
|
|
let peerConnections = {}; // Store WebRTC peer connections
|
|
|
|
let iceCandidateQueues = {}; // Store ICE candidate queues
|
|
|
|
let conns = []; // Store Hyperswarm connections
|
2024-11-14 02:09:58 -05:00
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("DOM fully loaded and parsed");
|
2024-11-14 02:09:58 -05:00
|
|
|
document.getElementById('create-station').addEventListener('click', () => {
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("Create Station button clicked");
|
2024-11-14 03:44:12 -05:00
|
|
|
const createStationModal = new bootstrap.Modal(document.getElementById('createStationModal'));
|
|
|
|
createStationModal.show();
|
2024-11-14 02:09:58 -05:00
|
|
|
});
|
2024-11-14 03:44:12 -05:00
|
|
|
|
|
|
|
document.getElementById('generate-new-key').addEventListener('click', () => {
|
|
|
|
stationKey = crypto.randomBytes(32);
|
2024-11-23 05:06:43 -05:00
|
|
|
document.getElementById('existing-key').value = b4a.toString(stationKey, 'hex');
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("New station key generated");
|
2024-11-14 03:44:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById('create-station-button').addEventListener('click', () => {
|
|
|
|
const existingKey = document.getElementById('existing-key').value.trim();
|
|
|
|
stationKey = existingKey ? b4a.from(existingKey, 'hex') : stationKey;
|
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("Creating station with key:", b4a.toString(stationKey, 'hex'));
|
2024-11-14 03:44:12 -05:00
|
|
|
setupStation(stationKey);
|
2024-11-23 05:06:43 -05:00
|
|
|
|
2024-11-14 03:44:12 -05:00
|
|
|
const createStationModal = bootstrap.Modal.getInstance(document.getElementById('createStationModal'));
|
|
|
|
createStationModal.hide();
|
|
|
|
});
|
|
|
|
|
2024-11-14 02:09:58 -05:00
|
|
|
document.getElementById('leave-stream').addEventListener('click', () => {
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("Leave Stream button clicked");
|
2024-11-14 02:09:58 -05:00
|
|
|
leaveStation();
|
|
|
|
});
|
2024-11-14 03:44:12 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
document.getElementById('join-station-button').addEventListener('click', () => {
|
|
|
|
console.log("Join Station button clicked");
|
|
|
|
joinStation();
|
|
|
|
const joinModal = bootstrap.Modal.getInstance(document.getElementById('joinModal'));
|
|
|
|
joinModal.hide();
|
|
|
|
});
|
|
|
|
|
2024-11-14 02:09:58 -05:00
|
|
|
document.getElementById('apply-audio-source').addEventListener('click', applyAudioSource);
|
|
|
|
|
|
|
|
populateAudioInputSources();
|
|
|
|
});
|
|
|
|
|
|
|
|
async function populateAudioInputSources() {
|
|
|
|
try {
|
|
|
|
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
|
|
const audioInputSelect = document.getElementById('audio-input-select');
|
2024-11-23 05:06:43 -05:00
|
|
|
audioInputSelect.innerHTML = '';
|
2024-11-14 02:09:58 -05:00
|
|
|
devices.forEach((device) => {
|
|
|
|
if (device.kind === 'audioinput') {
|
|
|
|
const option = document.createElement('option');
|
|
|
|
option.value = device.deviceId;
|
|
|
|
option.textContent = device.label || `Microphone ${audioInputSelect.length + 1}`;
|
|
|
|
audioInputSelect.appendChild(option);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
currentDeviceId = audioInputSelect.value;
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("Audio input devices populated");
|
2024-11-14 02:09:58 -05:00
|
|
|
} catch (err) {
|
|
|
|
console.error("Error enumerating devices:", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
// Updated applyAudioSource function
|
2024-11-14 02:09:58 -05:00
|
|
|
async function applyAudioSource() {
|
|
|
|
const selectedDeviceId = document.getElementById('audio-input-select').value;
|
|
|
|
if (selectedDeviceId !== currentDeviceId) {
|
|
|
|
currentDeviceId = selectedDeviceId;
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
if (isBroadcasting) {
|
|
|
|
console.log("Applying new audio source:", selectedDeviceId);
|
|
|
|
try {
|
|
|
|
// Get the new audio stream
|
|
|
|
const newStream = await navigator.mediaDevices.getUserMedia({
|
|
|
|
audio: { deviceId: currentDeviceId ? { exact: currentDeviceId } : undefined },
|
|
|
|
});
|
|
|
|
console.log("New audio stream obtained");
|
|
|
|
|
|
|
|
// Replace tracks in existing peer connections
|
|
|
|
for (const remoteKey in peerConnections) {
|
|
|
|
const peerConnection = peerConnections[remoteKey];
|
|
|
|
const senders = peerConnection.getSenders();
|
|
|
|
for (const sender of senders) {
|
|
|
|
if (sender.track && sender.track.kind === 'audio') {
|
|
|
|
const newTrack = newStream.getAudioTracks()[0];
|
|
|
|
await sender.replaceTrack(newTrack);
|
|
|
|
console.log(`Replaced audio track for peer ${remoteKey}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop the old audio tracks
|
|
|
|
if (localStream) {
|
|
|
|
localStream.getTracks().forEach((track) => track.stop());
|
|
|
|
console.log("Old audio tracks stopped");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the localStream
|
|
|
|
localStream = newStream;
|
|
|
|
console.log("localStream updated with new audio stream");
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error applying new audio source:", err);
|
|
|
|
alert("Failed to apply new audio source. Please try again.");
|
|
|
|
}
|
|
|
|
}
|
2024-11-14 02:09:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
// Update peer count using conns.length
|
|
|
|
function updatePeerCount() {
|
|
|
|
const peerCount = conns.length;
|
|
|
|
const stationInfoElement = document.getElementById('station-info');
|
|
|
|
if (isBroadcasting) {
|
|
|
|
stationInfoElement.textContent = `Station ID: ${b4a.toString(stationKey, 'hex')}\nConnected Peers: ${peerCount}`;
|
|
|
|
} else {
|
|
|
|
stationInfoElement.textContent = `Connected Peers: ${peerCount}`;
|
|
|
|
}
|
|
|
|
console.log(`Peer count updated: ${peerCount}`);
|
|
|
|
}
|
2024-11-14 02:09:58 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
async function setupStation(key) {
|
2024-11-14 02:09:58 -05:00
|
|
|
try {
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("Setting up station...");
|
|
|
|
// Initialize Hyperswarm
|
|
|
|
swarm = new Hyperswarm();
|
|
|
|
swarm.join(key, { client: false, server: true });
|
|
|
|
|
|
|
|
// Get user media (audio input)
|
|
|
|
localStream = await navigator.mediaDevices.getUserMedia({
|
2024-11-14 02:09:58 -05:00
|
|
|
audio: { deviceId: currentDeviceId ? { exact: currentDeviceId } : undefined },
|
|
|
|
});
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("Local audio stream obtained");
|
2024-11-23 04:28:41 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
isBroadcasting = true;
|
2024-11-14 02:09:58 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
swarm.on('connection', (conn) => {
|
|
|
|
console.log("New connection established");
|
|
|
|
conns.push(conn);
|
|
|
|
updatePeerCount(); // Update peer count when a new connection is established
|
|
|
|
const remoteKey = conn.remotePublicKey.toString('hex');
|
|
|
|
console.log("Remote key:", remoteKey);
|
|
|
|
|
|
|
|
// Initialize ICE candidate queue
|
|
|
|
iceCandidateQueues[remoteKey] = [];
|
|
|
|
|
|
|
|
// Handle incoming signaling data
|
|
|
|
conn.on('data', async (data) => {
|
|
|
|
console.log("Received data from peer:", data.toString());
|
|
|
|
const message = JSON.parse(data.toString());
|
|
|
|
await handleSignalingData(conn, message);
|
|
|
|
});
|
|
|
|
|
|
|
|
conn.on('close', () => {
|
|
|
|
console.log("Connection closed with peer:", remoteKey);
|
|
|
|
// Clean up peer connection when connection closes
|
|
|
|
if (peerConnections[remoteKey]) {
|
|
|
|
peerConnections[remoteKey].close();
|
|
|
|
delete peerConnections[remoteKey];
|
|
|
|
}
|
|
|
|
delete iceCandidateQueues[remoteKey];
|
|
|
|
conns.splice(conns.indexOf(conn), 1);
|
|
|
|
updatePeerCount(); // Update peer count when a connection is closed
|
|
|
|
});
|
|
|
|
|
|
|
|
conn.on('error', (err) => {
|
|
|
|
console.error("Connection error with peer:", remoteKey, err);
|
|
|
|
if (peerConnections[remoteKey]) {
|
|
|
|
peerConnections[remoteKey].close();
|
|
|
|
delete peerConnections[remoteKey];
|
|
|
|
}
|
|
|
|
delete iceCandidateQueues[remoteKey];
|
|
|
|
conns.splice(conns.indexOf(conn), 1);
|
|
|
|
updatePeerCount(); // Update peer count on error
|
|
|
|
});
|
|
|
|
});
|
2024-11-14 02:09:58 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
document.getElementById('broadcaster-controls').classList.remove('d-none');
|
|
|
|
document.getElementById('setup').classList.add('d-none');
|
|
|
|
document.getElementById('controls').classList.remove('d-none');
|
|
|
|
document.getElementById('station-info').textContent = `Station ID: ${b4a.toString(key, 'hex')}`;
|
|
|
|
|
|
|
|
console.log("Station setup complete");
|
2024-11-14 02:09:58 -05:00
|
|
|
} catch (err) {
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.error("Error setting up station:", err);
|
|
|
|
alert("Failed to set up station. Please try again.");
|
2024-11-14 02:09:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopBroadcast() {
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("Broadcast stopped");
|
|
|
|
// Close all peer connections
|
|
|
|
Object.values(peerConnections).forEach((pc) => pc.close());
|
|
|
|
peerConnections = {};
|
|
|
|
|
|
|
|
// Stop local media tracks
|
|
|
|
if (localStream) {
|
|
|
|
localStream.getTracks().forEach((track) => track.stop());
|
|
|
|
localStream = null;
|
|
|
|
console.log("Local media tracks stopped");
|
2024-11-14 02:09:58 -05:00
|
|
|
}
|
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
isBroadcasting = false;
|
2024-11-23 05:06:43 -05:00
|
|
|
}
|
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
async function handleSignalingData(conn, message, peerConnection = null) {
|
|
|
|
try {
|
|
|
|
const remoteKey = conn.remotePublicKey.toString('hex');
|
|
|
|
console.log("Handling signaling data:", message.type, "from", remoteKey);
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
if (!peerConnection) {
|
|
|
|
peerConnection = peerConnections[remoteKey];
|
|
|
|
}
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
if (message.type === 'offer') {
|
|
|
|
// Received an offer from a listener (only for broadcaster)
|
|
|
|
console.log("Creating new RTCPeerConnection for remote key:", remoteKey);
|
|
|
|
const configuration = {
|
|
|
|
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }],
|
|
|
|
};
|
|
|
|
peerConnection = new RTCPeerConnection(configuration);
|
|
|
|
peerConnections[remoteKey] = peerConnection;
|
|
|
|
|
|
|
|
// Add local stream tracks to peer connection
|
|
|
|
localStream.getTracks().forEach((track) => {
|
|
|
|
peerConnection.addTrack(track, localStream);
|
|
|
|
console.log("Added track to peer connection:", track);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Handle ICE candidates
|
|
|
|
peerConnection.onicecandidate = ({ candidate }) => {
|
|
|
|
if (candidate) {
|
|
|
|
console.log("Sending ICE candidate to peer:", candidate);
|
|
|
|
conn.write(JSON.stringify({ type: 'candidate', candidate }));
|
|
|
|
} else {
|
|
|
|
console.log("All ICE candidates have been sent to peer");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
peerConnection.oniceconnectionstatechange = () => {
|
|
|
|
console.log("Broadcaster ICE connection state changed to:", peerConnection.iceConnectionState);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set remote description
|
|
|
|
await peerConnection.setRemoteDescription(new RTCSessionDescription(message.offer));
|
|
|
|
console.log("Set remote description with offer from peer");
|
|
|
|
|
|
|
|
// Process any queued ICE candidates
|
|
|
|
if (iceCandidateQueues[remoteKey]) {
|
|
|
|
console.log("Processing queued ICE candidates");
|
|
|
|
for (const candidate of iceCandidateQueues[remoteKey]) {
|
|
|
|
await peerConnection.addIceCandidate(candidate);
|
|
|
|
console.log("Added queued ICE candidate");
|
|
|
|
}
|
|
|
|
iceCandidateQueues[remoteKey] = [];
|
|
|
|
}
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
const answer = await peerConnection.createAnswer();
|
|
|
|
await peerConnection.setLocalDescription(answer);
|
|
|
|
console.log("Created and set local description with answer");
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
// Send the answer back to the listener
|
|
|
|
conn.write(JSON.stringify({ type: 'answer', answer }));
|
|
|
|
console.log("Sent answer to peer");
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
} else if (message.type === 'candidate') {
|
|
|
|
// Received an ICE candidate
|
|
|
|
const candidate = new RTCIceCandidate(message.candidate);
|
|
|
|
console.log("Received ICE candidate from peer:", candidate);
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
if (peerConnection && peerConnection.remoteDescription && peerConnection.remoteDescription.type) {
|
|
|
|
await peerConnection.addIceCandidate(candidate);
|
|
|
|
console.log("Added ICE candidate to peer connection");
|
|
|
|
} else {
|
|
|
|
console.log("Remote description not set yet, queuing ICE candidate");
|
|
|
|
if (!iceCandidateQueues[remoteKey]) {
|
|
|
|
iceCandidateQueues[remoteKey] = [];
|
|
|
|
}
|
|
|
|
iceCandidateQueues[remoteKey].push(candidate);
|
|
|
|
}
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
} else if (message.type === 'answer') {
|
|
|
|
// Received an answer from the broadcaster (only for listener)
|
|
|
|
console.log("Received answer from broadcaster");
|
|
|
|
await peerConnection.setRemoteDescription(new RTCSessionDescription(message.answer));
|
|
|
|
console.log("Set remote description with answer from broadcaster");
|
|
|
|
|
|
|
|
// Process any queued ICE candidates
|
|
|
|
if (iceCandidateQueues[remoteKey]) {
|
|
|
|
console.log("Processing queued ICE candidates");
|
|
|
|
for (const candidate of iceCandidateQueues[remoteKey]) {
|
|
|
|
await peerConnection.addIceCandidate(candidate);
|
|
|
|
console.log("Added queued ICE candidate");
|
|
|
|
}
|
|
|
|
iceCandidateQueues[remoteKey] = [];
|
|
|
|
}
|
2024-11-23 05:06:43 -05:00
|
|
|
}
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
} catch (err) {
|
|
|
|
console.error("Error handling signaling data:", err);
|
2024-11-14 02:09:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
function leaveStation() {
|
|
|
|
console.log("Leaving station...");
|
|
|
|
if (swarm) {
|
|
|
|
swarm.destroy();
|
|
|
|
console.log("Swarm destroyed");
|
|
|
|
}
|
2024-11-14 02:09:58 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
// Close all peer connections
|
|
|
|
Object.values(peerConnections).forEach((pc) => pc.close());
|
|
|
|
peerConnections = {};
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
// Close all Hyperswarm connections
|
|
|
|
conns.forEach((conn) => conn.destroy());
|
|
|
|
conns = [];
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
// Stop local media tracks
|
|
|
|
if (localStream) {
|
|
|
|
localStream.getTracks().forEach((track) => track.stop());
|
|
|
|
localStream = null;
|
|
|
|
console.log("Local media tracks stopped");
|
|
|
|
}
|
2024-11-14 02:09:58 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
isBroadcasting = false;
|
2024-11-14 02:09:58 -05:00
|
|
|
|
|
|
|
document.getElementById('setup').classList.remove('d-none');
|
|
|
|
document.getElementById('controls').classList.add('d-none');
|
|
|
|
document.getElementById('broadcaster-controls').classList.add('d-none');
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
document.getElementById('listener-controls').classList.add('d-none');
|
|
|
|
document.getElementById('station-info').textContent = '';
|
2024-11-14 02:09:58 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("Left the station.");
|
2024-11-14 02:09:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async function joinStation() {
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
try {
|
|
|
|
const stationId = document.getElementById('station-id').value;
|
|
|
|
if (!stationId) {
|
|
|
|
alert("Please enter a station ID.");
|
|
|
|
return;
|
|
|
|
}
|
2024-11-14 02:09:58 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("Joining station with ID:", stationId);
|
|
|
|
const topicBuffer = b4a.from(stationId, 'hex');
|
|
|
|
swarm = new Hyperswarm();
|
|
|
|
swarm.join(topicBuffer, { client: true, server: false });
|
|
|
|
|
|
|
|
swarm.on('connection', (conn) => {
|
|
|
|
console.log("Connected to broadcaster");
|
|
|
|
conns.push(conn);
|
|
|
|
updatePeerCount(); // Update peer count when a new connection is established
|
|
|
|
const remoteKey = conn.remotePublicKey.toString('hex');
|
|
|
|
console.log("Remote key:", remoteKey);
|
|
|
|
|
|
|
|
// Initialize ICE candidate queue
|
|
|
|
iceCandidateQueues[remoteKey] = [];
|
|
|
|
|
|
|
|
const configuration = {
|
|
|
|
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }],
|
|
|
|
};
|
|
|
|
const peerConnection = new RTCPeerConnection(configuration);
|
|
|
|
peerConnections[remoteKey] = peerConnection;
|
|
|
|
|
|
|
|
// Add transceiver to receive audio
|
|
|
|
peerConnection.addTransceiver('audio', { direction: 'recvonly' });
|
|
|
|
|
|
|
|
// Handle incoming tracks (audio streams)
|
|
|
|
peerConnection.ontrack = (event) => {
|
|
|
|
console.log("Received remote track");
|
|
|
|
const [remoteStream] = event.streams;
|
|
|
|
// Play the remote audio stream
|
|
|
|
const audioElement = document.createElement('audio');
|
|
|
|
audioElement.srcObject = remoteStream;
|
|
|
|
audioElement.autoplay = true;
|
|
|
|
document.body.appendChild(audioElement);
|
|
|
|
console.log("Audio element created and playback started");
|
|
|
|
};
|
|
|
|
|
|
|
|
// Handle ICE candidates
|
|
|
|
peerConnection.onicecandidate = ({ candidate }) => {
|
|
|
|
if (candidate) {
|
|
|
|
console.log("Sending ICE candidate to broadcaster:", candidate);
|
|
|
|
conn.write(JSON.stringify({ type: 'candidate', candidate }));
|
|
|
|
} else {
|
|
|
|
console.log("All ICE candidates have been sent to broadcaster");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
peerConnection.oniceconnectionstatechange = () => {
|
|
|
|
console.log("Listener ICE connection state changed to:", peerConnection.iceConnectionState);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Handle signaling data from broadcaster
|
|
|
|
conn.on('data', async (data) => {
|
|
|
|
console.log("Received data from broadcaster:", data.toString());
|
|
|
|
const message = JSON.parse(data.toString());
|
|
|
|
await handleSignalingData(conn, message, peerConnection);
|
|
|
|
});
|
|
|
|
|
|
|
|
conn.on('close', () => {
|
|
|
|
console.log("Connection closed with broadcaster");
|
|
|
|
peerConnection.close();
|
|
|
|
delete peerConnections[remoteKey];
|
|
|
|
delete iceCandidateQueues[remoteKey];
|
|
|
|
conns.splice(conns.indexOf(conn), 1);
|
|
|
|
updatePeerCount(); // Update peer count when a connection is closed
|
|
|
|
});
|
|
|
|
|
|
|
|
conn.on('error', (err) => {
|
|
|
|
console.error("Connection error with broadcaster:", err);
|
|
|
|
peerConnection.close();
|
|
|
|
delete peerConnections[remoteKey];
|
|
|
|
delete iceCandidateQueues[remoteKey];
|
|
|
|
conns.splice(conns.indexOf(conn), 1);
|
|
|
|
updatePeerCount(); // Update peer count on error
|
|
|
|
});
|
|
|
|
|
|
|
|
// Start signaling process
|
|
|
|
initiateOffer(conn, peerConnection, remoteKey);
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
updatePeerCount();
|
|
|
|
});
|
2024-11-14 02:09:58 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
document.getElementById('station-info').textContent = `Connected to Station: ${stationId}`;
|
|
|
|
document.getElementById('setup').classList.add('d-none');
|
|
|
|
document.getElementById('controls').classList.remove('d-none');
|
|
|
|
document.getElementById('listener-controls').classList.remove('d-none');
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("Joined station successfully");
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error joining station:", err);
|
|
|
|
alert("Failed to join station. Please try again.");
|
|
|
|
}
|
|
|
|
}
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
async function initiateOffer(conn, peerConnection, remoteKey) {
|
|
|
|
try {
|
|
|
|
console.log("Initiating offer to broadcaster");
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
// Handle ICE candidates
|
|
|
|
peerConnection.onicecandidate = ({ candidate }) => {
|
|
|
|
if (candidate) {
|
|
|
|
console.log("Sending ICE candidate to broadcaster:", candidate);
|
|
|
|
conn.write(JSON.stringify({ type: 'candidate', candidate }));
|
2024-11-14 02:09:58 -05:00
|
|
|
} else {
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
console.log("All ICE candidates have been sent to broadcaster");
|
2024-11-14 02:09:58 -05:00
|
|
|
}
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
};
|
2024-11-14 02:09:58 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
peerConnection.oniceconnectionstatechange = () => {
|
|
|
|
console.log("Listener ICE connection state changed to:", peerConnection.iceConnectionState);
|
|
|
|
};
|
2024-11-23 05:06:43 -05:00
|
|
|
|
Refactor application to integrate WebRTC for audio streaming and enhance overall functionality
**Overview:**
This commit represents a comprehensive refactoring of the application to improve real-time audio streaming capabilities. The key change is the integration of WebRTC for peer-to-peer audio streaming while using Hyperswarm exclusively for signaling. This transition addresses efficiency, reliability, and scalability issues present in the original implementation.
**Old Method:**
- **Audio Streaming via Hyperswarm Data Channels:**
- The original code used Hyperswarm for both signaling and streaming audio data.
- Audio data was captured from the microphone, converted to binary, and transmitted over Hyperswarm connections.
- Listeners received the audio data chunks and processed them to play back the audio.
- **Issues:**
- Inefficient for real-time audio streaming due to Hyperswarm's limitations for media data.
- Higher latency and potential synchronization problems.
- Difficulty managing peer connections and media streams effectively.
**New Method:**
- **Integration of WebRTC for Audio Streaming:**
- Implemented `RTCPeerConnection` instances for efficient, real-time, peer-to-peer audio streaming.
- Used Hyperswarm solely for signaling to establish and manage connections.
- Audio tracks are now transmitted over WebRTC connections, leveraging optimized protocols for media.
- **Benefits:**
- Improved audio quality and reduced latency.
- Enhanced NAT traversal and firewall compatibility via ICE servers.
- Better management of media streams and peer connections.
**Key Changes:**
1. **WebRTC Implementation:**
- **Broadcaster Side:**
- Created `RTCPeerConnection` instances for each listener.
- Added local audio tracks from the microphone to the peer connections.
- Managed signaling messages (`offer`, `answer`, `candidate`) received via Hyperswarm.
- Handled ICE candidate exchange and connection state changes.
- **Listener Side:**
- Created an `RTCPeerConnection` to connect to the broadcaster.
- Added a transceiver with `recvonly` direction to receive audio streams.
- Managed signaling messages and ICE candidates.
- Played received audio streams using HTML `<audio>` elements.
2. **Signaling via Hyperswarm:**
- Utilized Hyperswarm connections for exchanging signaling messages in JSON format.
- Messages include `offer`, `answer`, and `candidate` types.
- Ensured proper serialization and deserialization of signaling data.
3. **ICE Candidate Handling:**
- Implemented ICE candidate queuing to handle candidates arriving before the remote description is set.
- Stored incoming ICE candidates in queues and processed them after setting the remote description.
- Added detailed logging for ICE candidate exchange and connection states.
4. **Peer Count Accuracy:**
- Updated the `updatePeerCount()` function to use `conns.length`, reflecting active Hyperswarm connections.
- Ensured the peer count updates immediately when connections are established or closed.
- Improved UI feedback regarding the number of connected peers.
5. **Audio Input Switching Without Disconnecting Peers:**
- Modified the `applyAudioSource()` function to replace audio tracks in existing peer connections without restarting the station.
- Obtained a new audio stream with the selected input device.
- Used `RTCRtpSender.replaceTrack()` to update the audio track in each peer connection.
- Stopped old audio tracks to free up resources.
- Allowed broadcasters to switch microphones seamlessly without interrupting listeners' audio.
6. **Error Handling and Debugging Improvements:**
- Added extensive logging throughout the code to trace execution flow and internal state.
- Wrapped asynchronous operations in `try...catch` blocks to handle errors gracefully.
- Provided informative console messages for successful operations and errors.
7. **User Interface Adjustments:**
- Retained existing UI elements and controls.
- Updated event listeners to align with the new logic.
- Provided real-time updates to station information and peer count.
**Benefits of the New Method:**
- **Enhanced Audio Quality and Performance:**
- Leveraging WebRTC provides better audio streaming capabilities optimized for real-time communication.
- Reduced latency and improved synchronization.
- **Scalability and Reliability:**
- Proper handling of peer connections and media streams improves the application's scalability.
- Robust error handling ensures better reliability under various network conditions.
- **Improved User Experience:**
- Listeners experience uninterrupted audio even when broadcasters change input devices.
- Accurate peer count provides broadcasters with immediate feedback on their audience size.
**Testing and Verification:**
- Tested the application with multiple broadcasters and listeners to ensure proper functionality.
- Verified that audio streams initiate correctly and continue even after input device changes.
- Confirmed that peer counts update accurately on both broadcaster and listener sides.
- Ensured that no errors appear in the console logs during normal operation.
2024-11-24 02:29:16 -05:00
|
|
|
// Create offer
|
|
|
|
const offer = await peerConnection.createOffer();
|
|
|
|
await peerConnection.setLocalDescription(offer);
|
|
|
|
console.log("Created and set local description with offer");
|
|
|
|
|
|
|
|
// Send offer to broadcaster
|
|
|
|
conn.write(JSON.stringify({ type: 'offer', offer }));
|
|
|
|
console.log("Sent offer to broadcaster");
|
|
|
|
|
|
|
|
// Process any queued ICE candidates
|
|
|
|
if (iceCandidateQueues[remoteKey]) {
|
|
|
|
console.log("Processing queued ICE candidates");
|
|
|
|
for (const candidate of iceCandidateQueues[remoteKey]) {
|
|
|
|
await peerConnection.addIceCandidate(candidate);
|
|
|
|
console.log("Added queued ICE candidate");
|
|
|
|
}
|
|
|
|
iceCandidateQueues[remoteKey] = [];
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error initiating offer:", err);
|
|
|
|
}
|
2024-11-23 04:28:41 -05:00
|
|
|
}
|