[fix] sending messages
This commit is contained in:
parent
0dfcbf17d8
commit
c59edb71a2
6 changed files with 147 additions and 13 deletions
41
webapp/static/ace/esm.html
Normal file
41
webapp/static/ace/esm.html
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en-US">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta name="viewport" content="width=device-width,height=device-height" />
|
||||
<title>BaseX LSP</title>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div>something<button onclick="foo()">send</button><a href="/dba/logs" target="_blank">dba</a></div>
|
||||
<div id="editor" style="height: 100px">some text</div>
|
||||
<script type="module">
|
||||
import * as ace from "https://www.unpkg.com/ace-code@latest/src-noconflict/ace.js";
|
||||
import { Mode as JSONMode } from "ace-code/src/mode/json"; //any mode you want
|
||||
import { AceLanguageClient } from "ace-linters/build/ace-language-client";
|
||||
|
||||
// Create a web socket
|
||||
const serverData = {
|
||||
module: () => import("ace-linters/build/language-client"),
|
||||
modes: "json|json5",
|
||||
type: "socket",
|
||||
socket: new WebSocket("ws://127.0.0.1:3000/exampleServer"), // address of your websocket server
|
||||
}
|
||||
// Create an Ace editor
|
||||
let editor = ace.edit("container", {
|
||||
mode: new JSONMode() // Set the mode of the editor to JSON
|
||||
});
|
||||
|
||||
// Create a language provider for web socket
|
||||
let languageProvider = AceLanguageClient.for(serverData);
|
||||
|
||||
// Register the editor with the language provider
|
||||
languageProvider.registerEditor(editor);
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -32,7 +32,7 @@ const serverData = {
|
|||
module: () => import("https://www.unpkg.com/ace-linters@latest/build/language-client"),
|
||||
modes: "json|json5",
|
||||
type: "socket",
|
||||
socket: new WebSocket("ws://127.0.0.1:3000/exampleServer"), // your websocket server address
|
||||
socket: new WebSocket("ws://127.0.0.1:3000/ws/lsp"), // your websocket server address
|
||||
}
|
||||
|
||||
function opts(editor) {
|
||||
|
|
|
|||
33
webapp/static/ace/socket.html
Normal file
33
webapp/static/ace/socket.html
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en-US">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta name="viewport" content="width=device-width,height=device-height" />
|
||||
<title>BaseX LSP</title>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div>Socket <button onclick="foo()">send</button><a href="/dba/logs" target="_blank">dba</a></div>
|
||||
<script>
|
||||
|
||||
var socket = new WebSocket("ws://127.0.0.1:3000/ws/lsp") // address of your websocket server
|
||||
// Listen for possible errors
|
||||
socket.addEventListener("error", (event) => {
|
||||
console.log("WebSocket error: ", event);
|
||||
});
|
||||
socket.addEventListener("close", (event) => {
|
||||
console.log("closed", event.code, event.reason, event.wasClean);
|
||||
});
|
||||
socket.addEventListener("open", (event) => {
|
||||
setInterval(function ping() { socket.send('{"type":"ping","msg":"staying alive"}'); }, 100000);
|
||||
socket.send('{"type":"ping","msg":"Hello Server!"}');
|
||||
});
|
||||
function foo() {
|
||||
socket.send('{"type":"ping","msg":"foo!"}');
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue