mirror of
https://github.com/Devolutions/IronRDP.git
synced 2025-08-04 15:18:17 +00:00
refactor(iron-remote-desktop): use PartialObserver
instead of single callback for onSessionEvent
(#787)
This commit is contained in:
parent
ce7379be03
commit
0817d60910
5 changed files with 36 additions and 29 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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',
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue