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

fix(express): fixing a version mismatch preventing the server from wo… #2

Open
wants to merge 8 commits into
base: websockets
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
38 changes: 31 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@ notification (e.g. websockets) would most likely be used for the sake of perform

## Building the Demo

1. Set up the OpenDDS environment variables (DDS_ROOT, TAO_ROOT, ACE_ROOT etc)
2. Set up PATH / LD_LIBRARY_PATH to include OpenDDS, TAO, ACE, and MPC binaries
3. Set up the environment variable DEMO_ROOT to point to the root of this repository
4. Generate project files using mwc. Assuming `gnuace`:
1.
- Set up the OpenDDS environment variables (DDS_ROOT, TAO_ROOT, ACE_ROOT etc)
- Set up PATH / LD_LIBRARY_PATH to include OpenDDS, TAO, ACE, and MPC binaries
```
cd <PathToOpenDDS>
source sentenv.sh
cd <pathToThisDemoRoot>
```
2. Set up the environment variable DEMO_ROOT to point to the root of this repository
```
export DEMO_ROOT=$(pwd)
```
3. Generate project files using mwc. Assuming `gnuace`:
```
mwc.pl -type gnuace node-opendds-rest-demo.mwc
```
5. Build C++ IDL library and `control` application. Again, assuming 'gnuace':
4. Build C++ IDL library and `control` application. Again, assuming 'gnuace':
```
make depend && make
```
6. Build Node.js `server` application
5. Build Node.js `server` application
```
cd server
npm install
Expand All @@ -47,12 +56,27 @@ at the same time. Generally speaking, you hopefully shouldn't ever need to resta
2. Run the server application
```
cd server
node main.js -DCPSPendingTimeout 3 -DCPSConfigFile ../rtps.ini
npx ts-node main.ts -DCPSPendingTimeout 3 -DCPSConfigFile ../rtps.ini
```

3. Navigate a javascript-enabled web browser to [http://localhost:3210](http://localhost:3210)

### Multiple Servers

Same as the steps above, though you will obviously need to launch multiple 'server' applications running on different
ports (use the `--port <PORT>` option) as well as have multiple browser tabs open to connect to each of the servers.

### Trouble Shooting

#### Error: Could not load node-opendds addon module
If you are experiencing the following error when starting the server,
```
Error: Could not load node-opendds addon module
```
make that the $PATH is containing all OpenDDS libs. It should look something like:

```
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ubuntu/source/OpenDDS-3.22/ACE_wrappers/bin:/home/ubuntu/source/OpenDDS-3.22/bin
```

fix it by sourcing the OpenDDS `setenv.sh` script, e.g. `source ../OpenDDS-3.2.2/setenv.sh`
116 changes: 116 additions & 0 deletions server/GameControlClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import * as opendds from 'opendds';
import * as path from 'path';

export class GameControlClient {
public playerConnectionWriter = null;
public augmentedPlayerConnectionReader = null;

private factory;
private participant;
private library;

public constructor() {
// Handle exit gracefully
process.on('SIGINT', () => {
console.log("OnSIGINT");
this.finalizeDds();
process.exit(0);
});
process.on('SIGTERM', () => {
console.log("OnSIGTERM");
this.finalizeDds();
process.exit(0);
});
process.on('exit', () => {
console.log("OnExit");
this.finalizeDds();
});
}

public create_player_connection(player_connection_request) {
if (this.playerConnectionWriter) {
console.log("Attempting to write player connection: " + JSON.stringify(player_connection_request));
try {
this.playerConnectionWriter.write(player_connection_request);
return true;
} catch (err) {
console.error(err.message);
}
}
return false;
};

public remove_player_connection(player_connection_request) {
if (this.playerConnectionWriter) {
console.log("Attempting to unregister / dispose player connection: " + JSON.stringify(player_connection_request));
try {
this.playerConnectionWriter.dispose(player_connection_request);
return true;
} catch (err) {
console.error(err.message);
}
}
return false;
};

public subscribe_augmented_player_connections(apc_received, apc_removed) {
try {
var qos = { durability: 'TRANSIENT_LOCAL_DURABILITY_QOS' };
this.augmentedPlayerConnectionReader =
this.participant.subscribe(
'Augmented Player Connections',
'Game::AugmentedPlayerConnection',
qos,
function (dr, sInfo, sample) {
if (sInfo.valid_data) {
apc_received(sample);
} else if (sInfo.instance_state == 2 || sInfo.instance_state == 4) {
console.log("About to call apc_removed for guid '" + JSON.stringify(sample.guid) + '"');
apc_removed(sample.guid);
}
}
);
console.log("successfully created APC reader");
} catch (e) {
console.log(e);
}
};

private finalizeDds() {
if (this.factory) {
console.log("finalizing DDS connection");
if (this.participant) {
this.factory.delete_participant(this.participant);
delete this.participant;
}
opendds.finalize(this.factory);
delete this.factory;
}
};

public initializeDds(argsArray) {
var CONTROL_DOMAIN_ID = 9;
this.factory = opendds.initialize.apply(null, argsArray);
if (!process.env.DEMO_ROOT) {
throw new Error("DEMO_ROOT environment variable not set");
}
this.library = opendds.load(path.join(process.env.DEMO_ROOT, 'lib', 'Game_Idl'));
if (!this.library) {
throw new Error("Could not open type support library");
}
this.participant = this.factory.create_participant(CONTROL_DOMAIN_ID);

try {
var qos = {};
this.playerConnectionWriter =
this.participant.create_datawriter(
'Player Connections',
'Game::PlayerConnection',
qos
);
console.log("successfully created PC writer");
} catch (e) {
console.log(e);
}
};
}
114 changes: 0 additions & 114 deletions server/game_control_client.js

This file was deleted.

Loading