phonesinc 1.0.0 → 1.1.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/dist/index.d.ts +16 -1
- package/dist/index.js +24 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -19,13 +19,28 @@ export declare class PhonesInc {
|
|
|
19
19
|
};
|
|
20
20
|
readonly session: {
|
|
21
21
|
get: OptionalEndpoint<PhoneSelection, Session[]>;
|
|
22
|
-
start: OptionalEndpoint<PhoneSelection
|
|
22
|
+
start: OptionalEndpoint<PhoneSelection & {
|
|
23
|
+
viewId?: string;
|
|
24
|
+
}, PhoneResult<{
|
|
23
25
|
session: Session;
|
|
24
26
|
}>[]>;
|
|
25
27
|
renew: OptionalEndpoint<PhoneSelection, PhoneResult<{
|
|
26
28
|
session: Session;
|
|
27
29
|
}>[]>;
|
|
28
30
|
end: OptionalEndpoint<PhoneSelection, PhoneResult[]>;
|
|
31
|
+
view: {
|
|
32
|
+
close: Endpoint<PhoneTargets & {
|
|
33
|
+
viewId: string;
|
|
34
|
+
}, PhoneResult[]>;
|
|
35
|
+
/** Authenticates in the first frame. Wait for {type:"ready"} before controlling. */
|
|
36
|
+
connect: ((view: {
|
|
37
|
+
phoneId: string;
|
|
38
|
+
viewId: string;
|
|
39
|
+
sessionId: string;
|
|
40
|
+
}, options?: RequestOptions) => Promise<WebSocket>) & {
|
|
41
|
+
readonly endpoint: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
29
44
|
};
|
|
30
45
|
readonly touch: Endpoint<TouchRequest, PhoneResult[]>;
|
|
31
46
|
readonly type: Endpoint<TypeRequest, PhoneResult[]>;
|
package/dist/index.js
CHANGED
|
@@ -93,6 +93,30 @@ export class PhonesInc {
|
|
|
93
93
|
start: this.optional("/v1/session/start"),
|
|
94
94
|
renew: this.optional("/v1/session/renew"),
|
|
95
95
|
end: this.optional("/v1/session/end"),
|
|
96
|
+
view: {
|
|
97
|
+
close: this.required("/v1/session/view/close"),
|
|
98
|
+
/** Authenticates in the first frame. Wait for {type:"ready"} before controlling. */
|
|
99
|
+
connect: named("/v1/session/view/socket", async (view, options = {}) => {
|
|
100
|
+
const token = typeof this.token === "function" ? await this.token() : this.token;
|
|
101
|
+
options.signal?.throwIfAborted();
|
|
102
|
+
const url = new URL(`${this.baseUrl}/v1/session/view/socket`);
|
|
103
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
104
|
+
const socket = new WebSocket(url.toString());
|
|
105
|
+
const abort = () => socket.close();
|
|
106
|
+
options.signal?.addEventListener("abort", abort, { once: true });
|
|
107
|
+
socket.addEventListener("close", () => options.signal?.removeEventListener("abort", abort), { once: true });
|
|
108
|
+
socket.addEventListener("open", () => {
|
|
109
|
+
if (options.signal?.aborted) {
|
|
110
|
+
socket.close();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const organizationId = options.organizationId === undefined ? this.organizationId : options.organizationId;
|
|
114
|
+
socket.send(JSON.stringify({ type: "attach", token, ...view,
|
|
115
|
+
...(organizationId == null ? {} : { organizationId }) }));
|
|
116
|
+
}, { once: true });
|
|
117
|
+
return socket;
|
|
118
|
+
}),
|
|
119
|
+
},
|
|
96
120
|
};
|
|
97
121
|
touch = this.required("/v1/touch");
|
|
98
122
|
type = this.required("/v1/type");
|