Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fastify example, updating ws package, fix ws closing #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions docs/advanced-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,8 @@ The `examples` directory within the `guacamole-lite` project contains the follow
language of choice.
- [expressjs.js](../examples/expressjs.js): Illustrates how to integrate `guacamole-lite` with an Express.js application, combining web server
functionality with remote desktop capabilities.
- [fastify.js](../examples/fastify.js): Illustrates how to integrate `guacamole-lite` with a Fastify application, combining web server
functionality with remote desktop capabilities.

These examples are designed to be informative and easily adaptable to your specific use case. Whether you're just
getting started with `guacamole-lite` or looking to implement more complex features, the examples directory is a
Expand Down
29 changes: 29 additions & 0 deletions examples/fastify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env node

import Fastify from 'fastify';
import GuacamoleLite from 'guacamole-lite';

const fastify = Fastify();

const guacdOptions = {
port: 4822,
};

const clientOptions = {
crypt: {
cypher: 'AES-256-CBC',
key: 'MySuperSecretKeyForParamsToken12',
}
};

new GuacamoleLite({ server: fastify.server }, guacdOptions, clientOptions);

process.on('SIGINT', fastify.close);
process.on('SIGTERM', fastify.close);

fastify.listen({ port: 8080 }, function (err) {
if (err) {
console.error(err);
process.exit(1);
}
});
4 changes: 2 additions & 2 deletions lib/ClientConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Crypt = require('./Crypt.js');

class ClientConnection {

constructor(server, connectionId, webSocket) {
constructor(server, connectionId, webSocket, upgradeRequest) {
this.STATE_OPEN = 1;
this.STATE_CLOSED = 2;

Expand All @@ -16,7 +16,7 @@ class ClientConnection {
this.server = server;
this.connectionId = connectionId;
this.webSocket = webSocket;
this.query = Url.parse(this.webSocket.upgradeReq.url, true).query;
this.query = Url.parse(upgradeRequest.url, true).query;
this.lastActivity = Date.now();
this.activityCheckInterval = null;

Expand Down
11 changes: 5 additions & 6 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,15 @@ class Server extends EventEmitter {
this.clientOptions.log.stdLog('Closing all connections and exiting...');
}

this.webSocketServer.close(() => {
this.activeConnections.forEach((activeConnection) => {
activeConnection.close();
});
this.activeConnections.forEach((activeConnection) => {
activeConnection.close();
});
this.webSocketServer.close();
}

newConnection(webSocketConnection) {
newConnection(webSocketConnection, upgradeRequest) {
this.connectionsCount++;
this.activeConnections.set(this.connectionsCount, new ClientConnection(this, this.connectionsCount, webSocketConnection));
this.activeConnections.set(this.connectionsCount, new ClientConnection(this, this.connectionsCount, webSocketConnection, upgradeRequest));
}
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
],
"dependencies": {
"deep-extend": "^0.6.0",
"moment": "^2.17.1",
"ws": "^1.1.2"
"moment": "^2.30.1",
"ws": "^8.17.0"
},
"engines": {
"node": ">=6"
Expand Down