Skip to content

Commit

Permalink
Fix cs
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelWei committed Dec 3, 2024
1 parent 86df51b commit 5e8da44
Show file tree
Hide file tree
Showing 22 changed files with 5,237 additions and 352 deletions.
16 changes: 8 additions & 8 deletions appliance-application/.electron-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = async function () {
output: 'dist',
buildResources: 'buildResources',
},
files: ['packages/**/dist/**', "packages/**/assets/**"],
files: ['packages/**/dist/**', 'packages/**/assets/**'],
extraMetadata: {
version: getVersion(),
},
Expand All @@ -27,22 +27,22 @@ module.exports = async function () {

// Specify linux target just for disabling snap compilation
linux: {
target: ['deb','rpm']
target: ['deb', 'rpm'],
},
win: {
target: ['portable']
target: ['portable'],
},
deb: {
afterInstall:"linux/after-install.tpl",
afterInstall: 'linux/after-install.tpl',
},
rpm: {
afterInstall:"linux/after-install.tpl",
afterInstall: 'linux/after-install.tpl',
},

publish: [
{
provider: "github"
}
]
provider: 'github',
},
],
};
};
1 change: 0 additions & 1 deletion appliance-application/packages/main/src/HID.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export interface HID {

newOffer(accept: () => void, reject: () => void): void;

acceptedOffer(): void;
Expand Down
39 changes: 18 additions & 21 deletions appliance-application/packages/main/src/bbb-graphql.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import {createClient} from 'graphql-ws';
import WebSocket from 'ws'
import WebSocket from 'ws';
import {
ApolloClient,
InMemoryCache,
Expand All @@ -25,11 +25,11 @@ export class BBBGraphql {
private apolloClient: ApolloClient<NormalizedCacheObject> | undefined;
private userId: string | null = null;

constructor (joinUrl: string) {
constructor(joinUrl: string) {
this.joinUrl = joinUrl;
}

public async connect () {
public async connect() {
if (!(await this.requestSessionToken())) {
console.error('Failed to request session token.');
return false;
Expand All @@ -53,7 +53,7 @@ export class BBBGraphql {
return true;
}

private async requestSessionToken (): Promise<boolean> {
private async requestSessionToken(): Promise<boolean> {
try {
console.debug('Join link used:', this.joinUrl);
const joinUrl = new URL(this.joinUrl);
Expand Down Expand Up @@ -87,9 +87,8 @@ export class BBBGraphql {
return false;
}

private async getAuthToken(): Promise<boolean> {

if (!(this?.apolloClient)) {
private async getAuthToken(): Promise<boolean> {
if (!this?.apolloClient) {
return false;
}
const USER_CURRENT_QUERY = gql`
Expand All @@ -100,12 +99,10 @@ export class BBBGraphql {
}
`;

const { data } = await this.apolloClient.query(
{
query: USER_CURRENT_QUERY,
fetchPolicy: 'network-only',
}
);
const {data} = await this.apolloClient.query({
query: USER_CURRENT_QUERY,
fetchPolicy: 'network-only',
});

if (data && data?.user_current?.[0]?.authToken) {
console.log('IN getAuthToken: ', data);
Expand All @@ -116,7 +113,7 @@ export class BBBGraphql {
return false;
}

public async connectToGraphQL () {
public async connectToGraphQL() {
await this.initApolloClient();

console.debug('--- Connecting to GraphQL... ---');
Expand All @@ -136,7 +133,7 @@ export class BBBGraphql {
return false;
}

if (!(this?.apolloClient)) {
if (!this?.apolloClient) {
console.error('apolloClient is not set.');
return false;
}
Expand Down Expand Up @@ -165,7 +162,7 @@ export class BBBGraphql {
return true;
}

private async initApolloClient (): Promise<boolean> {
private async initApolloClient(): Promise<boolean> {
let wsLink;
try {
// Check if cookies are not null before attempting to find a cookie
Expand All @@ -181,7 +178,7 @@ export class BBBGraphql {

// You need to override the WebSocket class to add the cookie
class WebSocketWithCookie extends WebSocket {
constructor (address: string, protocols?: string | string[]) {
constructor(address: string, protocols?: string | string[]) {
super(address, protocols, {
headers: {
Cookie: jSessionCookie,
Expand Down Expand Up @@ -251,18 +248,18 @@ export class BBBGraphql {
return true;
}

public getApolloClient () {
public getApolloClient() {
return this.apolloClient;
}

public getUserId () {
public getUserId() {
return this.userId;
}

public async leaveMeeting () {
public async leaveMeeting() {
if (this?.apolloClient) {
await this.apolloClient.clearStore();
this.apolloClient.stop();
}
}
}
}
58 changes: 26 additions & 32 deletions appliance-application/packages/main/src/bbb-meeting.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { BrowserWindow} from 'electron';
import {BrowserWindow} from 'electron';
import {app, screen} from 'electron';
import Display = Electron.Display;
import type {ApolloClient, NormalizedCacheObject} from '@apollo/client/core';
import { gql } from '@apollo/client/core';
import {gql} from '@apollo/client/core';
import {BBBGraphql} from '/@/bbb-graphql';
import {DisplayManager} from "/@/displayManager";

export class BBBMeeting{
import {DisplayManager} from '/@/displayManager';

export class BBBMeeting {
private screens;

private displayManager: DisplayManager;
Expand All @@ -18,7 +17,6 @@ export class BBBMeeting{
private user_id: any;
private bbbGraphQl: BBBGraphql;


constructor(control, screens, displayManager) {
this.screens = screens;
this.control = control;
Expand All @@ -32,58 +30,58 @@ export class BBBMeeting{
this.openScreens();

this.bbbGraphQl = new BBBGraphql(this.control);
if(await this.bbbGraphQl.connect()){
if (await this.bbbGraphQl.connect()) {
console.log('connected to graphql');

this.user_id = this.bbbGraphQl.getUserId();
this.apolloClient = this.bbbGraphQl.getApolloClient();


this.onUsersLeft(async () => {
console.log('all users left');
await this.leave();
leftCallback();
});

return true;

}

return false;
}

private onUsersLeft(callback) {
const USER_COUNT = gql`subscription($userId: String) {
user_aggregate(where: {extId: {_nlike: $userId}}) {
aggregate {
count
const USER_COUNT = gql`
subscription ($userId: String) {
user_aggregate(where: {extId: {_nlike: $userId}}) {
aggregate {
count
}
}
}
}`;

this.apolloClient.subscribe({
query: USER_COUNT,
variables: {
userId: this.user_id+'%',
},
})
`;

this.apolloClient
.subscribe({
query: USER_COUNT,
variables: {
userId: this.user_id + '%',
},
})
.subscribe({
next(data) {
const userCount = data.data.user_aggregate.aggregate.count;

console.log('userCount', userCount);
if(userCount == 0) {
if (userCount == 0) {
callback();
}
},
error(err) { console.error('err', err); },
error(err) {
console.error('err', err);
},
});
}

private openScreens() {



for (const [screen, url] of Object.entries(this.screens)) {
const screenDisplay = this.displayManager.getDisplay(screen);

Expand All @@ -106,29 +104,25 @@ export class BBBMeeting{
webPreferences: {
partition: partition,
contextIsolation: true,

},
});


this.windows.push(screenWindows);

screenWindows.loadURL(url);

//screenWindows.webContents.openDevTools();


}
}

private closeScreens() {
this.windows.forEach((window) => {
this.windows.forEach(window => {
window.close();
window.destroy();
});
}

public async leave(){
public async leave() {
this.closeScreens();
await this.bbbGraphQl.leaveMeeting();
}
Expand Down
10 changes: 3 additions & 7 deletions appliance-application/packages/main/src/displayManager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Display = Electron.Display;
import { screen } from 'electron';

export class DisplayManager{
import {screen} from 'electron';

export class DisplayManager {
private displays: Display[];

constructor() {
Expand All @@ -13,10 +12,7 @@ export class DisplayManager{
return this.displays;
}

public getDisplay(label: string): Display | null{
public getDisplay(label: string): Display | null {
return this.displays.find(display => display.label === label) || null;
}



}
18 changes: 7 additions & 11 deletions appliance-application/packages/main/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {app} from 'electron';
import './security-restrictions';
import {restoreOrCreateWindow, hdiDevices } from '/@/mainWindow';
import {restoreOrCreateWindow, hdiDevices} from '/@/mainWindow';
import {listStreamDecks, openStreamDeck} from '@elgato-stream-deck/node';
import {StreamDeckHID} from '/@/streamdeck';
import { autoUpdater } from "electron-updater";
import {autoUpdater} from 'electron-updater';

/**
* Prevent electron from running multiple instances.
Expand All @@ -27,11 +27,11 @@ app.on('window-all-closed', () => {
let isQuitting = false;

app.on('before-quit', async (event: Event): Promise<void> => {
if(!isQuitting) {
if (!isQuitting) {
event.preventDefault();
isQuitting = true;

const promises = hdiDevices.map((device) => {
const promises = hdiDevices.map(device => {
return device.close();
});

Expand All @@ -58,24 +58,20 @@ app
try {
const allStreamDeckDevices = await listStreamDecks();

const streamDecks = allStreamDeckDevices.map((device) => {
const streamDecks = allStreamDeckDevices.map(device => {
return openStreamDeck(device.path, {resetToLogoOnClose: true});
});

(await Promise.all(streamDecks)).forEach((streamDeck) => {
console.debug('Stream Deck found: '+streamDeck.PRODUCT_NAME);
(await Promise.all(streamDecks)).forEach(streamDeck => {
console.debug('Stream Deck found: ' + streamDeck.PRODUCT_NAME);
hdiDevices.push(new StreamDeckHID(streamDeck));
});

} catch (e) {
console.error(e);
}


})
.catch(e => console.error('Failed create window:', e));


/**
* Check for app updates, install it in background and notify user that new version was installed.
* No reason run this in non-production build.
Expand Down
Loading

0 comments on commit 5e8da44

Please sign in to comment.