Skip to content

Commit

Permalink
Add connection relayed/p2p indicator.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Mar 9, 2020
1 parent ac52bd5 commit 3ede7a0
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 5 deletions.
37 changes: 37 additions & 0 deletions Server/Pages/RemoteControl.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@page
@using Remotely.Shared.Models
@inject Remotely.Server.Services.ApplicationConfig AppConfig
@inject UserManager<RemotelyUser> UserManager
@model Remotely.Server.Pages.RemoteControlModel
@{
Layout = null;
Expand All @@ -26,6 +28,35 @@
{
<link href="~/css/remote-control-dark.css" rel="stylesheet" asp-append-version="true" />
}

@if (User.Identity.IsAuthenticated)
{
var user = await UserManager.GetUserAsync(User);
switch (user.UserOptions.Theme)
{
case Remotely.Shared.Enums.Theme.Light:
<link href="~/css/remote-control-light.css" rel="stylesheet" asp-append-version="true" />
break;
case Remotely.Shared.Enums.Theme.Dark:
<link href="~/css/remote-control-dark.css" rel="stylesheet" asp-append-version="true" />
break;
default:
break;
}
}
else
{
if (AppConfig.Theme.ToLower() == "light")
{
<link href="~/css/remote-control-light.css" rel="stylesheet" asp-append-version="true" />
}
else
{
<link href="~/css/remote-control-dark.css" rel="stylesheet" asp-append-version="true" />
}
}


<link href="~/lib/fontawesome/css/all.min.css" rel="stylesheet" />

<environment include="Development">
Expand Down Expand Up @@ -83,6 +114,12 @@
<button id="qualityButton" class="option-button">Quality <i class="far fa-image"></i></button>
</div>

<div style="margin-top:5px;">
<span>Connection: </span>
<i id="connectionRelayedIcon" class="fas fa-wifi connection-icon" title="Connection is relayed"></i>
<i id="connectionP2PIcon" class="fas fa-wifi connection-icon" title="Connection is peer-to-peer" style="display:none"></i>
</div>

</div>

<div id="screenSelectBar" class="horizontal-button-bar">
Expand Down
12 changes: 12 additions & 0 deletions Server/wwwroot/css/remote-control-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,15 @@ footer a {
position: fixed;
top: -100%;
}

.connection-icon {
padding: 5px;
}

#connectionRelayedIcon {
background-color: orange;
}

#connectionP2PIcon {
background-color: green;
}
13 changes: 12 additions & 1 deletion Server/wwwroot/css/remote-control-light.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

button {
cursor: pointer;
/*background-color: #008cba;*/
background-color: #017ea7;
color: white;
border-radius: 5px;
Expand Down Expand Up @@ -292,3 +291,15 @@ footer a {
position: fixed;
top: -100%;
}

.connection-icon {
padding: 5px;
}

#connectionRelayedIcon {
background-color: orange;
}

#connectionP2PIcon {
background-color: green;
}
16 changes: 15 additions & 1 deletion Server/wwwroot/scripts/RemoteControl/RtcSession.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/wwwroot/scripts/RemoteControl/RtcSession.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion Server/wwwroot/scripts/RemoteControl/RtcSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ export class RtcSession {
};
this.DataChannel.onclose = (ev) => {
console.log("Data channel closed.");
UI.ConnectionP2PIcon.style.display = "none";
UI.ConnectionRelayedIcon.style.display = "unset";
};
this.DataChannel.onerror = (ev) => {
console.log("Data channel error.", ev.error);
UI.ConnectionP2PIcon.style.display = "none";
UI.ConnectionRelayedIcon.style.display = "unset";
};
this.DataChannel.onmessage = async (ev) => {
var data = ev.data as ArrayBuffer;
Expand All @@ -38,14 +42,24 @@ export class RtcSession {
};
this.DataChannel.onopen = (ev) => {
console.log("Data channel opened.");
UI.ConnectionP2PIcon.style.display = "unset";
UI.ConnectionRelayedIcon.style.display = "none";
};
};
this.PeerConnection.onconnectionstatechange = function (ev) {
console.log("Connection state changed to " + this.connectionState);
if (this.connectionState != "connected") {
UI.ConnectionP2PIcon.style.display = "none";
UI.ConnectionRelayedIcon.style.display = "unset";
}
}

this.PeerConnection.oniceconnectionstatechange = function (ev) {
console.log("Connection state changed to " + this.iceConnectionState);
console.log("ICE connection state changed to " + this.iceConnectionState);
if (this.iceConnectionState != "connected") {
UI.ConnectionP2PIcon.style.display = "none";
UI.ConnectionRelayedIcon.style.display = "unset";
}
}
this.PeerConnection.onicecandidate = async (ev) => {
await Remotely.RCBrowserSockets.SendIceCandidate(ev.candidate);
Expand Down
2 changes: 2 additions & 0 deletions Server/wwwroot/scripts/RemoteControl/UI.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/wwwroot/scripts/RemoteControl/UI.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Server/wwwroot/scripts/RemoteControl/UI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export var ClipboardTransferBar = document.getElementById("clipboardTransferBar"
export var ClipboardTransferTextArea = document.getElementById("clipboardTransferTextArea") as HTMLTextAreaElement;
export var ClipboardTransferButton = document.getElementById("clipboardTransferButton") as HTMLButtonElement;
export var ClipboardTransferTypeCheckbox = document.getElementById("clipboardTransferTypeCheckbox") as HTMLInputElement;
export var ConnectionP2PIcon = document.getElementById("connectionP2PIcon") as HTMLElement;
export var ConnectionRelayedIcon = document.getElementById("connectionRelayedIcon") as HTMLElement;

var lastPointerMove = Date.now();
var isDragging: boolean;
Expand Down

0 comments on commit 3ede7a0

Please sign in to comment.