-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathlib.w
55 lines (47 loc) · 1.38 KB
/
lib.w
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
bring util;
bring cloud;
bring ui;
bring "./commons/api.w" as api;
bring "./platform/awscdk.w" as awscdk;
bring "./platform/tf-aws.w" as tfaws;
bring "./platform/sim.w" as sim;
pub class WebSocket impl api.IWebSocket {
inner: api.IWebSocket;
pub url: str;
new(props: api.WebSocketProps) {
let target = util.env("WING_TARGET");
if target == "tf-aws" {
let ws = new tfaws.WebSocket_tfaws(props) as props.name;
this.url = ws.url;
this.inner = ws;
} else if target == "awscdk" {
let ws = new awscdk.WebSocket_awscdk(props) as props.name;
this.url = ws.url;
this.inner = ws;
} else if target == "sim" {
let ws = new sim.WebSocket_sim(props) as props.name;
this.url = ws.url;
this.inner = ws;
} else {
throw "unsupported target {target}";
}
let inner = nodeof(this.inner);
inner.hidden = true;
new ui.Field("url", inflight () => {
return this.url;
});
new cloud.Endpoint(this.url);
}
pub onConnect(handler: inflight(str): void): void {
this.inner.onConnect(handler);
}
pub onDisconnect(handler: inflight(str): void): void {
this.inner.onDisconnect(handler);
}
pub onMessage(handler: inflight(str, str): void): void {
this.inner.onMessage(handler);
}
pub inflight sendMessage(connectionId: str, message: str) {
this.inner.sendMessage(connectionId, message);
}
}