@celljs/ta-host 4.17.0 → 4.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/node/app-commands.d.ts +1 -1
- package/esm/node/app-commands.js +46 -29
- package/esm/node/credentials.d.ts +12 -0
- package/esm/node/credentials.js +35 -0
- package/esm/node/index.d.ts +2 -0
- package/esm/node/index.js +2 -0
- package/esm/node/keep-awake.d.ts +3 -0
- package/esm/node/keep-awake.js +6 -1
- package/esm/node/package-hosts.d.ts +2 -0
- package/esm/node/package-hosts.js +6 -0
- package/esm/node/rooms-bridge.d.ts +10 -1
- package/esm/node/rooms-bridge.js +25 -0
- package/esm/node/screen-share/desktop-picture.d.ts +51 -0
- package/esm/node/screen-share/desktop-picture.js +133 -0
- package/esm/node/screen-share/desktop-session.d.ts +128 -0
- package/esm/node/screen-share/desktop-session.js +437 -0
- package/esm/node/screen-share/desktop-targets.d.ts +24 -0
- package/esm/node/screen-share/desktop-targets.js +80 -0
- package/esm/node/screen-share/desktop-viewer.d.ts +146 -0
- package/esm/node/screen-share/desktop-viewer.js +339 -0
- package/esm/node/screen-share/index.d.ts +8 -0
- package/esm/node/screen-share/index.js +9 -0
- package/esm/node/screen-share/rfb-client.d.ts +54 -0
- package/esm/node/screen-share/rfb-client.js +179 -0
- package/esm/node/screen-share/rfb-des.d.ts +11 -0
- package/esm/node/screen-share/rfb-des.js +143 -0
- package/esm/node/screen-share/rfb-encodings.d.ts +71 -0
- package/esm/node/screen-share/rfb-encodings.js +288 -0
- package/esm/node/screen-share/rfb-framebuffer.d.ts +16 -0
- package/esm/node/screen-share/rfb-framebuffer.js +53 -0
- package/esm/node/screen-share/rfb-protocol.d.ts +90 -0
- package/esm/node/screen-share/rfb-protocol.js +36 -0
- package/esm/node/screen-share/rfb-reader.d.ts +34 -0
- package/esm/node/screen-share/rfb-reader.js +110 -0
- package/esm/node/screen-share/rfb-security.d.ts +30 -0
- package/esm/node/screen-share/rfb-security.js +136 -0
- package/esm/node/screen-share/rfb-test-server.d.ts +37 -0
- package/esm/node/screen-share/rfb-test-server.js +116 -0
- package/esm/node/screen-share/screen-share-server-impl.d.ts +37 -0
- package/esm/node/screen-share/screen-share-server-impl.js +76 -0
- package/esm/node/screen-share/screen-shares.d.ts +123 -0
- package/esm/node/screen-share/screen-shares.js +463 -0
- package/esm/node/session-info-util.d.ts +10 -11
- package/esm/node/session-info-util.js +16 -94
- package/esm/node/settings-store.d.ts +1 -1
- package/esm/node/settings-store.js +7 -4
- package/esm/node/sign-in/access-store.d.ts +1 -1
- package/esm/node/sign-in/access-store.js +4 -1
- package/esm/node/sign-in/index.d.ts +2 -0
- package/esm/node/sign-in/index.js +2 -0
- package/esm/node/sign-in/polled-sign-in.d.ts +50 -0
- package/esm/node/sign-in/polled-sign-in.js +83 -0
- package/esm/node/sign-in/sign-in-devices.d.ts +55 -0
- package/esm/node/sign-in/sign-in-devices.js +113 -0
- package/esm/node/sign-in/sign-in-flow.d.ts +38 -4
- package/esm/node/sign-in/sign-in-flow.js +79 -4
- package/esm/node/sign-in/sign-in-pages.d.ts +8 -0
- package/esm/node/sign-in/sign-in-pages.js +137 -8
- package/esm/node/sign-in/sign-in-provider.d.ts +6 -0
- package/esm/node/sign-in/sign-in-provider.js +15 -0
- package/esm/node/sources-extension.d.ts +10 -0
- package/esm/node/sources-extension.js +18 -0
- package/esm/node/ta-server-impl.js +3 -3
- package/esm/node/ta-session-factory.js +2 -0
- package/esm/node/team/team-calls.js +27 -0
- package/esm/node/voice-bridge.d.ts +3 -1
- package/esm/node/voice-bridge.js +10 -3
- package/esm/node/voices-file.d.ts +5 -0
- package/esm/node/voices-file.js +14 -3
- package/esm/node/working-directory.d.ts +8 -2
- package/esm/node/working-directory.js +7 -0
- package/lib/node/app-commands.d.ts +1 -1
- package/lib/node/app-commands.js +46 -29
- package/lib/node/credentials.d.ts +13 -0
- package/lib/node/credentials.js +38 -0
- package/lib/node/index.d.ts +2 -0
- package/lib/node/index.js +2 -0
- package/lib/node/keep-awake.d.ts +3 -0
- package/lib/node/keep-awake.js +6 -1
- package/lib/node/package-hosts.d.ts +2 -0
- package/lib/node/package-hosts.js +6 -0
- package/lib/node/rooms-bridge.d.ts +10 -1
- package/lib/node/rooms-bridge.js +25 -0
- package/lib/node/screen-share/desktop-picture.d.ts +52 -0
- package/lib/node/screen-share/desktop-picture.js +136 -0
- package/lib/node/screen-share/desktop-session.d.ts +129 -0
- package/lib/node/screen-share/desktop-session.js +442 -0
- package/lib/node/screen-share/desktop-targets.d.ts +25 -0
- package/lib/node/screen-share/desktop-targets.js +84 -0
- package/lib/node/screen-share/desktop-viewer.d.ts +147 -0
- package/lib/node/screen-share/desktop-viewer.js +343 -0
- package/lib/node/screen-share/index.d.ts +9 -0
- package/lib/node/screen-share/index.js +25 -0
- package/lib/node/screen-share/rfb-client.d.ts +55 -0
- package/lib/node/screen-share/rfb-client.js +183 -0
- package/lib/node/screen-share/rfb-des.d.ts +12 -0
- package/lib/node/screen-share/rfb-des.js +146 -0
- package/lib/node/screen-share/rfb-encodings.d.ts +72 -0
- package/lib/node/screen-share/rfb-encodings.js +295 -0
- package/lib/node/screen-share/rfb-framebuffer.d.ts +17 -0
- package/lib/node/screen-share/rfb-framebuffer.js +57 -0
- package/lib/node/screen-share/rfb-protocol.d.ts +91 -0
- package/lib/node/screen-share/rfb-protocol.js +39 -0
- package/lib/node/screen-share/rfb-reader.d.ts +35 -0
- package/lib/node/screen-share/rfb-reader.js +115 -0
- package/lib/node/screen-share/rfb-security.d.ts +31 -0
- package/lib/node/screen-share/rfb-security.js +141 -0
- package/lib/node/screen-share/rfb-test-server.d.ts +38 -0
- package/lib/node/screen-share/rfb-test-server.js +120 -0
- package/lib/node/screen-share/screen-share-server-impl.d.ts +38 -0
- package/lib/node/screen-share/screen-share-server-impl.js +79 -0
- package/lib/node/screen-share/screen-shares.d.ts +124 -0
- package/lib/node/screen-share/screen-shares.js +464 -0
- package/lib/node/session-info-util.d.ts +10 -11
- package/lib/node/session-info-util.js +15 -93
- package/lib/node/settings-store.d.ts +1 -1
- package/lib/node/settings-store.js +6 -3
- package/lib/node/sign-in/access-store.d.ts +1 -1
- package/lib/node/sign-in/access-store.js +4 -1
- package/lib/node/sign-in/index.d.ts +2 -0
- package/lib/node/sign-in/index.js +2 -0
- package/lib/node/sign-in/polled-sign-in.d.ts +51 -0
- package/lib/node/sign-in/polled-sign-in.js +87 -0
- package/lib/node/sign-in/sign-in-devices.d.ts +56 -0
- package/lib/node/sign-in/sign-in-devices.js +117 -0
- package/lib/node/sign-in/sign-in-flow.d.ts +38 -4
- package/lib/node/sign-in/sign-in-flow.js +80 -5
- package/lib/node/sign-in/sign-in-pages.d.ts +8 -0
- package/lib/node/sign-in/sign-in-pages.js +136 -7
- package/lib/node/sign-in/sign-in-provider.d.ts +6 -0
- package/lib/node/sign-in/sign-in-provider.js +15 -0
- package/lib/node/sources-extension.d.ts +11 -0
- package/lib/node/sources-extension.js +22 -0
- package/lib/node/ta-server-impl.js +2 -2
- package/lib/node/ta-session-factory.js +2 -0
- package/lib/node/team/team-calls.js +27 -0
- package/lib/node/voice-bridge.d.ts +3 -1
- package/lib/node/voice-bridge.js +9 -2
- package/lib/node/voices-file.d.ts +5 -0
- package/lib/node/voices-file.js +14 -3
- package/lib/node/working-directory.d.ts +8 -2
- package/lib/node/working-directory.js +7 -0
- package/package.json +14 -10
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
2
|
+
import type { TaDesktopFrames, TaDesktopInput, TaDesktopView } from '@celljs/ta-protocol';
|
|
3
|
+
import { type DesktopViewSize } from './desktop-picture';
|
|
4
|
+
import type { RfbClient } from './rfb-client';
|
|
5
|
+
import type { RfbRect } from './rfb-protocol';
|
|
6
|
+
/** How long a claim of the next frame waits for something to change before it answers `idle`. */
|
|
7
|
+
export declare const DESKTOP_READ_WAIT_MS = 10000;
|
|
8
|
+
/** Frames a viewer keeps, for a claim sent again: as many as a page may have claimed (its window). */
|
|
9
|
+
export declare const DESKTOP_KEPT_FRAMES = 4;
|
|
10
|
+
/** The least time between two changes of the mouse buttons sent to a desktop (apply). */
|
|
11
|
+
export declare const DESKTOP_BUTTON_GAP_MS = 20;
|
|
12
|
+
/** Input as it goes to the desktop: a state of the pointer, or a key. */
|
|
13
|
+
type DesktopOutgoing = {
|
|
14
|
+
kind: 'pointer';
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
buttons: number;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'key';
|
|
20
|
+
keysym: number;
|
|
21
|
+
down: boolean;
|
|
22
|
+
};
|
|
23
|
+
/** What a viewer has yet to tell its page. */
|
|
24
|
+
export interface DesktopPending {
|
|
25
|
+
/** Tiles of the view that changed. */
|
|
26
|
+
tiles: Set<number>;
|
|
27
|
+
/** Every tile: a new view, a new size, a page that starts again. */
|
|
28
|
+
all: boolean;
|
|
29
|
+
size: boolean;
|
|
30
|
+
cursor: boolean;
|
|
31
|
+
/** Control or the link changed: a frame goes even without pictures. */
|
|
32
|
+
news: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** How a frame is made of what changed: the session's. */
|
|
35
|
+
export type DesktopFrameMaker = (viewer: DesktopViewer, frame: {
|
|
36
|
+
seq: number;
|
|
37
|
+
whole: boolean;
|
|
38
|
+
waited: number;
|
|
39
|
+
}) => Promise<TaDesktopFrames>;
|
|
40
|
+
/**
|
|
41
|
+
* One page looking at a desktop (docs/design/ta-desktop-remote.md 5.4): its view, what changed in it since its last
|
|
42
|
+
* frame, and its frames numbered from 1. A page claims frames by number, several at once: the next waits for a change,
|
|
43
|
+
* one beyond waits for the one before, so that no two claims get the same picture; the last frames are kept, so that a
|
|
44
|
+
* claim sent again gets what it got. Its input once it works the desktop.
|
|
45
|
+
*/
|
|
46
|
+
export declare class DesktopViewer {
|
|
47
|
+
readonly id: string;
|
|
48
|
+
connection: RpcConnection;
|
|
49
|
+
readonly principal: string;
|
|
50
|
+
readonly clientMessageId: string;
|
|
51
|
+
readonly device: string;
|
|
52
|
+
view?: DesktopViewSize;
|
|
53
|
+
asked: TaDesktopView;
|
|
54
|
+
quality: 'auto' | 'crisp' | 'smooth';
|
|
55
|
+
/** The last frame made. */
|
|
56
|
+
built: number;
|
|
57
|
+
readonly since: number;
|
|
58
|
+
/** The largest batch of input taken. */
|
|
59
|
+
inputSeq: number;
|
|
60
|
+
readonly pastes: Set<string>;
|
|
61
|
+
/** Mouse buttons held and keys down: let go when it loses control or goes. */
|
|
62
|
+
buttons: number;
|
|
63
|
+
readonly keys: Set<number>;
|
|
64
|
+
lastInputAt: number;
|
|
65
|
+
/** Input not sent yet, and what of the buttons went last and when (apply). */
|
|
66
|
+
protected outgoing: DesktopOutgoing[];
|
|
67
|
+
protected client?: RfbClient;
|
|
68
|
+
protected sentButtons: number;
|
|
69
|
+
protected buttonsAt: number;
|
|
70
|
+
protected pacing?: ReturnType<typeof setTimeout>;
|
|
71
|
+
/** What its last frame told of control and the link: told again only when it changes. */
|
|
72
|
+
told: {
|
|
73
|
+
control?: string;
|
|
74
|
+
state?: string;
|
|
75
|
+
};
|
|
76
|
+
protected pending: DesktopPending;
|
|
77
|
+
protected readonly frames: Map<number, Promise<TaDesktopFrames>>;
|
|
78
|
+
protected building?: {
|
|
79
|
+
seq: number;
|
|
80
|
+
frame: Promise<TaDesktopFrames>;
|
|
81
|
+
};
|
|
82
|
+
/** A claim came for a frame dropped: the next is whole. */
|
|
83
|
+
protected needsFull: boolean;
|
|
84
|
+
protected wake?: () => void;
|
|
85
|
+
protected stopped: boolean;
|
|
86
|
+
protected lastBuiltAt: number;
|
|
87
|
+
constructor(id: string, connection: RpcConnection, principal: string, clientMessageId: string, device: string, view: TaDesktopView);
|
|
88
|
+
/**
|
|
89
|
+
* Frame `want`, as docs/design/ta-desktop-remote.md 5.4 answers it. `minGapMs` keeps frames apart (the cap of
|
|
90
|
+
* frames a second); `showing` says whether the desktop has pictures to give.
|
|
91
|
+
*/
|
|
92
|
+
claim(want: number, make: DesktopFrameMaker, options: {
|
|
93
|
+
minGapMs: number;
|
|
94
|
+
showing: () => boolean;
|
|
95
|
+
}): Promise<TaDesktopFrames>;
|
|
96
|
+
protected build(want: number, arrived: number, make: DesktopFrameMaker, options: {
|
|
97
|
+
minGapMs: number;
|
|
98
|
+
showing: () => boolean;
|
|
99
|
+
}): Promise<TaDesktopFrames>;
|
|
100
|
+
/** The view a page asks for; a later revision only. */
|
|
101
|
+
setView(view: TaDesktopView, framebuffer: {
|
|
102
|
+
width: number;
|
|
103
|
+
height: number;
|
|
104
|
+
}, screen?: RfbRect): boolean;
|
|
105
|
+
/** The view fitted to the framebuffer (and the screen asked for): again whenever its size changes. */
|
|
106
|
+
fit(framebuffer: {
|
|
107
|
+
width: number;
|
|
108
|
+
height: number;
|
|
109
|
+
}, screen?: RfbRect): void;
|
|
110
|
+
damage(rect: RfbRect): void;
|
|
111
|
+
sized(): void;
|
|
112
|
+
cursorChanged(): void;
|
|
113
|
+
/** Something its page should hear of (control, the link). */
|
|
114
|
+
news(): void;
|
|
115
|
+
/** An update of the desktop ended: a claim that waits answers now. */
|
|
116
|
+
updated(): void;
|
|
117
|
+
get ready(): boolean;
|
|
118
|
+
/** Ends what waits: the viewer closed. */
|
|
119
|
+
stop(): void;
|
|
120
|
+
/** What it has to tell, taken: the next frame starts from nothing. */
|
|
121
|
+
take(): DesktopPending;
|
|
122
|
+
/** What it took and could not tell (the view changed while it was made): told with the next. */
|
|
123
|
+
putBack(taken: DesktopPending): void;
|
|
124
|
+
/**
|
|
125
|
+
* The JPEG quality for this many tiles of the view: the whole screen changing (a scroll, a video) at less, so that
|
|
126
|
+
* frames keep coming; a little change crisper. `crisp` and `smooth` hold it up or down.
|
|
127
|
+
*/
|
|
128
|
+
qualityFor(tiles: number): number;
|
|
129
|
+
/**
|
|
130
|
+
* Input of a batch into RFB, in the framebuffer's coordinates; keys and buttons it holds are remembered. It goes in
|
|
131
|
+
* order, each change of the buttons (a press, a release, a notch of the wheel) DESKTOP_BUTTON_GAP_MS after the one
|
|
132
|
+
* before: the Screen Sharing of macOS keeps only the last state of the pointer of what comes at once, so that a
|
|
133
|
+
* click sent in one batch never clicked.
|
|
134
|
+
*/
|
|
135
|
+
apply(client: RfbClient, events: TaDesktopInput[]): void;
|
|
136
|
+
/** Lets go of what it holds: it lost control, or closed. */
|
|
137
|
+
letGo(client: RfbClient | undefined, at: {
|
|
138
|
+
x: number;
|
|
139
|
+
y: number;
|
|
140
|
+
}): void;
|
|
141
|
+
/** Sends what waits, up to a change of the buttons too soon after the last: the rest goes when it may. */
|
|
142
|
+
protected send(): void;
|
|
143
|
+
protected wait(ms: number): Promise<void>;
|
|
144
|
+
protected notify(): void;
|
|
145
|
+
}
|
|
146
|
+
export {};
|
|
147
|
+
//# sourceMappingURL=desktop-viewer.d.ts.map
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DesktopViewer = exports.DESKTOP_BUTTON_GAP_MS = exports.DESKTOP_KEPT_FRAMES = exports.DESKTOP_READ_WAIT_MS = void 0;
|
|
4
|
+
const desktop_picture_1 = require("./desktop-picture");
|
|
5
|
+
/** How long a claim of the next frame waits for something to change before it answers `idle`. */
|
|
6
|
+
exports.DESKTOP_READ_WAIT_MS = 10000;
|
|
7
|
+
/** Frames a viewer keeps, for a claim sent again: as many as a page may have claimed (its window). */
|
|
8
|
+
exports.DESKTOP_KEPT_FRAMES = 4;
|
|
9
|
+
/** The least time between two changes of the mouse buttons sent to a desktop (apply). */
|
|
10
|
+
exports.DESKTOP_BUTTON_GAP_MS = 20;
|
|
11
|
+
/** Notches of the wheel that may wait to be sent. */
|
|
12
|
+
const DESKTOP_QUEUED_NOTCHES = 8;
|
|
13
|
+
/** The buttons of RFB that are notches of the wheel. */
|
|
14
|
+
const WHEEL = 8 | 16 | 32 | 64;
|
|
15
|
+
const fresh = () => ({ tiles: new Set(), all: false, size: false, cursor: false, news: false });
|
|
16
|
+
/**
|
|
17
|
+
* One page looking at a desktop (docs/design/ta-desktop-remote.md 5.4): its view, what changed in it since its last
|
|
18
|
+
* frame, and its frames numbered from 1. A page claims frames by number, several at once: the next waits for a change,
|
|
19
|
+
* one beyond waits for the one before, so that no two claims get the same picture; the last frames are kept, so that a
|
|
20
|
+
* claim sent again gets what it got. Its input once it works the desktop.
|
|
21
|
+
*/
|
|
22
|
+
class DesktopViewer {
|
|
23
|
+
constructor(id, connection, principal, clientMessageId, device, view) {
|
|
24
|
+
var _a;
|
|
25
|
+
this.id = id;
|
|
26
|
+
this.connection = connection;
|
|
27
|
+
this.principal = principal;
|
|
28
|
+
this.clientMessageId = clientMessageId;
|
|
29
|
+
this.device = device;
|
|
30
|
+
this.quality = 'auto';
|
|
31
|
+
/** The last frame made. */
|
|
32
|
+
this.built = 0;
|
|
33
|
+
this.since = Date.now();
|
|
34
|
+
/** The largest batch of input taken. */
|
|
35
|
+
this.inputSeq = 0;
|
|
36
|
+
this.pastes = new Set();
|
|
37
|
+
/** Mouse buttons held and keys down: let go when it loses control or goes. */
|
|
38
|
+
this.buttons = 0;
|
|
39
|
+
this.keys = new Set();
|
|
40
|
+
this.lastInputAt = 0;
|
|
41
|
+
/** Input not sent yet, and what of the buttons went last and when (apply). */
|
|
42
|
+
this.outgoing = [];
|
|
43
|
+
this.sentButtons = 0;
|
|
44
|
+
this.buttonsAt = 0;
|
|
45
|
+
/** What its last frame told of control and the link: told again only when it changes. */
|
|
46
|
+
this.told = {};
|
|
47
|
+
this.pending = { ...fresh(), all: true, size: true, cursor: true, news: true };
|
|
48
|
+
this.frames = new Map();
|
|
49
|
+
/** A claim came for a frame dropped: the next is whole. */
|
|
50
|
+
this.needsFull = false;
|
|
51
|
+
this.stopped = false;
|
|
52
|
+
this.lastBuiltAt = 0;
|
|
53
|
+
this.asked = view;
|
|
54
|
+
this.quality = (_a = view.quality) !== null && _a !== void 0 ? _a : 'auto';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Frame `want`, as docs/design/ta-desktop-remote.md 5.4 answers it. `minGapMs` keeps frames apart (the cap of
|
|
58
|
+
* frames a second); `showing` says whether the desktop has pictures to give.
|
|
59
|
+
*/
|
|
60
|
+
async claim(want, make, options) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const arrived = Date.now();
|
|
63
|
+
const kept = this.frames.get(want);
|
|
64
|
+
if (kept) {
|
|
65
|
+
return kept;
|
|
66
|
+
}
|
|
67
|
+
if (!Number.isInteger(want) || want <= this.built || want > this.built + exports.DESKTOP_KEPT_FRAMES) {
|
|
68
|
+
if (Number.isInteger(want) && want <= this.built) {
|
|
69
|
+
this.needsFull = true;
|
|
70
|
+
}
|
|
71
|
+
return { seq: this.built, stale: true, waited: 0, tiles: [] };
|
|
72
|
+
}
|
|
73
|
+
if (want > this.built + 1) {
|
|
74
|
+
await this.claim(this.built + 1, make, options).catch(() => undefined);
|
|
75
|
+
if (this.stopped) {
|
|
76
|
+
return { seq: 0, unknown: true, waited: 0, tiles: [] };
|
|
77
|
+
}
|
|
78
|
+
// The one before came (or answered idle): this one waits its turn now.
|
|
79
|
+
return this.claim(want, make, options);
|
|
80
|
+
}
|
|
81
|
+
if (((_a = this.building) === null || _a === void 0 ? void 0 : _a.seq) === want) {
|
|
82
|
+
return this.building.frame;
|
|
83
|
+
}
|
|
84
|
+
const frame = this.build(want, arrived, make, options);
|
|
85
|
+
this.building = { seq: want, frame };
|
|
86
|
+
try {
|
|
87
|
+
return await frame;
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
if (((_b = this.building) === null || _b === void 0 ? void 0 : _b.frame) === frame) {
|
|
91
|
+
this.building = undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async build(want, arrived, make, options) {
|
|
96
|
+
const deadline = arrived + exports.DESKTOP_READ_WAIT_MS;
|
|
97
|
+
for (;;) {
|
|
98
|
+
if (this.stopped) {
|
|
99
|
+
return { seq: 0, unknown: true, waited: 0, tiles: [] };
|
|
100
|
+
}
|
|
101
|
+
const showing = options.showing();
|
|
102
|
+
if ((this.needsFull && showing) || (showing ? this.ready : this.pending.news)) {
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
const left = deadline - Date.now();
|
|
106
|
+
if (left <= 0) {
|
|
107
|
+
return { seq: this.built, idle: true, waited: Date.now() - arrived, tiles: [] };
|
|
108
|
+
}
|
|
109
|
+
await this.wait(left);
|
|
110
|
+
}
|
|
111
|
+
// Frames no closer than the cap allows: what changes meanwhile goes in this one.
|
|
112
|
+
const gap = this.lastBuiltAt + options.minGapMs - Date.now();
|
|
113
|
+
if (gap > 0) {
|
|
114
|
+
await new Promise(resolve => setTimeout(resolve, gap));
|
|
115
|
+
}
|
|
116
|
+
const whole = this.needsFull || this.pending.all;
|
|
117
|
+
if (this.needsFull) {
|
|
118
|
+
this.needsFull = false;
|
|
119
|
+
this.pending.all = true;
|
|
120
|
+
}
|
|
121
|
+
const seq = want;
|
|
122
|
+
this.built = seq;
|
|
123
|
+
this.lastBuiltAt = Date.now();
|
|
124
|
+
const frame = make(this, { seq, whole, waited: this.lastBuiltAt - arrived });
|
|
125
|
+
this.frames.set(seq, frame);
|
|
126
|
+
for (const old of this.frames.keys()) {
|
|
127
|
+
if (old <= seq - exports.DESKTOP_KEPT_FRAMES) {
|
|
128
|
+
this.frames.delete(old);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return frame;
|
|
132
|
+
}
|
|
133
|
+
/** The view a page asks for; a later revision only. */
|
|
134
|
+
setView(view, framebuffer, screen) {
|
|
135
|
+
if (typeof (view === null || view === void 0 ? void 0 : view.revision) !== 'number' || view.revision < this.asked.revision) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
this.asked = view;
|
|
139
|
+
this.quality = view.quality === 'crisp' || view.quality === 'smooth' ? view.quality : 'auto';
|
|
140
|
+
this.fit(framebuffer, screen);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
/** The view fitted to the framebuffer (and the screen asked for): again whenever its size changes. */
|
|
144
|
+
fit(framebuffer, screen) {
|
|
145
|
+
var _a;
|
|
146
|
+
if (framebuffer.width < 1 || framebuffer.height < 1) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const next = desktop_picture_1.DesktopPicture.fit(framebuffer, { ...this.asked, rect: (_a = this.asked.rect) !== null && _a !== void 0 ? _a : screen });
|
|
150
|
+
const now = this.view;
|
|
151
|
+
const same = now &&
|
|
152
|
+
now.width === next.width &&
|
|
153
|
+
now.height === next.height &&
|
|
154
|
+
now.rect.x === next.rect.x &&
|
|
155
|
+
now.rect.y === next.rect.y &&
|
|
156
|
+
now.rect.w === next.rect.w &&
|
|
157
|
+
now.rect.h === next.rect.h;
|
|
158
|
+
if (!same) {
|
|
159
|
+
this.view = next;
|
|
160
|
+
this.pending.all = true;
|
|
161
|
+
this.notify();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
damage(rect) {
|
|
165
|
+
if (!this.view || this.pending.all) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
for (const tile of desktop_picture_1.DesktopPicture.touched(this.view, rect)) {
|
|
169
|
+
this.pending.tiles.add(tile);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
sized() {
|
|
173
|
+
this.pending.size = true;
|
|
174
|
+
this.pending.all = true;
|
|
175
|
+
}
|
|
176
|
+
cursorChanged() {
|
|
177
|
+
this.pending.cursor = true;
|
|
178
|
+
}
|
|
179
|
+
/** Something its page should hear of (control, the link). */
|
|
180
|
+
news() {
|
|
181
|
+
this.pending.news = true;
|
|
182
|
+
this.notify();
|
|
183
|
+
}
|
|
184
|
+
/** An update of the desktop ended: a claim that waits answers now. */
|
|
185
|
+
updated() {
|
|
186
|
+
if (this.ready) {
|
|
187
|
+
this.notify();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
get ready() {
|
|
191
|
+
const { pending } = this;
|
|
192
|
+
return pending.all || pending.tiles.size > 0 || pending.size || pending.cursor || pending.news;
|
|
193
|
+
}
|
|
194
|
+
/** Ends what waits: the viewer closed. */
|
|
195
|
+
stop() {
|
|
196
|
+
this.stopped = true;
|
|
197
|
+
clearTimeout(this.pacing);
|
|
198
|
+
this.pacing = undefined;
|
|
199
|
+
this.outgoing = [];
|
|
200
|
+
this.notify();
|
|
201
|
+
}
|
|
202
|
+
/** What it has to tell, taken: the next frame starts from nothing. */
|
|
203
|
+
take() {
|
|
204
|
+
const taken = this.pending;
|
|
205
|
+
this.pending = fresh();
|
|
206
|
+
return taken;
|
|
207
|
+
}
|
|
208
|
+
/** What it took and could not tell (the view changed while it was made): told with the next. */
|
|
209
|
+
putBack(taken) {
|
|
210
|
+
var _a, _b, _c, _d;
|
|
211
|
+
(_a = this.pending).all || (_a.all = taken.all);
|
|
212
|
+
(_b = this.pending).size || (_b.size = taken.size);
|
|
213
|
+
(_c = this.pending).cursor || (_c.cursor = taken.cursor);
|
|
214
|
+
(_d = this.pending).news || (_d.news = taken.news);
|
|
215
|
+
for (const tile of taken.tiles) {
|
|
216
|
+
this.pending.tiles.add(tile);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The JPEG quality for this many tiles of the view: the whole screen changing (a scroll, a video) at less, so that
|
|
221
|
+
* frames keep coming; a little change crisper. `crisp` and `smooth` hold it up or down.
|
|
222
|
+
*/
|
|
223
|
+
qualityFor(tiles) {
|
|
224
|
+
if (this.quality === 'crisp') {
|
|
225
|
+
return 85;
|
|
226
|
+
}
|
|
227
|
+
if (this.quality === 'smooth') {
|
|
228
|
+
return 50;
|
|
229
|
+
}
|
|
230
|
+
const { columns, rows } = this.view ? desktop_picture_1.DesktopPicture.grid(this.view) : { columns: 1, rows: 1 };
|
|
231
|
+
return tiles > columns * rows * 0.25 ? 60 : 80;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Input of a batch into RFB, in the framebuffer's coordinates; keys and buttons it holds are remembered. It goes in
|
|
235
|
+
* order, each change of the buttons (a press, a release, a notch of the wheel) DESKTOP_BUTTON_GAP_MS after the one
|
|
236
|
+
* before: the Screen Sharing of macOS keeps only the last state of the pointer of what comes at once, so that a
|
|
237
|
+
* click sent in one batch never clicked.
|
|
238
|
+
*/
|
|
239
|
+
apply(client, events) {
|
|
240
|
+
this.client = client;
|
|
241
|
+
for (const event of events) {
|
|
242
|
+
if (event.kind === 'pointer') {
|
|
243
|
+
this.buttons = (Number(event.buttons) || 0) & 7;
|
|
244
|
+
this.outgoing.push({ kind: 'pointer', x: Number(event.x) || 0, y: Number(event.y) || 0, buttons: this.buttons });
|
|
245
|
+
}
|
|
246
|
+
else if (event.kind === 'wheel') {
|
|
247
|
+
const x = Number(event.x) || 0;
|
|
248
|
+
const y = Number(event.y) || 0;
|
|
249
|
+
// RFB scrolls by buttons 4 and 5 (up, down), 6 and 7 (left, right), each a press and a release a notch;
|
|
250
|
+
// notches beyond those waiting already are dropped, so that a scroll stops when the fingers do.
|
|
251
|
+
let room = DESKTOP_QUEUED_NOTCHES - this.outgoing.filter(one => one.kind === 'pointer' && one.buttons & WHEEL).length;
|
|
252
|
+
const notch = (count, bit) => {
|
|
253
|
+
for (let index = 0; index < count && room > 0; index++, room--) {
|
|
254
|
+
this.outgoing.push({ kind: 'pointer', x, y, buttons: this.buttons | bit }, { kind: 'pointer', x, y, buttons: this.buttons });
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const notches = (delta) => Math.min(10, Math.max(0, Math.round(Math.abs(delta))));
|
|
258
|
+
const vertical = Number(event.dy) || 0;
|
|
259
|
+
const horizontal = Number(event.dx) || 0;
|
|
260
|
+
notch(notches(vertical), vertical < 0 ? 8 : 16);
|
|
261
|
+
notch(notches(horizontal), horizontal < 0 ? 32 : 64);
|
|
262
|
+
}
|
|
263
|
+
else if (event.kind === 'key') {
|
|
264
|
+
const keysym = Number(event.keysym) >>> 0;
|
|
265
|
+
if (!keysym) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (event.down) {
|
|
269
|
+
this.keys.add(keysym);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
this.keys.delete(keysym);
|
|
273
|
+
}
|
|
274
|
+
this.outgoing.push({ kind: 'key', keysym, down: !!event.down });
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
this.lastInputAt = Date.now();
|
|
278
|
+
this.send();
|
|
279
|
+
}
|
|
280
|
+
/** Lets go of what it holds: it lost control, or closed. */
|
|
281
|
+
letGo(client, at) {
|
|
282
|
+
clearTimeout(this.pacing);
|
|
283
|
+
this.pacing = undefined;
|
|
284
|
+
this.outgoing = [];
|
|
285
|
+
if (client) {
|
|
286
|
+
for (const keysym of this.keys) {
|
|
287
|
+
client.key(keysym, false);
|
|
288
|
+
}
|
|
289
|
+
if (this.sentButtons) {
|
|
290
|
+
client.pointer(at.x, at.y, 0);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
this.keys.clear();
|
|
294
|
+
this.buttons = 0;
|
|
295
|
+
this.sentButtons = 0;
|
|
296
|
+
}
|
|
297
|
+
/** Sends what waits, up to a change of the buttons too soon after the last: the rest goes when it may. */
|
|
298
|
+
send() {
|
|
299
|
+
clearTimeout(this.pacing);
|
|
300
|
+
this.pacing = undefined;
|
|
301
|
+
const client = this.client;
|
|
302
|
+
while (client && this.outgoing.length > 0) {
|
|
303
|
+
const next = this.outgoing[0];
|
|
304
|
+
if (next.kind === 'pointer' && next.buttons !== this.sentButtons) {
|
|
305
|
+
const wait = this.buttonsAt + exports.DESKTOP_BUTTON_GAP_MS - Date.now();
|
|
306
|
+
if (wait > 0) {
|
|
307
|
+
this.pacing = setTimeout(() => this.send(), wait);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
this.buttonsAt = Date.now();
|
|
311
|
+
}
|
|
312
|
+
this.outgoing.shift();
|
|
313
|
+
if (next.kind === 'pointer') {
|
|
314
|
+
this.sentButtons = next.buttons;
|
|
315
|
+
client.pointer(next.x, next.y, next.buttons);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
client.key(next.keysym, next.down);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
wait(ms) {
|
|
323
|
+
return new Promise(resolve => {
|
|
324
|
+
const timer = setTimeout(done, ms);
|
|
325
|
+
const previous = this.wake;
|
|
326
|
+
function done() {
|
|
327
|
+
clearTimeout(timer);
|
|
328
|
+
resolve();
|
|
329
|
+
}
|
|
330
|
+
this.wake = () => {
|
|
331
|
+
previous === null || previous === void 0 ? void 0 : previous();
|
|
332
|
+
done();
|
|
333
|
+
};
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
notify() {
|
|
337
|
+
const wake = this.wake;
|
|
338
|
+
this.wake = undefined;
|
|
339
|
+
wake === null || wake === void 0 ? void 0 : wake();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
exports.DesktopViewer = DesktopViewer;
|
|
343
|
+
//# sourceMappingURL=desktop-viewer.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './desktop-picture';
|
|
2
|
+
export * from './desktop-session';
|
|
3
|
+
export * from './desktop-targets';
|
|
4
|
+
export * from './desktop-viewer';
|
|
5
|
+
export * from './rfb-client';
|
|
6
|
+
export * from './rfb-protocol';
|
|
7
|
+
export * from './screen-share-server-impl';
|
|
8
|
+
export * from './screen-shares';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./desktop-picture"), exports);
|
|
18
|
+
__exportStar(require("./desktop-session"), exports);
|
|
19
|
+
__exportStar(require("./desktop-targets"), exports);
|
|
20
|
+
__exportStar(require("./desktop-viewer"), exports);
|
|
21
|
+
__exportStar(require("./rfb-client"), exports);
|
|
22
|
+
__exportStar(require("./rfb-protocol"), exports);
|
|
23
|
+
__exportStar(require("./screen-share-server-impl"), exports);
|
|
24
|
+
__exportStar(require("./screen-shares"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ExecSocket } from '@celljs/ta-exec';
|
|
2
|
+
import { RfbDecoders } from './rfb-encodings';
|
|
3
|
+
import { RfbFramebuffer } from './rfb-framebuffer';
|
|
4
|
+
import { type RfbClientEvents, type RfbClientOptions, type RfbScreen } from './rfb-protocol';
|
|
5
|
+
import { RfbReader } from './rfb-reader';
|
|
6
|
+
/** What a server said it is once Ta was let in. */
|
|
7
|
+
export interface RfbServerInit {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A client of RFB 3.8 (also 3.7 and 3.3) on a socket of an ExecEnvironment (docs/design/ta-desktop-remote.md 3): signs
|
|
14
|
+
* in, keeps the framebuffer, and asks for the next update only when the last has been taken (`request`), which is
|
|
15
|
+
* all the flow control RFB has.
|
|
16
|
+
*/
|
|
17
|
+
export declare class RfbClient {
|
|
18
|
+
protected readonly socket: ExecSocket;
|
|
19
|
+
protected readonly options: RfbClientOptions;
|
|
20
|
+
readonly reader: RfbReader;
|
|
21
|
+
readonly framebuffer: RfbFramebuffer;
|
|
22
|
+
screens: RfbScreen[];
|
|
23
|
+
/** The server told its screens (ExtendedDesktopSize). */
|
|
24
|
+
extended: boolean;
|
|
25
|
+
name: string;
|
|
26
|
+
protected decoders?: RfbDecoders;
|
|
27
|
+
protected closed: boolean;
|
|
28
|
+
protected events?: RfbClientEvents;
|
|
29
|
+
/** An update was asked for and has not come. */
|
|
30
|
+
protected asked: boolean;
|
|
31
|
+
constructor(socket: ExecSocket, options: RfbClientOptions);
|
|
32
|
+
/** Signs in and reads the first size; `run` then reads updates. */
|
|
33
|
+
connect(): Promise<RfbServerInit>;
|
|
34
|
+
/** Reads what the server sends until the connection ends; the first update asked is the whole screen. */
|
|
35
|
+
run(events: RfbClientEvents): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Asks for the next update: incremental, what changed since the last; the server answers once something did. One
|
|
38
|
+
* at a time: a page that is slow asks later, and what changed meanwhile comes as one.
|
|
39
|
+
*/
|
|
40
|
+
request(incremental?: boolean): void;
|
|
41
|
+
pointer(x: number, y: number, buttons: number): void;
|
|
42
|
+
key(keysym: number, down: boolean): void;
|
|
43
|
+
/** Text into the clipboard of the desktop: Latin-1, as RFB has it; other characters become ?. */
|
|
44
|
+
clipboard(text: string): void;
|
|
45
|
+
protected closedByUs: boolean;
|
|
46
|
+
close(): void;
|
|
47
|
+
/** Ended by Ta, not lost: `closed` says no error. */
|
|
48
|
+
end(): void;
|
|
49
|
+
protected update(events: RfbClientEvents): Promise<void>;
|
|
50
|
+
protected resize(width: number, height: number, screens: RfbScreen[]): void;
|
|
51
|
+
protected colourMap(): Promise<void>;
|
|
52
|
+
protected cutText(): Promise<string>;
|
|
53
|
+
protected send(bytes: Uint8Array): void;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=rfb-client.d.ts.map
|