6
6
import com .vertispan .tsdefs .annotations .TsIgnore ;
7
7
import elemental2 .core .JsArray ;
8
8
import elemental2 .core .JsSet ;
9
- import elemental2 .dom .CustomEventInit ;
10
- import elemental2 .dom .DomGlobal ;
11
9
import elemental2 .promise .Promise ;
10
+ import io .deephaven .javascript .proto .dhinternal .grpcweb .Grpc ;
11
+ import io .deephaven .javascript .proto .dhinternal .grpcweb .client .RpcOptions ;
12
12
import io .deephaven .javascript .proto .dhinternal .io .deephaven .proto .session_pb .TerminationNotificationResponse ;
13
+ import io .deephaven .web .client .api .event .HasEventHandling ;
14
+ import io .deephaven .web .client .api .grpc .MultiplexedWebsocketTransport ;
13
15
import io .deephaven .web .client .ide .IdeSession ;
14
16
import io .deephaven .javascript .proto .dhinternal .io .deephaven .proto .console_pb .*;
15
17
import io .deephaven .javascript .proto .dhinternal .io .deephaven .proto .ticket_pb .Ticket ;
26
28
27
29
import java .util .ArrayList ;
28
30
import java .util .List ;
31
+ import java .util .function .BiFunction ;
29
32
30
33
import static io .deephaven .web .client .ide .IdeConnection .HACK_CONNECTION_FAILURE ;
31
34
import static io .deephaven .web .shared .fu .PromiseLike .CANCELLATION_MESSAGE ;
@@ -51,9 +54,9 @@ public QueryConnectable() {
51
54
this .connection = JsLazy .of (() -> new WorkerConnection (this ));
52
55
}
53
56
54
- public abstract Promise < ConnectToken > getConnectToken ();
57
+ public abstract ConnectToken getToken ();
55
58
56
- public abstract Promise < ConnectOptions > getConnectOptions ();
59
+ public abstract ConnectOptions getOptions ();
57
60
58
61
@ Deprecated
59
62
public void notifyConnectionError (ResponseStreamWrapper .Status status ) {
@@ -62,12 +65,10 @@ public void notifyConnectionError(ResponseStreamWrapper.Status status) {
62
65
}
63
66
notifiedConnectionError = true ;
64
67
65
- CustomEventInit <JsPropertyMap <Object >> event = CustomEventInit .create ();
66
- event .setDetail (JsPropertyMap .of (
68
+ fireEvent (HACK_CONNECTION_FAILURE , JsPropertyMap .of (
67
69
"status" , status .getCode (),
68
70
"details" , status .getDetails (),
69
71
"metadata" , status .getMetadata ()));
70
- fireEvent (HACK_CONNECTION_FAILURE , event );
71
72
JsLog .warn (
72
73
"The event dh.IdeConnection.HACK_CONNECTION_FAILURE is deprecated and will be removed in a later release" );
73
74
}
@@ -244,4 +245,28 @@ public void disconnected() {
244
245
}
245
246
246
247
public abstract void notifyServerShutdown (TerminationNotificationResponse success );
248
+
249
+ public boolean useWebsockets () {
250
+ Boolean useWebsockets = getOptions ().useWebsockets ;
251
+ if (useWebsockets == null ) {
252
+ useWebsockets = getServerUrl ().startsWith ("http:" );
253
+ }
254
+ return useWebsockets ;
255
+ }
256
+
257
+ public <T > T createClient (BiFunction <String , Object , T > constructor ) {
258
+ return constructor .apply (getServerUrl (), makeRpcOptions ());
259
+ }
260
+
261
+ public RpcOptions makeRpcOptions () {
262
+ RpcOptions options = RpcOptions .create ();
263
+ options .setDebug (getOptions ().debug );
264
+ if (useWebsockets ()) {
265
+ // Replace with our custom websocket impl, with fallback to the built-in one
266
+ options .setTransport (o -> new MultiplexedWebsocketTransport (o , () -> {
267
+ Grpc .setDefaultTransport .onInvoke (Grpc .WebsocketTransport .onInvoke ());
268
+ }));
269
+ }
270
+ return options ;
271
+ }
247
272
}
0 commit comments