Skip to content

Commit

Permalink
fix channel connected - we dont have type messages in this code
Browse files Browse the repository at this point in the history
  • Loading branch information
willwade committed Oct 31, 2024
1 parent 010ab44 commit 593d894
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nodejs/sender-monitor/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async function captureAndProcessScreen() {
function processAndSendText(text) {
if (text && text !== lastText && isConnected && webrtc.isChannelOpen()) {
webrtc.sendMessage(JSON.stringify({
type: messageTypes.MESSAGE,
type: "MESSAGE",
content: text,
}));
lastText = text;
Expand Down
6 changes: 5 additions & 1 deletion nodejs/sender-monitor/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class WebRTCConnection extends EventEmitter {
this.dataChannels[peerId] = dataChannel;

dataChannel.onopen = () => {
this.emit("connected"); // Emit connected event when data channel is open
this.emit("connected");
const channelConnectedMessage = JSON.stringify({ type: "CHANNEL_CONNECTED" });
dataChannel.send(channelConnectedMessage);
console.log("Sent CHANNEL_CONNECTED message to display.");
Expand Down Expand Up @@ -109,6 +109,10 @@ class WebRTCConnection extends EventEmitter {
});
}

isChannelOpen() {
return Object.values(this.dataChannels).some(channel => channel.readyState === "open");
}

closeConnection() {
Object.values(this.peerConnections).forEach((peerConnection) => {
peerConnection.close();
Expand Down

0 comments on commit 593d894

Please sign in to comment.