1
- import { Component , OnInit } from '@angular/core' ;
1
+ import { Component , OnInit , ViewChild , ElementRef , HostListener } from '@angular/core' ;
2
2
import { MatDialog } from '@angular/material' ;
3
3
import { ConnectDialog } from './connect.dialog/connect.dialog' ;
4
4
import { ConnectModel } from './models/connect.model' ;
@@ -7,11 +7,15 @@ import { CreateClientDriverConfiguration, IClientDriver, Monitor, Point, Rect, W
7
7
8
8
@Component ( { selector : 'app-root' , templateUrl : './app.component.html' } )
9
9
export class AppComponent implements OnInit {
10
+ @ViewChild ( 'HTMLCanvasMouseImage_' ) HTMLCanvasMouseImage_ :ElementRef ;
11
+ @ViewChild ( 'HTMLCanvasScreenImage_' ) HTMLCanvasScreenImage_ :ElementRef ;
12
+ OriginalImage_ : HTMLImageElement ;
10
13
11
14
ScaleImage_ = false ;
12
15
ClientDriver_ : IClientDriver ;
13
16
Socket_ : WebSocket ;
14
17
Monitors = new Array < Monitor > ( ) ;
18
+ Cursor_ : ImageData ;
15
19
16
20
constructor ( public dialog : MatDialog ) { }
17
21
public ngOnInit ( ) : void
@@ -34,6 +38,7 @@ export class AppComponent implements OnInit {
34
38
. onMessage ( ( ws : WebSocket , message : WSMessage ) => { console . log ( 'onMessage length:' + message . data . byteLength ) ; } )
35
39
. onDisconnection ( ( ws : WebSocket , code : number , message : string ) => {
36
40
console . log ( 'onDisconnection' ) ;
41
+ this . Cursor_ = null ;
37
42
this . ScaleImage_ = false ;
38
43
this . Monitors = new Array < Monitor > ( ) ;
39
44
this . ClientDriver_ = null ;
@@ -42,8 +47,8 @@ export class AppComponent implements OnInit {
42
47
} )
43
48
. onClipboardChanged ( ( clipstring : string ) => { console . log ( 'onClipboardChanged: ' + clipstring ) ; } )
44
49
. onFrameChanged ( ( image : HTMLImageElement , monitor : Monitor , rect : Rect ) => {
45
-
46
- } )
50
+ this . HTMLCanvasScreenImage_ . nativeElement . getContext ( "2d" ) . drawImage ( image , monitor . OffsetX + rect . Origin . X , monitor . OffsetY + rect . Origin . Y ) ;
51
+ } )
47
52
. onMonitorsChanged ( ( monitors : Monitor [ ] ) => {
48
53
this . Monitors = monitors ;
49
54
var width = 0 ;
@@ -53,17 +58,22 @@ export class AppComponent implements OnInit {
53
58
if ( m . Height > maxheight )
54
59
maxheight = m . Height ;
55
60
} ) ;
56
-
61
+ this . HTMLCanvasScreenImage_ . nativeElement . width = width ;
62
+ this . HTMLCanvasScreenImage_ . nativeElement . height = maxheight ;
63
+
57
64
} )
58
65
. onMouseImageChanged ( ( image : ImageData ) => {
59
-
60
- } )
66
+ this . Cursor_ = image ;
67
+ this . HTMLCanvasMouseImage_ . nativeElement . getContext ( "2d" ) . putImageData ( this . Cursor_ , 0 , 0 ) ;
68
+ } )
61
69
. onMousePositionChanged ( ( pos : Point ) => {
62
-
63
- } )
70
+ this . HTMLCanvasMouseImage_ . nativeElement . style . top = pos . Y + "px" ;
71
+ this . HTMLCanvasMouseImage_ . nativeElement . style . left = pos . X + "px" ;
72
+ } )
64
73
. onNewFrame ( ( image : HTMLImageElement , monitor : Monitor , rect : Rect ) => {
65
-
66
- } )
74
+ this . HTMLCanvasScreenImage_ . nativeElement . getContext ( "2d" ) . drawImage ( image , monitor . OffsetX , monitor . OffsetY ) ;
75
+ this . OriginalImage_ = image ;
76
+ } )
67
77
. Build ( this . Socket_ ) ;
68
78
69
79
this . Socket_ . onerror = ( ev : Event ) => { console . log ( ev ) ; } ;
@@ -73,4 +83,47 @@ export class AppComponent implements OnInit {
73
83
}
74
84
} ) ;
75
85
}
86
+
87
+ @HostListener ( 'window:mousedown' , [ '$event' ] )
88
+ mousedown ( ev : MouseEvent ) {
89
+ if ( this . ClientDriver_ ) {
90
+ this . ClientDriver_ . SendMouseDown ( ev . button ) ;
91
+ }
92
+ }
93
+ @HostListener ( 'window:onkeydown' , [ '$event' ] )
94
+ onkeydown ( ev : KeyboardEvent ) {
95
+ if ( this . ClientDriver_ ) {
96
+ this . ClientDriver_ . SendKeyDown ( ConvertToKeyCode ( ev ) ) ;
97
+ }
98
+ }
99
+ @HostListener ( 'window:onkeyup' , [ '$event' ] )
100
+ onkeyup ( ev : KeyboardEvent ) {
101
+ if ( this . ClientDriver_ ) {
102
+ this . ClientDriver_ . SendKeyUp ( ConvertToKeyCode ( ev ) ) ;
103
+ }
104
+ }
105
+ @HostListener ( 'window:onwheel' , [ '$event' ] )
106
+ onwheel ( ev : WheelEvent ) {
107
+ if ( this . ClientDriver_ ) {
108
+ this . ClientDriver_ . SendMouseScroll ( ev . deltaY < 0 ? - 1 : 1 ) ;
109
+ }
110
+ }
111
+ @HostListener ( 'window:onmove' , [ '$event' ] )
112
+ onmove ( ev : WheelEvent ) {
113
+ if ( this . ClientDriver_ ) {
114
+ this . ClientDriver_ . SendMousePosition ( { Y : ev . pageY , X : ev . pageX } ) ;
115
+ }
116
+ }
117
+ @HostListener ( 'window:onmouseup' , [ '$event' ] )
118
+ onmouseup ( ev : MouseEvent ) {
119
+ if ( this . ClientDriver_ ) {
120
+ this . ClientDriver_ . SendMouseUp ( ev . button ) ;
121
+ }
122
+ }
123
+ @HostListener ( 'window:onwonmousedownheel' , [ '$event' ] )
124
+ onmousedown ( ev : MouseEvent ) {
125
+ if ( this . ClientDriver_ ) {
126
+ this . ClientDriver_ . SendMouseDown ( ev . button ) ;
127
+ }
128
+ }
76
129
}
0 commit comments