refactor(iron-remote-desktop): use PartialObserver instead of single callback for onSessionEvent (#787)

This commit is contained in:
Alex Yusiuk 2025-05-09 12:13:39 +03:00 committed by GitHub
parent ce7379be03
commit 0817d60910
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 29 deletions

View file

@ -3,6 +3,7 @@ import type { NewSessionInfo } from './NewSessionInfo';
import type { SessionEvent } from './session-event';
import { ConfigBuilder } from '../services/ConfigBuilder';
import type { Config } from '../services/Config';
import type { PartialObserver } from 'rxjs';
export interface UserInteraction {
setVisibility(state: boolean): void;
@ -23,7 +24,7 @@ export interface UserInteraction {
setCursorStyleOverride(style: string | null): void;
onSessionEvent(callback: (event: SessionEvent) => void): void;
onSessionEvent(partialObserver: PartialObserver<SessionEvent>): void;
resize(width: number, height: number, scale?: number): void;

View file

@ -68,8 +68,8 @@ export class PublicAPI {
configBuilder: this.configBuilder.bind(this),
connect: this.connect.bind(this),
setScale: this.setScale.bind(this),
onSessionEvent: (callback) => {
this.remoteDesktopService.sessionObserver.subscribe(callback);
onSessionEvent: (partialObserver) => {
this.remoteDesktopService.sessionObserver.subscribe(partialObserver);
},
ctrlAltDel: this.ctrlAltDel.bind(this),
metaKey: this.metaKey.bind(this),

View file

@ -30,20 +30,22 @@
});
const initListeners = () => {
userInteraction.onSessionEvent((event) => {
if (event.type === 2) {
console.log('Error event', event.data);
userInteraction.onSessionEvent({
next: (event) => {
if (event.type === 2) {
console.log('Error event', event.data);
toast.set({
type: 'error',
message: typeof event.data !== 'string' ? event.data.backtrace() : event.data,
});
} else {
toast.set({
type: 'info',
message: typeof event.data === 'string' ? event.data : event.data?.backtrace() ?? 'No info',
});
}
toast.set({
type: 'error',
message: typeof event.data !== 'string' ? event.data.backtrace() : event.data,
});
} else {
toast.set({
type: 'info',
message: typeof event.data === 'string' ? event.data : event.data?.backtrace() ?? 'No info',
});
}
},
});
};

View file

@ -12,12 +12,14 @@
userInteractionService.subscribe((val) => {
if (val != null) {
userInteraction = val;
userInteraction.onSessionEvent((event) => {
if (event.type === 0) {
userInteraction.setVisibility(true);
} else if (event.type === 1) {
setCurrentSessionActive(false);
}
userInteraction.onSessionEvent({
next: (event) => {
if (event.type === 0) {
userInteraction.setVisibility(true);
} else if (event.type === 1) {
setCurrentSessionActive(false);
}
},
});
}
});

View file

@ -12,13 +12,15 @@
userInteractionService.subscribe((uis) => {
if (uis != null) {
uiService = uis;
uiService.onSessionEvent((event) => {
if (event.type === 0) {
uiService.setVisibility(true);
} else if (event.type === 1) {
setCurrentSessionActive(false);
showLogin.set(true);
}
uiService.onSessionEvent({
next: (event) => {
if (event.type === 0) {
uiService.setVisibility(true);
} else if (event.type === 1) {
setCurrentSessionActive(false);
showLogin.set(true);
}
},
});
}
});