-
Notifications
You must be signed in to change notification settings - Fork 25
/
eventhandler.ts
643 lines (536 loc) · 26.7 KB
/
eventhandler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
/* spellchecker: disable */
import { vec2 } from 'gl-matrix';
import { Observable, Subscription } from 'rxjs';
import { assert } from './auxiliaries';
import { EyeGazeEvent } from './eyegazeevent';
import { EyeGazeEventProvider } from './eyegazeeventprovider';
import { MouseEventProvider } from './mouseeventprovider';
import { PointerEventProvider } from './pointereventprovider';
import { Invalidate } from './renderer';
import { TouchEventProvider } from './toucheventprovider';
/* spellchecker: enable */
export interface EventProvider {
pointerEventProvider: PointerEventProvider;
mouseEventProvider: MouseEventProvider;
eyeGazeEventProvider?: EyeGazeEventProvider;
}
/**
* Callback for handling mouse events, given the latest mouse events (since last update) as well as the previous.
*/
export interface MouseEventHandler { (latests: Array<MouseEvent>, previous: Array<MouseEvent>): void; }
/**
* Callback for handling touch events, given the latest touch events (since last update) as well as the previous.
*/
export interface TouchEventHandler { (latests: Array<TouchEvent>, previous: Array<TouchEvent>): void; }
/**
* Callback for handling pointer events, given the latest touch events (since last update) as well as the previous.
*/
export interface PointerEventHandler { (latests: Array<PointerEvent>, previous: Array<PointerEvent>): void; }
/**
* Callback for handling eye gaze events, given the latest eye gaze events (since last update) as well as the previous.
*/
export interface EyeGazeEventHandler { (latests: Array<EyeGazeEvent>, previous: Array<EyeGazeEvent>): void; }
/**
* ... Provider and event handler are explicitly separated in order to reduce the number of observables (reuse of event
* provider for multiple handler).
*/
export class EventHandler {
/**
* The event handler's invalidation callback. This should usually be setup by the owning renderer and invoke the
* same callback the renderer has been given by the canvas. This invalidation is required, when continuous
* rendering is not present, events might cause need for new rendering requests.
*/
protected _invalidate: Invalidate | undefined;
protected _subscriptions = new Array<Subscription>();
/**
* Assigned key event provider. This is usually created and owned by the canvas.
*/
// protected _keyEventProvider: KeyEventProvider | undefined;
/**
* Assigned mouse event provider. This is usually created and owned by the canvas.
*/
protected _mouseEventProvider: MouseEventProvider | undefined;
/**
* Assigned touch event provider. This is usually created and owned by the canvas.
*/
protected _touchEventProvider: TouchEventProvider | undefined;
/**
* Assigned pointer event provider. This is usually created and owned by the canvas.
*/
protected _pointerEventProvider: PointerEventProvider | undefined;
/**
* Assigned eye gaze event provider. This is usually created and owned by the eye gaze data stream.
*/
protected _eyeGazeEventProvider: EyeGazeEventProvider | undefined;
protected _latestMouseEventsByType =
new Map<MouseEventProvider.Type, Array<MouseEvent>>();
protected _previousMouseEventsByType =
new Map<MouseEventProvider.Type, Array<MouseEvent>>();
protected _mouseEventHandlerByType =
new Map<MouseEventProvider.Type, Array<MouseEventHandler>>();
protected _latestTouchEventsByType =
new Map<TouchEventProvider.Type, Array<TouchEvent>>();
protected _previousTouchEventsByType =
new Map<TouchEventProvider.Type, Array<TouchEvent>>();
protected _touchEventHandlerByType =
new Map<TouchEventProvider.Type, Array<TouchEventHandler>>();
protected _latestPointerEventsByType =
new Map<PointerEventProvider.Type, Array<PointerEvent>>();
protected _previousPointerEventsByType =
new Map<PointerEventProvider.Type, Array<PointerEvent>>();
protected _pointerEventHandlerByType =
new Map<PointerEventProvider.Type, Array<PointerEventHandler>>();
protected _latestEyeGazeEventsByType =
new Map<EyeGazeEventProvider.Type, Array<EyeGazeEvent>>();
protected _previousEyeGazeEventsByType =
new Map<EyeGazeEventProvider.Type, Array<EyeGazeEvent>>();
protected _eyeGazeEventHandlerByType =
new Map<EyeGazeEventProvider.Type, Array<EyeGazeEventHandler>>();
constructor(invalidate: Invalidate | undefined,
eventProvider: EventProvider) {
this._invalidate = invalidate;
this._mouseEventProvider = eventProvider.mouseEventProvider;
this._mouseEventProvider.preventDefault(MouseEventProvider.Type.Wheel);
this._pointerEventProvider = eventProvider.pointerEventProvider;
this._eyeGazeEventProvider = eventProvider.eyeGazeEventProvider;
}
/** @callback Invalidate
* A callback intended to be invoked whenever the specialized event handler itself is invalid. By default only
* optional updates (renderer decides whether or not to continue redraw) are triggered.
*/
protected invalidate(force: boolean = false): void {
if (this._invalidate) {
this._invalidate(force);
}
}
/**
* Utility for registering an additional mouse event handler for updates on mouse events of the given type. The
* handler is to be called on update if at least a single mouse event of the given type has occurred since last
* update.
* @param type - Mouse event type the handler is to be associated with.
* @param handler - Handler to be called on update.
*/
protected pushMouseEventHandler(type: MouseEventProvider.Type, handler: MouseEventHandler): void {
if (this._mouseEventHandlerByType.has(type)) {
(this._mouseEventHandlerByType.get(type) as Array<MouseEventHandler>).push(handler);
return;
}
this._mouseEventHandlerByType.set(type, new Array<MouseEventHandler>());
this._previousMouseEventsByType.set(type, new Array<MouseEvent>());
const latest = new Array<MouseEvent>();
this._latestMouseEventsByType.set(type, latest);
assert(this._mouseEventProvider !== undefined, `expected valid mouse event provider`);
const observable = (this._mouseEventProvider as MouseEventProvider).observable(type);
switch (type) {
case MouseEventProvider.Type.Wheel:
this._subscriptions.push((observable as Observable<WheelEvent>).subscribe(
(event) => { latest.push(event); this.invalidate(); }));
break;
default:
this._subscriptions.push((observable as Observable<MouseEvent>).subscribe(
(event) => { latest.push(event); this.invalidate(); }));
break;
}
(this._mouseEventHandlerByType.get(type) as Array<MouseEventHandler>).push(handler);
}
protected invokeMouseEventHandler(type: MouseEventProvider.Type): void {
const handlers = this._mouseEventHandlerByType.get(type);
if (handlers === undefined || handlers.length === 0) {
return;
}
const latest = this._latestMouseEventsByType.get(type) as Array<MouseEvent>;
if (latest.length === 0) {
return;
}
const previous = this._previousMouseEventsByType.get(type) as Array<MouseEvent>;
handlers.forEach((handler) => handler(latest, previous));
Object.assign(previous, latest);
latest.length = 0;
}
/**
* Utility for registering an additional touch event handler for updates on touch events of the given type. The
* handler is to be called on update iff at least a single touch event of the given type has occurred since last
* update.
* @param type - Touch event type the handler is to be associated with.
* @param handler - Handler to be called on update.
*/
protected pushTouchEventHandler(type: TouchEventProvider.Type, handler: TouchEventHandler): void {
if (this._touchEventHandlerByType.has(type)) {
(this._touchEventHandlerByType.get(type) as Array<TouchEventHandler>).push(handler);
return;
}
this._touchEventHandlerByType.set(type, new Array<TouchEventHandler>());
this._previousTouchEventsByType.set(type, new Array<TouchEvent>());
const latest = new Array<TouchEvent>();
this._latestTouchEventsByType.set(type, latest);
assert(this._touchEventProvider !== undefined, `expected valid touch event provider`);
const observable = (this._touchEventProvider as TouchEventProvider).observable(type);
this._subscriptions.push((observable as Observable<TouchEvent>).subscribe(
(event) => { latest.push(event); this.invalidate(); }));
(this._touchEventHandlerByType.get(type) as Array<TouchEventHandler>).push(handler);
}
protected invokeTouchEventHandler(type: TouchEventProvider.Type): void {
const handlers = this._touchEventHandlerByType.get(type);
if (handlers === undefined || handlers.length === 0) {
return;
}
const latest = this._latestTouchEventsByType.get(type) as Array<TouchEvent>;
if (latest.length === 0) {
return;
}
const previous = this._previousTouchEventsByType.get(type) as Array<TouchEvent>;
handlers.forEach((handler) => handler(latest, previous));
Object.assign(previous, latest);
latest.length = 0;
}
/**
* Utility for registering an additional pointer event handler for updates on pointer events of the given type. The
* handler is to be called on update iff at least a single touch event of the given type has occurred since last
* update.
* @param type - Pointer event type the handler is to be associated with.
* @param handler - Handler to be called on update.
*/
protected pushPointerEventHandler(type: PointerEventProvider.Type, handler: PointerEventHandler): void {
if (this._pointerEventHandlerByType.has(type)) {
(this._pointerEventHandlerByType.get(type) as Array<PointerEventHandler>).push(handler);
return;
}
this._pointerEventHandlerByType.set(type, new Array<PointerEventHandler>());
this._previousPointerEventsByType.set(type, new Array<PointerEvent>());
const latest = new Array<PointerEvent>();
this._latestPointerEventsByType.set(type, latest);
assert(this._pointerEventProvider !== undefined, `expected valid pointer event provider`);
const observable = (this._pointerEventProvider as PointerEventProvider).observable(type);
this._subscriptions.push((observable as Observable<PointerEvent>).subscribe(
(event) => { latest.push(event); this.invalidate(); }));
(this._pointerEventHandlerByType.get(type) as Array<PointerEventHandler>).push(handler);
}
protected invokePointerEventHandler(type: PointerEventProvider.Type): void {
const handlers = this._pointerEventHandlerByType.get(type);
if (handlers === undefined || handlers.length === 0) {
return;
}
const latest = this._latestPointerEventsByType.get(type) as Array<PointerEvent>;
if (latest.length === 0) {
return;
}
const previous = this._previousPointerEventsByType.get(type) as Array<PointerEvent>;
handlers.forEach((handler) => handler(latest, previous));
Object.assign(previous, latest);
latest.length = 0;
}
/**
* Utility for registering an additional touch event handler for updates on touch events of the given type. The
* handler is to be called on update iff at least a single touch event of the given type has occurred since last
* update.
* @param type - Touch event type the handler is to be associated with.
* @param handler - Handler to be called on update.
*/
protected pushEyeGazeEventHandler(type: EyeGazeEventProvider.Type, handler: EyeGazeEventHandler): void {
if (this._eyeGazeEventHandlerByType.has(type)) {
(this._eyeGazeEventHandlerByType.get(type) as Array<EyeGazeEventHandler>).push(handler);
return;
}
this._eyeGazeEventHandlerByType.set(type, new Array<EyeGazeEventHandler>());
this._previousEyeGazeEventsByType.set(type, new Array<EyeGazeEvent>());
const latest = new Array<EyeGazeEvent>();
this._latestEyeGazeEventsByType.set(type, latest);
assert(this._eyeGazeEventProvider !== undefined, `expected valid eye gaze event provider`);
const observable = (this._eyeGazeEventProvider as EyeGazeEventProvider).observable(type);
this._subscriptions.push((observable as Observable<EyeGazeEvent>).subscribe(
(event) => { latest.push(event); this.invalidate(); }));
(this._eyeGazeEventHandlerByType.get(type) as Array<EyeGazeEventHandler>).push(handler);
}
protected invokeEyeGazeEventHandler(type: EyeGazeEventProvider.Type): void {
const handlers = this._eyeGazeEventHandlerByType.get(type);
if (handlers === undefined || handlers.length === 0) {
return;
}
const latest = this._latestEyeGazeEventsByType.get(type) as Array<EyeGazeEvent>;
if (latest.length === 0) {
return;
}
const previous = this._previousEyeGazeEventsByType.get(type) as Array<EyeGazeEvent>;
handlers.forEach((handler) => handler(latest, previous));
Object.assign(previous, latest);
latest.length = 0;
}
/**
* Disposes all registered handlers of all event types.
*/
dispose(): void {
this._latestMouseEventsByType.forEach((value) => value.length = 0);
this._previousMouseEventsByType.forEach((value) => value.length = 0);
this._latestTouchEventsByType.forEach((value) => value.length = 0);
this._previousTouchEventsByType.forEach((value) => value.length = 0);
this._latestPointerEventsByType.forEach((value) => value.length = 0);
this._previousPointerEventsByType.forEach((value) => value.length = 0);
this._previousEyeGazeEventsByType.forEach((value) => value.length = 0);
this._latestEyeGazeEventsByType.forEach((value) => value.length = 0);
for (const subscription of this._subscriptions) {
subscription.unsubscribe();
}
}
/**
* Triggers (by means of a helper function) invocation of all registered handler of all event types.
*/
update(): void {
this.invokeMouseEventHandler(MouseEventProvider.Type.Click);
this.invokeMouseEventHandler(MouseEventProvider.Type.Enter);
this.invokeMouseEventHandler(MouseEventProvider.Type.Leave);
this.invokeMouseEventHandler(MouseEventProvider.Type.Down);
this.invokeMouseEventHandler(MouseEventProvider.Type.Up);
this.invokeMouseEventHandler(MouseEventProvider.Type.Move);
this.invokeMouseEventHandler(MouseEventProvider.Type.Wheel);
this.invokeTouchEventHandler(TouchEventProvider.Type.Start);
this.invokeTouchEventHandler(TouchEventProvider.Type.End);
this.invokeTouchEventHandler(TouchEventProvider.Type.Move);
this.invokeTouchEventHandler(TouchEventProvider.Type.Cancel);
this.invokePointerEventHandler(PointerEventProvider.Type.Move);
this.invokePointerEventHandler(PointerEventProvider.Type.Down);
this.invokePointerEventHandler(PointerEventProvider.Type.Enter);
this.invokePointerEventHandler(PointerEventProvider.Type.Up);
this.invokePointerEventHandler(PointerEventProvider.Type.Leave);
this.invokePointerEventHandler(PointerEventProvider.Type.Cancel);
this.invokeEyeGazeEventHandler(EyeGazeEventProvider.Type.EyeGazeData);
this.invokeEyeGazeEventHandler(EyeGazeEventProvider.Type.NewServerMessage);
this.invokeEyeGazeEventHandler(EyeGazeEventProvider.Type.ConnectionStatus);
this.invokeEyeGazeEventHandler(EyeGazeEventProvider.Type.BinaryMessageParsingError);
}
/**
* Normalize mouse and touch event coordinates for various browsers.
* @param event - Mouse, wheel, or touch event.
* @param normalize - Whether or not to compute normalized coordinates (offsets).
* @returns - Array of normalized x and y offsets (in case of multiple touches).
*/
offsets(event: MouseEvent | WheelEvent | TouchEvent, normalize: boolean = true): Array<vec2> {
const offsets = new Array<vec2>();
/*
* Workaround for Chrome based on solution of Benjamin Wasty: EventHandler.offsets() uses
* event.target.getBoundingClientRect() which often triggers a reflow/layout that might take ~20ms and slow
* down, e.g., navigation a lot. Firefox on the other hand doesn't properly support offsetX/offsetY (set to 0).
*/
let chromeWorkaround = false;
if (event instanceof MouseEvent) {
const e = event as MouseEvent;
chromeWorkaround = (e.offsetX !== 0 && e.offsetY !== 0);
offsets.push(chromeWorkaround ?
vec2.fromValues(e.offsetX, e.offsetY) :
vec2.fromValues(e.clientX, e.clientY));
} else if (event instanceof WheelEvent) {
const e = event as WheelEvent;
chromeWorkaround = (e.offsetX !== 0 && e.offsetY !== 0);
offsets.push(chromeWorkaround ?
vec2.fromValues(e.offsetX, e.offsetY) :
vec2.fromValues(e.clientX, e.clientY));
} else if (event instanceof TouchEvent) {
const e = event as TouchEvent;
for (let index = 0; index < e.touches.length; ++index) {
const touch = e.touches.item(index)!;
offsets.push(vec2.fromValues(touch.clientX, touch.clientY));
}
}
if (chromeWorkaround) {
if (normalize) {
for (const offset of offsets) {
vec2.scale(offset, offset, window.devicePixelRatio);
}
}
return offsets;
}
const target = event.target || event.currentTarget || event.srcElement;
const rect = (target as HTMLElement).getBoundingClientRect();
for (const offset of offsets) {
offset[0] = Math.floor(offset[0] - rect.left);
offset[1] = Math.floor(offset[1] - rect.top);
if (normalize) {
vec2.scale(offset, offset, window.devicePixelRatio);
}
}
return offsets;
}
/**
* Register a click event handler that is to be called on update iff at least a single click event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushClickHandler(handler: MouseEventHandler): void {
this.pushMouseEventHandler(MouseEventProvider.Type.Click, handler);
}
/**
* Register an mouse enter event handler that is to be called on update iff at least a single mouse enter event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushMouseEnterHandler(handler: MouseEventHandler): void {
this.pushMouseEventHandler(MouseEventProvider.Type.Enter, handler);
}
/**
* Register an mouse leave event handler that is to be called on update iff at least a single mouse leave event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushMouseLeaveHandler(handler: MouseEventHandler): void {
this.pushMouseEventHandler(MouseEventProvider.Type.Leave, handler);
}
/**
* Register an mouse down event handler that is to be called on update iff at least a single mouse down event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushMouseDownHandler(handler: MouseEventHandler): void {
this.pushMouseEventHandler(MouseEventProvider.Type.Down, handler);
}
/**
* Register an mouse up event handler that is to be called on update iff at least a single mouse up event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushMouseUpHandler(handler: MouseEventHandler): void {
this.pushMouseEventHandler(MouseEventProvider.Type.Up, handler);
}
/**
* Register an mouse move event handler that is to be called on update iff at least a single mouse move event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushMouseMoveHandler(handler: MouseEventHandler): void {
this.pushMouseEventHandler(MouseEventProvider.Type.Move, handler);
}
/**
* Register an mouse wheel event handler that is to be called on update iff at least a single mouse wheel event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushMouseWheelHandler(handler: MouseEventHandler): void {
this.pushMouseEventHandler(MouseEventProvider.Type.Wheel, handler);
}
/**
* Register a touch start event handler that is to be called on update iff at least a single touch start event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushTouchStartHandler(handler: TouchEventHandler): void {
this.pushTouchEventHandler(TouchEventProvider.Type.Start, handler);
}
/**
* Register a touch end event handler that is to be called on update iff at least a single touch end event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushTouchEndHandler(handler: TouchEventHandler): void {
this.pushTouchEventHandler(TouchEventProvider.Type.End, handler);
}
/**
* Register a touch move event handler that is to be called on update iff at least a single touch move event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushTouchMoveHandler(handler: TouchEventHandler): void {
this.pushTouchEventHandler(TouchEventProvider.Type.Move, handler);
}
/**
* Register a touch cancel event handler that is to be called on update iff at least a single touch cancel event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushTouchCancelHandler(handler: TouchEventHandler): void {
this.pushTouchEventHandler(TouchEventProvider.Type.Cancel, handler);
}
/**
* Register a pointer up event handler that is to be called on update iff at least a single touch cancel event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushPointerUpHandler(handler: PointerEventHandler): void {
this.pushPointerEventHandler(PointerEventProvider.Type.Up, handler);
}
/**
* Register a pointer down event handler that is to be called on update iff at least a single touch cancel event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushPointerDownHandler(handler: PointerEventHandler): void {
this.pushPointerEventHandler(PointerEventProvider.Type.Down, handler);
}
/**
* Register a pointer enter event handler that is to be called on update iff at least a single touch cancel event
* has occurred since last update.
* @param handler - Handler to be called on update.
*/
pushPointerEnterHandler(handler: PointerEventHandler): void {
this.pushPointerEventHandler(PointerEventProvider.Type.Enter, handler);
}
/**
* Register a pointer leave event handler that is to be called on update iff at least a single touch cancel event
* has occurred since last update.
* @param handler - Handler to be called on update.
*/
pushPointerLeaveHandler(handler: PointerEventHandler): void {
this.pushPointerEventHandler(PointerEventProvider.Type.Leave, handler);
}
/**
* Register a pointer move event handler that is to be called on update iff at least a single touch cancel event has
* occurred since last update.
* @param handler - Handler to be called on update.
*/
pushPointerMoveHandler(handler: PointerEventHandler): void {
this.pushPointerEventHandler(PointerEventProvider.Type.Move, handler);
}
/**
* Register a pointer cancel event handler that is to be called on update iff at least a single touch cancel event
* has occurred since last update.
* @param handler - Handler to be called on update.
*/
pushPointerCancelHandler(handler: PointerEventHandler): void {
this.pushPointerEventHandler(PointerEventProvider.Type.Cancel, handler);
}
/**
* Register a eye gaze data event handler that is to be called on update if at least
* a single eye gaze data event has occurred since last update.
* @param handler - Handler to be called on update.
*/
pushEyeGazeDataHandler(handler: EyeGazeEventHandler): void {
this.pushEyeGazeEventHandler(EyeGazeEventProvider.Type.EyeGazeData, handler);
}
/**
* Register a eye gaze server message event handler that is to be called on update if at least
* a single eye gaze server message event has occurred since last update.
* @param handler - Handler to be called on update.
*/
pushEyeGazeServerMessageHandler(handler: EyeGazeEventHandler): void {
this.pushEyeGazeEventHandler(EyeGazeEventProvider.Type.NewServerMessage, handler);
}
/**
* Register a eye gaze connection status event handler that is to be called on update if at least
* a single eye gaze connection status event has occurred since last update.
* @param handler - Handler to be called on update.
*/
pushEyeGazeConnectionStatusHandler(handler: EyeGazeEventHandler): void {
this.pushEyeGazeEventHandler(EyeGazeEventProvider.Type.ConnectionStatus, handler);
}
/**
* Register a eye gaze binary message parsing error event handler that is to be called on update if at least
* a single eye gaze binary message parsing error event has occurred since last update.
* @param handler - Handler to be called on update.
*/
pushEyeGazeBinaryMessageParsingErrorHandler(handler: EyeGazeEventHandler): void {
this.pushEyeGazeEventHandler(EyeGazeEventProvider.Type.BinaryMessageParsingError, handler);
}
/**
* Forward pointer lock request to the mouse event provider (if one exists).
*/
requestPointerLock(): void {
if (this._mouseEventProvider) {
this._mouseEventProvider.pointerLock = true;
}
}
/**
* Forward pointer lock release request to the mouse event provider (if one exists).
*/
exitPointerLock(): void {
if (this._mouseEventProvider) {
this._mouseEventProvider.pointerLock = false;
}
}
}