@@ -11,7 +11,12 @@ import {
11
11
viewChild ,
12
12
input ,
13
13
output ,
14
- EventEmitter
14
+ EventEmitter ,
15
+ inject ,
16
+ Renderer2 ,
17
+ computed ,
18
+ model ,
19
+ effect
15
20
} from '@angular/core'
16
21
import {
17
22
AMTDesktop ,
@@ -32,9 +37,11 @@ import { throttleTime } from 'rxjs/operators'
32
37
styleUrls : [ './kvm.component.css' ]
33
38
} )
34
39
export class KVMComponent implements OnInit , AfterViewInit , OnDestroy {
40
+ renderer = inject ( Renderer2 )
35
41
readonly canvas = viewChild < ElementRef > ( 'canvas' )
36
42
readonly device = viewChild . required < string > ( 'device' )
37
43
public context ! : CanvasRenderingContext2D
44
+ public isFullscreen = input ( false )
38
45
39
46
//setting a width and height for the canvas
40
47
@@ -45,8 +52,9 @@ export class KVMComponent implements OnInit, AfterViewInit, OnDestroy {
45
52
public deviceId = input ( '' )
46
53
47
54
readonly deviceStatus = output < number > ( )
48
- readonly deviceConnection = input < EventEmitter < boolean > > ( new EventEmitter < boolean > ( ) )
49
- readonly selectedEncoding = input < EventEmitter < number > > ( new EventEmitter < number > ( ) )
55
+ readonly deviceConnection = input ( new EventEmitter < boolean > ( ) )
56
+ readonly selectedEncoding = input ( new EventEmitter < number > ( ) )
57
+
50
58
module : AMTDesktop | null
51
59
redirector : AMTKvmDataRedirector | null
52
60
dataProcessor ! : IDataProcessor | null
@@ -61,6 +69,11 @@ export class KVMComponent implements OnInit, AfterViewInit, OnDestroy {
61
69
{ value : 2 , viewValue : 'RLE 16' }
62
70
]
63
71
72
+ constructor ( ) {
73
+ effect ( ( ) => {
74
+ this . toggleFullscreen ( )
75
+ } )
76
+ }
64
77
ngOnInit ( ) : void {
65
78
this . deviceConnection ( ) . subscribe ( ( data : boolean ) => {
66
79
if ( data ) {
@@ -79,6 +92,26 @@ export class KVMComponent implements OnInit, AfterViewInit, OnDestroy {
79
92
this . init ( )
80
93
}
81
94
95
+ toggleFullscreen ( ) : void {
96
+ const canvasElement = this . canvas ( ) ?. nativeElement
97
+ if ( ! canvasElement ) return
98
+
99
+ if ( this . isFullscreen ( ) ) {
100
+ if ( canvasElement . requestFullscreen ) {
101
+ canvasElement . requestFullscreen ( )
102
+ }
103
+ this . renderer . addClass ( canvasElement , 'fullscreen' )
104
+ } else {
105
+ if ( document . exitFullscreen && document . fullscreenElement != null ) {
106
+ document . exitFullscreen ( )
107
+ }
108
+ this . renderer . removeClass ( canvasElement , 'fullscreen' )
109
+ }
110
+ if ( this . mouseHelper != null ) {
111
+ this . mouseHelper . resetOffsets ( )
112
+ }
113
+ }
114
+
82
115
instantiate ( ) : void {
83
116
const canvas = this . canvas ( )
84
117
this . context = canvas ?. nativeElement . getContext ( '2d' )
0 commit comments