Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the Repl.it Audio messages #3

Merged
merged 2 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions app/images/audio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 44 additions & 2 deletions app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ const UI = {
document.getElementById("noVNC_view_drag_button")
.addEventListener('click', UI.toggleViewDrag);

document.getElementById("noVNC_audio_button")
.addEventListener('click', UI.toggleEnableAudio);

document.getElementById("noVNC_control_bar_handle")
.addEventListener('mousedown', UI.controlbarHandleMouseDown);
document.getElementById("noVNC_control_bar_handle")
Expand Down Expand Up @@ -438,7 +441,7 @@ const UI = {
UI.enableSetting('port');
UI.enableSetting('path');
UI.enableSetting('repeaterID');
UI.updatePowerButton();
UI.updateCapabilities();
UI.keepControlbar();
}

Expand Down Expand Up @@ -869,6 +872,24 @@ const UI = {
}
},

updateCapabilities() {
UI.updatePowerButton();
UI.updateAudioButton();
},

updateAudioButton() {
if (UI.connected &&
UI.rfb.capabilities.audio) {
document.getElementById('noVNC_audio_button')
.classList.remove("noVNC_hidden");
document.getElementById('noVNC_audio_button')
.classList.remove("noVNC_selected");
Copy link
Member

Choose a reason for hiding this comment

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

How often is updateCapabilities called? Should we always remove this selected class?

Copy link
Author

@lhchavez lhchavez Apr 6, 2021

Choose a reason for hiding this comment

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

at most four times per connection: once after the connection is established (to clear everything), once when the power capabilities are advertised by the server, once when the server says that it supports audio (only once if the user opted in), and once more when the connection is lost (to clean everything again for good measure).

it should be roughly fine to always attempt to remove the selected class since classList.remove() is a no-op if the class is not there, and other UI functions follow roughly the same pattern (like updatePowerButton(), another funciton that's called from updateCapabilities()).

which is a very long way of saying i guess it's fine?

Copy link
Member

Choose a reason for hiding this comment

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

if they do this elsewhere, sounds good to me haha!

} else {
document.getElementById('noVNC_audio_button')
.classList.add("noVNC_hidden");
}
},

/* ------^-------
* /SETTINGS
* ==============
Expand Down Expand Up @@ -1032,7 +1053,7 @@ const UI = {
UI.rfb.addEventListener("disconnect", UI.disconnectFinished);
UI.rfb.addEventListener("credentialsrequired", UI.credentials);
UI.rfb.addEventListener("securityfailure", UI.securityFailed);
UI.rfb.addEventListener("capabilities", UI.updatePowerButton);
UI.rfb.addEventListener("capabilities", UI.updateCapabilities);
UI.rfb.addEventListener("clipboard", UI.clipboardReceive);
UI.rfb.addEventListener("bell", UI.bell);
UI.rfb.addEventListener("desktopname", UI.updateDesktopName);
Expand Down Expand Up @@ -1647,6 +1668,27 @@ const UI = {
}
},

toggleEnableAudio() {
if (!UI.rfb) return;

if (!document.getElementById('noVNC_audio_button')
.classList.contains("noVNC_selected")) {
UI.rfb.enableAudio(
2,
MediaSource.isTypeSupported('audio/webm;codecs=opus') ?
RFB.audioCodecs.OpusWebM :
RFB.audioCodecs.MP3,
32 * 1024 // 32kbps
);
document.getElementById('noVNC_audio_button')
.classList.add("noVNC_selected");
} else {
UI.rfb.disableAudio();
document.getElementById('noVNC_audio_button')
.classList.remove("noVNC_selected");
}
},

updateShowDotCursor() {
if (!UI.rfb) return;
UI.rfb.showDotCursor = UI.getSetting('show_dot');
Expand Down
1 change: 1 addition & 0 deletions core/encodings.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const encodings = {
pseudoEncodingContinuousUpdates: -313,
pseudoEncodingCompressLevel9: -247,
pseudoEncodingCompressLevel0: -256,
pseudoEncodingReplitAudio: 0x52706c41,
pseudoEncodingVMwareCursor: 0x574d5664,
pseudoEncodingExtendedClipboard: 0xc0a1e5ce
};
Expand Down
Loading