Skip to content
Merged
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
64 changes: 64 additions & 0 deletions .github/workflows/npm-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Publish npm packages
on:
push:
tags: ['node-v*.*.*']

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'

- name: Extract version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/node-v}" >> $GITHUB_OUTPUT

- name: Set package versions
working-directory: Node
run: |
cd ubiq && npm version ${{ steps.version.outputs.VERSION }} --no-git-tag-version && cd ..
cd modules && npm version ${{ steps.version.outputs.VERSION }} --no-git-tag-version && cd ..
cd components && npm version ${{ steps.version.outputs.VERSION }} --no-git-tag-version && cd ..
npm version ${{ steps.version.outputs.VERSION }} --no-git-tag-version

- name: Install dependencies
working-directory: Node
run: npm ci

- name: Build @ucl-vr/ubiq
working-directory: Node/ubiq
run: npm run build

- name: Build modules
working-directory: Node/modules
run: npm run build

- name: Build components
working-directory: Node/components
run: npm run build

- name: Build @ucl-vr/ubiq-server
working-directory: Node
run: npx tsc -p tsconfig.build.json

- name: Publish @ucl-vr/ubiq
working-directory: Node/ubiq
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish @ucl-vr/ubiq-server
working-directory: Node
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion Documentation/docs/nexus.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Currently `ubiq-master` is running on `8010`. This is the primary, public server

It is expected and encouraged that feature branches are created, run on nexus temporarily for development, then removed when no longer needed.

The following sections describe how Nexus is maintained by the VECG team. You do not need to follow this pattern to maintain your own server, but it may be instructive.
The following sections describe how Nexus is maintained by the VECG team. You do not need to follow this pattern to maintain your own server, but it may be instructive. The server is also available as an npm package (`@ucl-vr/ubiq-server`) — see [Server Setup](serversetup.md) for details.

## Administration

Expand Down
35 changes: 34 additions & 1 deletion Documentation/docs/serversetup.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Quick Start

## From the repository

The server code is included in the Ubiq repository in the `Node` directory.

After checking out the code, run,

```
npm install
```
```

in the `Node` directory. The server can then be started with,

Expand All @@ -16,6 +18,37 @@ npm start

This will start a server with the default TCP port - the same one running on Nexus - that Unity can connect to. Continue below if you also need to support Browser Clients.

## From npm

The server and core library are also published on npm under the `@ucl-vr` scope.

To start a server without installing anything:

```
npx @ucl-vr/ubiq-server
```

Or install globally:

```
npm install -g @ucl-vr/ubiq-server
ubiq-server
```

You can also add the packages as dependencies in another Node.js project, for example to build a custom application on top of the Ubiq messaging layer.

Install the server:

```
npm install @ucl-vr/ubiq-server
```

Or, if you only need the core messaging library (connections, message passing, network scenes):

```
npm install @ucl-vr/ubiq
```

# Advanced

## Supporting Secure WebSockets
Expand Down
2 changes: 1 addition & 1 deletion Node/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WrappedSecureWebSocketServer, WrappedTcpServer } from 'ubiq'
import { WrappedSecureWebSocketServer, WrappedTcpServer } from '@ucl-vr/ubiq'
import { RoomServer, IceServerProvider, Status } from 'modules'
import nconf from 'nconf'

Expand Down
56 changes: 56 additions & 0 deletions Node/bin/ubiq-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env node

import { fileURLToPath } from 'url'
import path from 'path'
import { WrappedSecureWebSocketServer, WrappedTcpServer } from '@ucl-vr/ubiq'
import { RoomServer, IceServerProvider, Status } from 'modules'
import nconf from 'nconf'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
// At runtime __dirname is dist/bin/, so go up two levels to reach the package root
const packageRoot = path.resolve(__dirname, '..', '..')

// nconf loads the configuration hierarchically - settings that load *first*
// take priority. CLI arguments and local config files override defaults.
process.argv.slice(2).forEach(element => {
nconf.file(element, element)
})
nconf.file('local', path.join(process.cwd(), 'config', 'local.json'))
nconf.file('default', path.join(packageRoot, 'config', 'default.json'))

const roomServer = new RoomServer()
roomServer.addServer(new WrappedTcpServer(nconf.get('roomserver:tcp')))
roomServer.addServer(new WrappedSecureWebSocketServer(nconf.get('roomserver:wss')))

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const statusModule = new Status(roomServer, nconf.get('status'))

const iceServerProvider = new IceServerProvider(roomServer)
const iceServers = nconf.get('iceservers')
if (iceServers !== undefined) {
for (const iceServer of iceServers) {
iceServerProvider.addIceServer(
iceServer.uri,
iceServer.secret,
iceServer.timeoutSeconds,
iceServer.refreshSeconds,
iceServer.username,
iceServer.password)
}
}

const roomTypeName = nconf.get('roomserver:roomType')
if (roomTypeName !== undefined) {
// eslint-disable-next-line no-eval
roomServer.T = eval(roomTypeName)
}

process.on('SIGINT', function () {
roomServer.exit().then(() => {
console.log('Shutdown')
}).catch((error) => {
console.error(error)
}).finally(() => {
process.exit(0)
})
})
2 changes: 2 additions & 0 deletions Node/components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
lib
4 changes: 2 additions & 2 deletions Node/components/avatarmanager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Message, NetworkContext, NetworkScene } from 'ubiq'
import { NetworkId } from 'ubiq'
import type { Message, NetworkContext, NetworkScene } from '@ucl-vr/ubiq'
import { NetworkId } from '@ucl-vr/ubiq'
import { EventEmitter } from 'events'
import type { RoomClient, RoomPeer } from './roomclient'

Expand Down
2 changes: 1 addition & 1 deletion Node/components/logcollector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from 'events'
import { Stream, type Readable, type Writable } from 'stream'
import { NetworkId, type INetworkComponent, type Message, type NetworkScene } from 'ubiq'
import { NetworkId, type INetworkComponent, type Message, type NetworkScene } from '@ucl-vr/ubiq'
import { type RoomClient } from './roomclient'
import { Buffer } from 'buffer' // This import is needed for rollup to polyfill Buffer

Expand Down
12 changes: 9 additions & 3 deletions Node/components/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"name": "components",
"version": "0.0.1",
"version": "1.0.0",
"description": "Ubiq Peer Components for Node",
"type": "module",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": ["lib"],
"scripts": {
"build": "tsc"
},
"keywords": [],
"author": "UCL VECG",
"license": "Apache-2.0",
"homepage": "https://github.com/UCL-VR/ubiq",
"type": "module"
"homepage": "https://github.com/UCL-VR/ubiq"
}
2 changes: 1 addition & 1 deletion Node/components/peerconnectionmanager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkId, type INetworkComponent, type NetworkContext, type NetworkScene, type Message } from 'ubiq'
import { NetworkId, type INetworkComponent, type NetworkContext, type NetworkScene, type Message } from '@ucl-vr/ubiq'
import { EventEmitter } from 'events'
import { type RoomClient, type RoomPeer } from './roomclient'

Expand Down
4 changes: 2 additions & 2 deletions Node/components/roomclient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from 'events'
import { NetworkId, Uuid, type INetworkComponent, type NetworkScene, type Message, type NetworkContext } from 'ubiq'
import { type PeerInfo, type RoomInfo, type AppendPeerPropertiesArgs, type AppendRoomPropertiesArgs, type JoinArgs, type RoomServerMessage } from 'modules/roomserver'
import { NetworkId, Uuid, type INetworkComponent, type NetworkScene, type Message, type NetworkContext } from '@ucl-vr/ubiq'
import { type PeerInfo, type RoomInfo, type AppendPeerPropertiesArgs, type AppendRoomPropertiesArgs, type JoinArgs, type RoomServerMessage } from 'modules'

// Implements a RoomClient Network Component. This can be attached to a
// NetworkScene to have the NetworkScene join a Room.
Expand Down
23 changes: 23 additions & 0 deletions Node/components/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "ESNext",
"lib": [
"es2020"
],
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"incremental": true,
"outDir": "lib",
"declaration": true,
},
"files": ["./index.ts"],
"exclude": [
"node_modules"
]
}
8 changes: 6 additions & 2 deletions Node/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ const config: JestConfigWithTsJest = {
}
]
},
resolver: 'ts-jest-resolver'

resolver: 'ts-jest-resolver',
moduleNameMapper: {
'^@ucl-vr/ubiq$': '<rootDir>/ubiq/index.ts',
'^modules$': '<rootDir>/modules/index.ts',
'^components$': '<rootDir>/components/index.ts',
}
}

export default config
2 changes: 1 addition & 1 deletion Node/lib.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is the entry point for the bundler used to build Ubiq classes for
// the Browser with Rollup.

export { NetworkId, NetworkScene, WebSocketConnectionWrapper } from 'ubiq'
export { NetworkId, NetworkScene, WebSocketConnectionWrapper } from '@ucl-vr/ubiq'
export { RoomClient, PeerConnectionManager, AvatarManager, ThreePointTrackedAvatar, LogCollector } from 'components'

// This file is intended to bundle almost all the Ubiq Components and
Expand Down
2 changes: 2 additions & 0 deletions Node/modules/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
lib
1 change: 1 addition & 0 deletions Node/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { IceServerProvider } from './ice.js' // The extension must be .js even though the files on disk are .ts
export { RoomServer } from './roomserver.js'
export { Status } from './status.js'
export type { PeerInfo, RoomInfo, AppendPeerPropertiesArgs, AppendRoomPropertiesArgs, JoinArgs, RoomServerMessage } from './roomserver.js'
8 changes: 7 additions & 1 deletion Node/modules/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"name": "modules",
"version": "0.0.1",
"version": "1.0.0",
"description": "Ubiq Modules for Building Server Side Applications",
"type": "module",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": ["lib"],
"scripts": {
"build": "tsc"
},
"keywords": [],
"author": "UCL VECG",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion Node/modules/roomserver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, NetworkId, Uuid, type IConnectionWrapper, type IServerWrapper } from 'ubiq'
import { Message, NetworkId, Uuid, type IConnectionWrapper, type IServerWrapper } from '@ucl-vr/ubiq'
import { EventEmitter } from 'events'
import { type ValidationError } from 'jsonschema'
import { z } from 'zod'
Expand Down
2 changes: 2 additions & 0 deletions Node/modules/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"resolveJsonModule": true,
"isolatedModules": true,
"incremental": true,
"outDir": "lib",
"declaration": true,
},
"files": ["./index.ts"],
"exclude": [
Expand Down
Loading
Loading