Skip to content

Start Langium as standalone server #471

Answered by spoenemann
theogiraudet asked this question in Q&A
Discussion options

You must be logged in to vote

You can connect Langium directly to a WebSocket with a custom message reader / writer. The following snippet is based on the ws package:

class WebSocketMessageWriter extends AbstractMessageWriter {
    private readonly ws: WebSocket;

    constructor(ws: WebSocket) {
        super();
        this.ws = ws;
    }

    write(msg: Message): Promise<void> {
        return new Promise((resolve, reject) => {
            const content = JSON.stringify(msg);
            this.ws.send(content, err => {
                if (err) {
                    reject(err);
                } else {
                    resolve();
                }
            });
        });
    }

    end(): void {}
}

class Web…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
7 replies
@theogiraudet
Comment options

@msujew
Comment options

@theogiraudet
Comment options

@spoenemann
Comment options

@theogiraudet
Comment options

Comment options

You must be logged in to vote
1 reply
@theogiraudet
Comment options

Answer selected by theogiraudet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants