mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-08-04 08:17:01 +00:00
Receivers: Added connect/disconenct notifications to player window
This commit is contained in:
parent
a7cd81aa34
commit
c54ce74dfd
11 changed files with 268 additions and 57 deletions
|
@ -1,5 +1,6 @@
|
|||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { Opcode } from 'common/Packets';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
|
@ -22,11 +23,13 @@ if (TARGET === 'electron') {
|
|||
})
|
||||
|
||||
electronAPI.contextBridge.exposeInMainWorld('targetAPI', {
|
||||
onDeviceInfo: (callback: any) => electronAPI.ipcRenderer.on("device-info", callback),
|
||||
onConnect: (callback: any) => electronAPI.ipcRenderer.on("connect", callback),
|
||||
onDisconnect: (callback: any) => electronAPI.ipcRenderer.on("disconnect", callback),
|
||||
onPing: (callback: any) => electronAPI.ipcRenderer.on("ping", callback),
|
||||
onDeviceInfo: (callback: any) => electronAPI.ipcRenderer.on('device-info', callback),
|
||||
getDeviceInfo: () => preloadData.deviceInfo,
|
||||
sendSessionMessage: (opcode: Opcode, message: any) => electronAPI.ipcRenderer.send('send-session-message', { opcode: opcode, message: message }),
|
||||
disconnectDevice: (session: string) => electronAPI.ipcRenderer.send('disconnect-device', session),
|
||||
onConnect: (callback: any) => electronAPI.ipcRenderer.on('connect', callback),
|
||||
onDisconnect: (callback: any) => electronAPI.ipcRenderer.on('disconnect', callback),
|
||||
onPing: (callback: any) => electronAPI.ipcRenderer.on('ping', callback),
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
import QRCode from 'modules/qrcode';
|
||||
import * as connectionMonitor from '../ConnectionMonitor';
|
||||
import { onQRCodeRendered } from 'src/main/Renderer';
|
||||
import { toast, ToastIcon } from '../components/Toast';
|
||||
|
||||
const connectionStatusText = document.getElementById('connection-status-text');
|
||||
const connectionStatusSpinner = document.getElementById('connection-spinner');
|
||||
const connectionStatusCheck = document.getElementById('connection-check');
|
||||
let connections = [];
|
||||
let renderedConnectionInfo = false;
|
||||
let renderedAddresses = null;
|
||||
let qrCodeUrl = null;
|
||||
|
@ -14,25 +14,15 @@ let qrWidth = null;
|
|||
|
||||
window.addEventListener('resize', (event) => calculateQRCodeWidth());
|
||||
|
||||
// Window might be re-created while devices are still connected
|
||||
window.targetAPI.onPing((_event, value: any) => {
|
||||
if (value && !connections.includes(value.id)) {
|
||||
connections.push(value.id);
|
||||
onConnect(value.id);
|
||||
}
|
||||
});
|
||||
|
||||
window.targetAPI.onDeviceInfo(renderIPsAndQRCode);
|
||||
window.targetAPI.onConnect((_event, value: any) => {
|
||||
connections.push(value.id);
|
||||
onConnect(value);
|
||||
});
|
||||
window.targetAPI.onDisconnect((_event, value: any) => {
|
||||
console.log(`Device disconnected: ${JSON.stringify(value)}`);
|
||||
const index = connections.indexOf(value.id);
|
||||
if (index != -1) {
|
||||
connections.splice(index, 1);
|
||||
|
||||
connectionMonitor.setUiUpdateCallbacks({
|
||||
onConnect: (connections: string[], connectionInfo: any) => {
|
||||
console.log(`Device connected: ${JSON.stringify(connectionInfo)}`);
|
||||
connectionStatusText.textContent = connections.length > 1 ? 'Multiple devices connected:\r\n Ready to cast' : 'Connected: Ready to cast';
|
||||
connectionStatusSpinner.style.display = 'none';
|
||||
connectionStatusCheck.style.display = 'inline-block';
|
||||
},
|
||||
onDisconnect: (connections: string[], connectionInfo: any) => {
|
||||
console.log(`Device disconnected: ${JSON.stringify(connectionInfo)}`);
|
||||
if (connections.length === 0) {
|
||||
connectionStatusText.textContent = 'Waiting for a connection';
|
||||
connectionStatusSpinner.style.display = 'inline-block';
|
||||
|
@ -43,21 +33,16 @@ window.targetAPI.onDisconnect((_event, value: any) => {
|
|||
connectionStatusText.textContent = connections.length > 1 ? 'Multiple devices connected:\r\n Ready to cast' : 'Connected: Ready to cast';
|
||||
toast('A device has disconnected', ToastIcon.INFO);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
window.targetAPI.onDeviceInfo(renderIPsAndQRCode);
|
||||
|
||||
if(window.targetAPI.getDeviceInfo()) {
|
||||
console.log('device info already present');
|
||||
renderIPsAndQRCode();
|
||||
}
|
||||
|
||||
function onConnect(value: any) {
|
||||
console.log(`Device connected: ${JSON.stringify(value)}`);
|
||||
connectionStatusText.textContent = connections.length > 1 ? 'Multiple devices connected:\r\n Ready to cast' : 'Connected: Ready to cast';
|
||||
connectionStatusSpinner.style.display = 'none';
|
||||
connectionStatusCheck.style.display = 'inline-block';
|
||||
}
|
||||
|
||||
function renderIPsAndQRCode() {
|
||||
const value = window.targetAPI.getDeviceInfo();
|
||||
console.log(`Network Interface Info: ${value}`);
|
||||
|
|
|
@ -293,6 +293,7 @@ body, html {
|
|||
position: relative;
|
||||
top: -200px;
|
||||
max-width: 70%;
|
||||
width: fit-content;
|
||||
|
||||
background: #F0F0F0;
|
||||
border: 3px solid rgba(0, 0, 0, 0.08);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue