Skip to content

Commit

Permalink
feat!: Compatibility with REPL's generic server interface
Browse files Browse the repository at this point in the history
This reverts commit fdc9700.
  • Loading branch information
radrow authored Jan 9, 2024
1 parent fdc9700 commit bfaf098
Show file tree
Hide file tree
Showing 11 changed files with 4,460 additions and 12,634 deletions.
26 changes: 13 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,47 @@

* nodejs build ([7621a94](https://github.com/aeternity/aerepl-web/commit/7621a942837ceba2c131e2450475849cff489d23))

## [2.2.0](https://github.com/aeternity/aerepl_web/compare/v2.1.3...v2.2.0) (2022-09-14)
## [2.2.0](https://github.com/aeternity/aerepl-web/compare/v2.1.3...v2.2.0) (2022-09-14)


### Features

* triggere release please ([28e1d95](https://github.com/aeternity/aerepl_web/commit/28e1d959937197e0e23949400904d56819fe2566))
* triggere release please ([28e1d95](https://github.com/aeternity/aerepl-web/commit/28e1d959937197e0e23949400904d56819fe2566))


### Bug Fixes

* release ([#37](https://github.com/aeternity/aerepl_web/issues/37)) ([ae33ec3](https://github.com/aeternity/aerepl_web/commit/ae33ec39216a7a188f92cae6f5f0e882152863d7))
* release ([#37](https://github.com/aeternity/aerepl-web/issues/37)) ([ae33ec3](https://github.com/aeternity/aerepl-web/commit/ae33ec39216a7a188f92cae6f5f0e882152863d7))

## [2.1.3](https://github.com/aeternity/aerepl_web/compare/v2.1.2...v2.1.3) (2022-09-13)
## [2.1.3](https://github.com/aeternity/aerepl-web/compare/v2.1.2...v2.1.3) (2022-09-13)


### CI / CD

* **build:** try to provide the elixir file name for release plugin ([#34](https://github.com/aeternity/aerepl_web/issues/34)) ([9e4b523](https://github.com/aeternity/aerepl_web/commit/9e4b52386c9a5d25b5b0fb389542f1d78396c6c1))
* **build:** try to provide the elixir file name for release plugin ([#34](https://github.com/aeternity/aerepl-web/issues/34)) ([9e4b523](https://github.com/aeternity/aerepl-web/commit/9e4b52386c9a5d25b5b0fb389542f1d78396c6c1))


### Miscellaneous

* release 2.3.0 ([#36](https://github.com/aeternity/aerepl_web/issues/36)) ([09bfb6c](https://github.com/aeternity/aerepl_web/commit/09bfb6c527d70970d2fd4b5415b1b8bff0e31210))
* release 2.3.0 ([#36](https://github.com/aeternity/aerepl-web/issues/36)) ([09bfb6c](https://github.com/aeternity/aerepl-web/commit/09bfb6c527d70970d2fd4b5415b1b8bff0e31210))

## [2.1.2](https://github.com/aeternity/aerepl_web/compare/v2.1.1...v2.1.2) (2022-09-06)
## [2.1.2](https://github.com/aeternity/aerepl-web/compare/v2.1.1...v2.1.2) (2022-09-06)


### CI / CD

* **build:** fix dockerhub repo name ([#29](https://github.com/aeternity/aerepl_web/issues/29)) ([3488a07](https://github.com/aeternity/aerepl_web/commit/3488a0781fd3c303d8fdbd901c81a90dbf0f17c2))
* **build:** try context path for docker build step ([#32](https://github.com/aeternity/aerepl_web/issues/32)) ([e0ea337](https://github.com/aeternity/aerepl_web/commit/e0ea337af4931fb62470721085e8cd4426ebf02d))
* **build:** fix dockerhub repo name ([#29](https://github.com/aeternity/aerepl-web/issues/29)) ([3488a07](https://github.com/aeternity/aerepl-web/commit/3488a0781fd3c303d8fdbd901c81a90dbf0f17c2))
* **build:** try context path for docker build step ([#32](https://github.com/aeternity/aerepl-web/issues/32)) ([e0ea337](https://github.com/aeternity/aerepl-web/commit/e0ea337af4931fb62470721085e8cd4426ebf02d))

## [2.1.1](https://github.com/aeternity/aerepl_web/compare/v2.1.0...v2.1.1) (2022-09-03)
## [2.1.1](https://github.com/aeternity/aerepl-web/compare/v2.1.0...v2.1.1) (2022-09-03)


### Bug Fixes

* **docker:** fix Dockerfile ([#17](https://github.com/aeternity/aerepl_web/issues/17)) ([33b9cff](https://github.com/aeternity/aerepl_web/commit/33b9cffb5e047d9c1d344d63fc97376ef697917c))
* **docker:** fix Dockerfile ([#17](https://github.com/aeternity/aerepl-web/issues/17)) ([33b9cff](https://github.com/aeternity/aerepl-web/commit/33b9cffb5e047d9c1d344d63fc97376ef697917c))


### CI / CD

* **build:** fix release please type ([#26](https://github.com/aeternity/aerepl_web/issues/26)) ([a0b4713](https://github.com/aeternity/aerepl_web/commit/a0b47136cdfa04c2e1e666c478e7ce1fbc29037e))
* **build:** fix the pipeline gitops folder ([#28](https://github.com/aeternity/aerepl_web/issues/28)) ([760744f](https://github.com/aeternity/aerepl_web/commit/760744fea7cc94d5ccaaaad03f400a3b68004d8b))
* **build:** fix release please type ([#26](https://github.com/aeternity/aerepl-web/issues/26)) ([a0b4713](https://github.com/aeternity/aerepl-web/commit/a0b47136cdfa04c2e1e666c478e7ce1fbc29037e))
* **build:** fix the pipeline gitops folder ([#28](https://github.com/aeternity/aerepl-web/issues/28)) ([760744f](https://github.com/aeternity/aerepl-web/commit/760744fea7cc94d5ccaaaad03f400a3b68004d8b))
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ WORKDIR /app

ENV MIX_ENV prod
RUN mkdir -p /etc/profile.d \
&& bash -l -c 'echo export SECRET_KEY_BASE="$(openssl rand -hex 64)" >> /etc/profile.d/aerepl-web.sh'
&& KEY_BASE="$(openssl rand -hex 64)" \
&& echo export SECRET_KEY_BASE=$KEY_BASE >> /etc/profile.d/aerepl-web.sh
ENV CXXFLAGS "-Wno-error=shadow -Wno-deprecated-copy -Wno-redundant-move -Wno-pessimizing-move"

RUN mix local.rebar --force \
Expand Down
82 changes: 63 additions & 19 deletions assets/js/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import {Socket} from "phoenix";
var AU = require('ansi_up');
var ansi = new AU.default;

let socket = new Socket("/socket", {params: {token: window.userToken}});
socket.connect();

let channel = socket.channel("repl_session:lobby", {});
var disabled = true;
var session = null;

let currentPrompt = document.getElementById("prompt");
let queryInput = document.getElementById("query-input");
Expand All @@ -20,9 +18,33 @@ let submitButton = document.getElementById("submit");
let contractEditor = document.getElementById("editor");
let loadButton = document.getElementById("load");

var session = null;
disableInput();

let socket = new Socket("/socket", {params: {token: window.userToken}});
socket.connect();

let channel = socket.channel("repl_session:lobby", {});

function enableInput() {
queryInput.disabled = false;
newlineButton.disabled = false;
submitButton.disabled = false;
contractEditor.disabled = false;
loadButton.disabled = false;
disabled = false;
}

function disableInput() {
queryInput.disabled = true;
newlineButton.disabled = true;
submitButton.disabled = true;
contractEditor.disabled = true;
loadButton.disabled = true;
disabled = true;
}

function handle_response(payload) {
console.log("Received response.");
var msg = payload.msg;
var last_prompt = currentPrompt.innerText;
var prompt = payload.prompt ? payload.prompt : last_prompt;
Expand All @@ -37,6 +59,8 @@ function handle_response(payload) {
}

function submitQuery() {
if(disabled) return;

let query = queryInput.value.trim();
let prompt = currentPrompt.innerText + "> ";

Expand All @@ -45,14 +69,17 @@ function submitQuery() {
messageItem.classList.add("in");
outputContainer.appendChild(messageItem);

channel.push("query", {input: query,
var t =channel.push("query", {input: query,
user_session: session
})
.receive("ok", handle_response);
.receive("ok", handle_response)
.receive("error", handle_response); // TODO why isn't this working?
queryInput.value = "";
}

function insertNewLine() {
if(disabled) return;

let pos = queryInput.selectionStart;
let input = queryInput.value;
let left = input.substr(0, pos);
Expand All @@ -63,12 +90,19 @@ function insertNewLine() {
}

function loadFiles() {
if(disabled) return;

let contract = contractEditor.value;
channel.push("load", {files: [{filename: "contract.aes",
content: contract
}],
user_session: session
});
channel.push("update_files",
{files: [{filename: "contract.aes",
content: contract
}],
user_session: session
});
channel.push("load",
{files: ["contract.aes"],
user_session: session
});
}

function log_response(msg) {
Expand All @@ -80,7 +114,7 @@ function log_response(msg) {
}

function update_prompt(prompt) {
let prompt_text = prompt + "> ";
let prompt_text = prompt;
currentPrompt.innerText = prompt_text;
queryInput.placeholder = prompt_text;
}
Expand All @@ -95,19 +129,29 @@ queryInput.addEventListener("keypress", event => {
}
});

channel.on("response", payload => {
handle_response(payload)
channel.onError( (e) => {
console.log("Channel error:", e);
update_prompt("(ERROR)");
disableInput();
});

channel.onError( () => alert("Channel error.") );
channel.onClose( () => {
console.log("Channel closed");
update_prompt("(CLOSED)");
alert("The channel has been closed. Please refresh to start a new session.");
disableInput();
});


channel.join()
.receive("ok", resp => { console.log("Joined aerepl lobby."); })
.receive("ok", resp => {
console.log("Joined aerepl lobby.");
session = resp.user_session;
console.log("Session: ", session);
var t = channel.push("banner", {user_session: session})
.receive("ok", handle_response);
console.log("Session established.");
enableInput();

})
.receive("error", resp => {
update_prompt("(CHANNEL ERROR)");
alert("Could not establish the connection.");
Expand Down
Loading

0 comments on commit bfaf098

Please sign in to comment.