Display local IP addresses
This commit is contained in:
parent
d50dd127ba
commit
a42f5a2e87
@ -32,6 +32,7 @@ uuid = {version = "0.8", features = ["v4"]}
|
||||
webbrowser = "0.5.5"
|
||||
libmdns = "0.6" #mDNS advertiser
|
||||
multicast_dns = "0.5" #mDNS browser
|
||||
pnet_datalink = "0.27.2"
|
||||
base64 = "0.13.0"
|
||||
time = "0.2.25"
|
||||
scrypt = "0.7.0"
|
||||
|
1
src/frontend/imgs/icons/info.svg
Normal file
1
src/frontend/imgs/icons/info.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#FILL_COLOR"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg>
|
After Width: | Height: | Size: 233 B |
@ -224,21 +224,35 @@ input[type="file"] {
|
||||
background-color: var(--accent);
|
||||
border-radius: 12px;
|
||||
}
|
||||
#refresher {
|
||||
position: relative;
|
||||
}
|
||||
#refresher button {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: 15px;
|
||||
z-index: 1;
|
||||
}
|
||||
#refresher button::after {
|
||||
content: url("/static/imgs/icons/refresh");
|
||||
}
|
||||
#connect_box {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
#refresher, #connect_box>div {
|
||||
position: relative;
|
||||
}
|
||||
#show_local_ips, #refresher button {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: 15px;
|
||||
z-index: 1;
|
||||
}
|
||||
#show_local_ips::after {
|
||||
content: url("/static/imgs/icons/info/52585C");
|
||||
background-color: unset;
|
||||
padding: unset;
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
}
|
||||
#show_local_ips:hover::after {
|
||||
background-color: unset;
|
||||
content: url("/static/imgs/icons/info/FF3C00");
|
||||
}
|
||||
ul.ips {
|
||||
list-style-type: unset;
|
||||
}
|
||||
#chat_header {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
@ -23,6 +23,9 @@
|
||||
<ul id="offline_sessions">
|
||||
</ul>
|
||||
<div id="connect_box">
|
||||
<div>
|
||||
<button id="show_local_ips" title="Local IP addresses"></button>
|
||||
</div>
|
||||
<p class="section_title">Add a new peer by IP:</p>
|
||||
<input type="text" id="ip_input" placeholder="Enter IP address">
|
||||
</div>
|
||||
|
@ -3,6 +3,7 @@
|
||||
let identityName = undefined;
|
||||
let socket = null;
|
||||
let notificationAllowed = false;
|
||||
let localIps = [];
|
||||
let currentSessionId = -1;
|
||||
let sessionsData = new Map();
|
||||
let msgHistory = new Map();
|
||||
@ -30,6 +31,21 @@ ip_input.addEventListener("keyup", function(event) {
|
||||
ip_input.value = "";
|
||||
}
|
||||
});
|
||||
document.getElementById("show_local_ips").onclick = function() {
|
||||
let mainDiv = document.createElement("div");
|
||||
let h2Title = document.createElement("h2");
|
||||
h2Title.textContent = "Your IP addresses:";
|
||||
mainDiv.appendChild(h2Title);
|
||||
let ul = document.createElement("ul");
|
||||
ul.classList.add("ips");
|
||||
for (let i=0; i<localIps.length; ++i) {
|
||||
let li = document.createElement("li");
|
||||
li.textContent = localIps[i];
|
||||
ul.appendChild(li);
|
||||
}
|
||||
mainDiv.appendChild(ul);
|
||||
showPopup(mainDiv);
|
||||
}
|
||||
let message_input = document.getElementById("message_input");
|
||||
message_input.addEventListener("keyup", function(event) {
|
||||
if (event.key === "Enter") {
|
||||
@ -428,6 +444,9 @@ socket.onmessage = function(msg) {
|
||||
case "not_seen":
|
||||
setNotSeen(msg.data.slice(args[0].length+1));
|
||||
break;
|
||||
case "local_ips":
|
||||
setLocalIps(msg.data.slice(args[0].length+1));
|
||||
break;
|
||||
case "set_name":
|
||||
onNameSet(msg.data.slice(args[0].length+1));
|
||||
break;
|
||||
@ -465,12 +484,15 @@ function onNameTold(sessionId, name) {
|
||||
displaySessions();
|
||||
}
|
||||
function setNotSeen(str_sessionIds) {
|
||||
let sessionIds = str_sessionIds.split(" ");
|
||||
let sessionIds = str_sessionIds.split(' ');
|
||||
for (let i=0; i<sessionIds.length; ++i) {
|
||||
sessionsData.get(sessionIds[i]).seen = false;
|
||||
}
|
||||
displaySessions();
|
||||
}
|
||||
function setLocalIps(str_ips) {
|
||||
localIps = str_ips.split(' ');
|
||||
}
|
||||
function onIsContact(sessionId, verified, fingerprint, name) {
|
||||
if (sessionsData.has(sessionId)) {
|
||||
let session = sessionsData.get(sessionId);
|
||||
|
10
src/main.rs
10
src/main.rs
@ -116,6 +116,15 @@ async fn websocket_worker(mut ui_connection: UiConnection, global_vars: Arc<RwLo
|
||||
session_manager.get_saved_msgs().into_iter().for_each(|msgs| {
|
||||
ui_connection.load_msgs(&msgs.0, &msgs.1);
|
||||
});
|
||||
let mut ips = Vec::new();
|
||||
for interface in pnet_datalink::interfaces() {
|
||||
if !interface.is_loopback() {
|
||||
for ip in interface.ips {
|
||||
ips.push(ip.ip());
|
||||
}
|
||||
}
|
||||
}
|
||||
ui_connection.set_local_ips(ips);
|
||||
discover_peers(session_manager.clone());
|
||||
let handle = Handle::current();
|
||||
std::thread::spawn(move || { //new thread needed to block on read_message() without blocking tokio tasks
|
||||
@ -549,6 +558,7 @@ fn handle_static(req: HttpRequest) -> HttpResponse {
|
||||
"download" => Some(include_str!("frontend/imgs/icons/download.svg")),
|
||||
"cancel" => Some(include_str!("frontend/imgs/icons/cancel.svg")),
|
||||
"refresh" => Some(include_str!("frontend/imgs/icons/refresh.svg")),
|
||||
"info" => Some(include_str!("frontend/imgs/icons/info.svg")),
|
||||
"delete_conversation" => Some(include_str!("frontend/imgs/icons/delete_conversation.svg")),
|
||||
_ => None
|
||||
} {
|
||||
|
@ -3,7 +3,7 @@ use tungstenite::{WebSocket, protocol::Role, Message};
|
||||
use crate::{protocol, session_manager::LargeFileDownload};
|
||||
|
||||
mod ui_messages {
|
||||
use std::{iter::FromIterator, net::IpAddr, str::from_utf8};
|
||||
use std::{fmt::Display, iter::FromIterator, net::IpAddr, str::from_utf8};
|
||||
use tungstenite::Message;
|
||||
use uuid::Uuid;
|
||||
use crate::{print_error, session_manager::{protocol, LargeFileDownload, FileState}, utils::to_uuid_bytes};
|
||||
@ -11,17 +11,22 @@ mod ui_messages {
|
||||
const ON_NEW_MESSAGE: &str = "new_message";
|
||||
const LOAD_SENT_MESSAGE: &str = "load_sent_msg";
|
||||
|
||||
fn new_message(verb: &str, session_id: &usize, outgoing: bool, raw_message: &[u8]) -> Option<Message> {
|
||||
fn new_message(command: &str, session_id: &usize, outgoing: bool, raw_message: &[u8]) -> Option<Message> {
|
||||
match from_utf8(raw_message) {
|
||||
Ok(msg) => Some(Message::from(format!("{} {} {} {}", verb, session_id, outgoing, msg))),
|
||||
Ok(msg) => Some(Message::from(format!("{} {} {} {}", command, session_id, outgoing, msg))),
|
||||
Err(e) => {
|
||||
print_error!(e);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
fn simple_event(verb: &str, session_id: &usize) -> Message {
|
||||
Message::from(format!("{} {}", verb, session_id))
|
||||
fn simple_event(command: &str, session_id: &usize) -> Message {
|
||||
Message::from(format!("{} {}", command, session_id))
|
||||
}
|
||||
fn data_list<T: Display>(command: &str, data: Vec<T>) -> Message {
|
||||
Message::from(command.to_owned()+&String::from_iter(data.into_iter().map(|i| {
|
||||
format!(" {}", i)
|
||||
})))
|
||||
}
|
||||
|
||||
pub fn on_disconnected(session_id: &usize) -> Message {
|
||||
@ -91,9 +96,10 @@ mod ui_messages {
|
||||
}
|
||||
}
|
||||
pub fn set_not_seen(session_ids: Vec<usize>) -> Message {
|
||||
Message::from("not_seen".to_owned()+&String::from_iter(session_ids.into_iter().map(|session_id| {
|
||||
format!(" {}", session_id)
|
||||
})))
|
||||
data_list("not_seen", session_ids)
|
||||
}
|
||||
pub fn set_local_ips(ips: Vec<IpAddr>) -> Message {
|
||||
data_list("local_ips", ips)
|
||||
}
|
||||
pub fn on_name_told(session_id: &usize, name: &str) -> Message {
|
||||
Message::from(format!("name_told {} {}", session_id, name))
|
||||
@ -183,6 +189,9 @@ impl UiConnection {
|
||||
pub fn set_not_seen(&mut self, session_ids: Vec<usize>) {
|
||||
self.write_message(ui_messages::set_not_seen(session_ids));
|
||||
}
|
||||
pub fn set_local_ips(&mut self, ips: Vec<IpAddr>) {
|
||||
self.write_message(ui_messages::set_local_ips(ips));
|
||||
}
|
||||
pub fn set_name(&mut self, new_name: &str) {
|
||||
self.write_message(ui_messages::set_name(new_name));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user