Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public void startConsole(StartConsoleRequest request, StreamObserver<StartConsol
scriptSession = globalSessionProvider.getGlobalSession();
} else {
scriptSession = new NoLanguageDeephavenSession(sessionType);
log.error().append("Session type '" + sessionType + "' is disabled. " +
"Use the More Actions icon to swap to session type '" + WORKER_CONSOLE_TYPE + "'.").endl();
log.error().append("Session type '" + sessionType + "' is disabled." +
"Use the session type '" + WORKER_CONSOLE_TYPE + "' instead.").endl();
}

safelyExecute(() -> {
Expand Down

This file was deleted.

8 changes: 8 additions & 0 deletions web/WebDevelopersGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,9 @@ This enum describes the name of each supported operation/aggregation type when c

##### Class `IdeConnection`

###### Constructor
* `new dh.IdeConnection(String websocketUrl, IdeConnectionOptions options)` - creates a new instance, from which console sessions can be made. `options` are optional.

###### Methods

* `addEventListener(String eventType, Function eventListener)`
Expand All @@ -1113,6 +1116,11 @@ This enum describes the name of each supported operation/aggregation type when c
* `String websocketUrl` - the url used when connecting to the server. Read-only.
* `String serviceId` - The name of the service that should be authenticated to on the server. Read-only.

##### Class `IdeConnectionOptions`
###### Properties
* `String authToken` - base 64 encoded auth token
* `String serviceId` - The service ID to use for the connection

##### Class `IdeSession`

###### Methods
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.deephaven.web.client.api;

import elemental2.core.JsArray;
import elemental2.core.JsSet;
import elemental2.dom.DomGlobal;
import elemental2.promise.Promise;
import io.deephaven.ide.shared.IdeSession;
import io.deephaven.javascript.proto.dhinternal.arrow.flight.protocol.flight_pb.Ticket;
import io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.GetConsoleTypesRequest;
import io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.GetConsoleTypesResponse;
import io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.StartConsoleRequest;
import io.deephaven.web.client.fu.CancellablePromise;
import io.deephaven.web.client.fu.JsLog;
Expand Down Expand Up @@ -166,6 +169,17 @@ public CancellablePromise<IdeSession> startSession(String type) {
}, closer);
}

@JsMethod
public Promise<JsArray<String>> getConsoleTypes() {
Promise<GetConsoleTypesResponse> promise = Callbacks.grpcUnaryPromise(callback -> {
GetConsoleTypesRequest request = new GetConsoleTypesRequest();
connection.get().consoleServiceClient().getConsoleTypes(request, connection.get().metadata(), callback::apply);
});

return promise.then(result -> Promise.resolve(result.getConsoleTypesList()));
}


public void connected() {
if (closed) {
JsLog.debug(getClass(), " closed before worker could connect");
Expand Down
13 changes: 10 additions & 3 deletions web/client-api/src/main/java/io/deephaven/web/public/console.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@
<textarea id="command" placeholder="waiting for connection..." rows="1" cols="80" autofocus="autofocus" disabled="disabled" style="resize:vertical"></textarea><button id="run">Run</button>
</div>
<script type="text/javascript">
var connection;
var ide;
var table;
(async () => {
// create a connection to the server
connection = new dh.IdeConnection(window.location.protocol + "//" + window.location.host);

// check if a language was specified
var url = new URL(window.location);
var language = url.searchParams.get("language");
if (typeof language !== 'string') {
url.searchParams.set("language", "groovy");
// Language was not specified, query the server to get the supported languages and use the first one
var consoleTypes = await connection.getConsoleTypes();
language = consoleTypes[0];
url.searchParams.set("language", language);
location.assign(url.toString());
}

// create a connection to the server using that language
ide = await dh.Ide.getExistingSession(window.location.protocol + "//" + window.location.host, "", null, language);
// start a session using the language derived
ide = await connection.startSession(language);

// set up log stream
ide.onLogMessage(log => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2>Feature Demos</h2>
<ul>
<!-- <li><a href="grpc.html">Raw GRPC sample in JS</a></li>-->
<!-- <li><a href="simple.html">JS API analog of the SimpleDeephavenClient</a></li>-->
<li><a href="console.html">JS API analog of the GroovyConsoleClient</a></li>
<li><a href="console.html">JS API analog of the ConsoleClient</a></li>
<li><a href="table_viewport.html">Create a table and display a viewport of it, with paging buttons</a></li>
<li><a href="table_filter.html">Create a table and display a viewport of it, with a filter context menu</a></li>
<li><a href="table_sort.html">Create a table and display a viewport of it, with clickable headers to sort</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ <h3>Simple test page to verify that the Deephaven JS API can connect, create a t
var ide;
var table;
(async () => {

ide = await dh.Ide.getExistingSession(window.location.protocol + "//" + window.location.host, "", null, "groovy");
var connection = new dh.IdeConnection(window.location.protocol + "//" + window.location.host);
var consoleTypes = await connection.getConsoleTypes();
ide = await connection.startSession(consoleTypes[0]);
document.body.append("session created", document.createElement("br"));
table = await ide.timeTable(1_000_000_000);
document.body.append("timetable created", document.createElement("br"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,17 @@ <h3>Filter Details</h3>

};

var connection;
var ide;
var table;
var oldTableHandlerCleanup;
var simplePagingTable = document.getElementById('simplePagingTable');
var topMenu = document.getElementById('topMenu');

(async () => {
ide = await dh.Ide.getExistingSession(window.location.protocol + "//" + window.location.host, "", null, "groovy");
connection = new dh.IdeConnection(window.location.protocol + "//" + window.location.host);

ide = await connection.startSession("groovy");

await ide.runCode('remoteTable = timeTable("00:00:01").updateView("I=i", "J=I*I", "K=I%100").lastBy("K")')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ <h3>Selected table data (click headers to sort)</h3>
<table id="simplePagingTable"></table>

<script>
var connection;
var ide;
var table;
var oldTableHandlerCleanup;
var simplePagingTable = document.getElementById("simplePagingTable");
(async () => {
ide = await dh.Ide.getExistingSession(window.location.protocol + "//" + window.location.host, "", null, "groovy");
connection = new dh.IdeConnection(window.location.protocol + "//" + window.location.host);

ide = await connection.startSession("groovy");

await ide.runCode('remoteTable = timeTable("00:00:01").updateView("I=i", "J=I*I", "K=I%100").lastBy("K")')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ <h3>Table data</h3>

<script>
var table;
var ide
var connection;
var ide;
var simplePagingTable = document.getElementById('simplePagingTable');
var oldTableHandlerCleanup;
var currentOffset;
var PAGE_SIZE = 20;
(async () => {
ide = await dh.Ide.getExistingSession(window.location.protocol + "//" + window.location.host, "", null, "groovy");
connection = new dh.IdeConnection(window.location.protocol + "//" + window.location.host);

ide = await connection.startSession("groovy");

await ide.runCode('remoteTable = timeTable("00:00:01").updateView("I=i", "J=I*I", "K=I%100").lastBy("K")')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,25 @@
import elemental2.promise.Promise;
import io.deephaven.ide.shared.IdeSession;
import io.deephaven.web.client.fu.CancellablePromise;
import io.deephaven.web.shared.data.ConnectToken;
import io.deephaven.web.shared.ide.ConsoleAddress;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

import java.nio.charset.StandardCharsets;

/**
*/
@JsType(name = "Ide", namespace = "dh")
public class IdeClient {
@JsMethod(namespace = JsPackage.GLOBAL)
private static native String atob(String encodedData);

@Deprecated
@JsMethod(name = "getExistingSession")
public Promise<IdeSession> getExistingSession_old(String websocketUrl, String authToken, String serviceId, String language) {
return IdeClient.getExistingSession(websocketUrl, authToken, serviceId, language);
}

public static CancellablePromise<IdeSession> getExistingSession(String websocketUrl, String authToken, String serviceId, String language) {
ConnectToken token = null;
if (authToken != null) {
token = new ConnectToken();
token.setBytes(atob(authToken).getBytes(StandardCharsets.ISO_8859_1));
}

ConsoleAddress address = new ConsoleAddress();
address.setWebsocketUrl(websocketUrl);
address.setServiceId(serviceId);
address.setToken(token);
IdeConnectionOptions options = new IdeConnectionOptions();
options.authToken = authToken;
options.serviceId = serviceId;

IdeConnection ideConnection = new IdeConnection(address);
IdeConnection ideConnection = new IdeConnection(websocketUrl, options);
return ideConnection.startSession(language);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@
import elemental2.promise.Promise;
import io.deephaven.web.client.api.QueryConnectable;
import io.deephaven.web.shared.fu.JsRunnable;
import io.deephaven.web.shared.ide.ConsoleAddress;
import jsinterop.annotations.JsIgnore;
import jsinterop.annotations.JsType;
import io.deephaven.web.shared.data.ConnectToken;
import jsinterop.annotations.*;

import java.nio.charset.StandardCharsets;

/**
*/
@JsType(namespace = "dh")
public class IdeConnection extends QueryConnectable<IdeConnection> {
private final ConsoleAddress address;
@JsMethod(namespace = JsPackage.GLOBAL)
private static native String atob(String encodedData);

private static AuthTokenPromiseSupplier getAuthTokenPromiseSupplier(IdeConnectionOptions options) {
ConnectToken token = null;
if (options != null && options.authToken != null) {
token = new ConnectToken();
token.setBytes(atob(options.authToken).getBytes(StandardCharsets.UTF_8));
}
return AuthTokenPromiseSupplier.oneShot(token);
}

private final String serverUrl;

private final JsRunnable deathListenerCleanup;

@Override
Expand All @@ -22,10 +36,10 @@ protected String logPrefix() {
/**
* Direct connection to an already-running worker instance, without first authenticating to a client.
*/
@JsIgnore
public IdeConnection(ConsoleAddress address) {
super(AuthTokenPromiseSupplier.oneShot(address.getToken()));
this.address = address;
@JsConstructor
public IdeConnection(String serverUrl, @JsOptional IdeConnectionOptions options) {
super(getAuthTokenPromiseSupplier(options));
this.serverUrl = serverUrl;
this.deathListenerCleanup = JsRunnable.doNothing();
}

Expand All @@ -38,7 +52,7 @@ public void close() {
@Override
@JsIgnore
public String getServerUrl() {
return address.getWebsocketUrl();
return serverUrl;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.deephaven.ide.client;

import jsinterop.annotations.JsConstructor;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;

@JsType(namespace = "dh")
public class IdeConnectionOptions {
public String authToken;
public String serviceId;

@JsConstructor
public IdeConnectionOptions() {
}
}