Skip to content
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
6 changes: 3 additions & 3 deletions 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, logger } from 'ubiq'
import { RoomServer, IceServerProvider, Status } from 'modules'
import nconf from 'nconf'

Expand Down Expand Up @@ -47,9 +47,9 @@ if (roomTypeName !== undefined) {

process.on('SIGINT', function () {
roomServer.exit().then(() => {
console.log('Shutdown')
logger.log('Shutdown')
}).catch((error) => {
console.error(error)
logger.error(error)
}).finally(() => {
process.exit(0)
})
Expand Down
3 changes: 2 additions & 1 deletion Node/components/roomclient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EventEmitter } from 'events'
import { NetworkId, Uuid, type INetworkComponent, type NetworkScene, type Message, type NetworkContext } from 'ubiq'
import { logger } from 'ubiq/logger'
import { type PeerInfo, type RoomInfo, type AppendPeerPropertiesArgs, type AppendRoomPropertiesArgs, type JoinArgs, type RoomServerMessage } from 'modules/roomserver'

// Implements a RoomClient Network Component. This can be attached to a
Expand Down Expand Up @@ -35,7 +36,7 @@ export class RoomPeer {

setProperty (key: string, value: string): void {
if (this.#setPeerProperty === undefined) {
console.error('Properties may only be set on the local Peer')
logger.error('Properties may only be set on the local Peer')
} else {
this.#setPeerProperty(key, value)
}
Expand Down
9 changes: 5 additions & 4 deletions Node/modules/ice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import crypto from 'crypto'
import { logger } from 'ubiq'
import { type Room, type RoomServer } from './roomserver'

interface IceServer {
Expand Down Expand Up @@ -41,7 +42,7 @@ export class IceServerProvider {
// clients preferentially and the secret will not be used.
addIceServer (uri: string, secret = '', timeoutSeconds = 0,
refreshSeconds = 0, username = '', password = ''): void {
console.log('IceServerProvider: Adding ice server with uri ' + uri)
logger.log('IceServerProvider: Adding ice server with uri ' + uri)

if (this.iceServers.some((iceServer) => { return iceServer.uri === uri })) {
return
Expand Down Expand Up @@ -123,7 +124,7 @@ export class IceServerProvider {
// Used internally - not exported
// Generate fresh credentials for an ice server and link all rooms with new info
function refresh (iceServer: IceServer, roomServer: RoomServer): void {
console.log('IceServerProvider: Refreshing credentials for ice server with uri ' + iceServer.uri)
logger.log('IceServerProvider: Refreshing credentials for ice server with uri ' + iceServer.uri)
const cred = generateCredentials(iceServer.secret, iceServer.timeoutSeconds)
iceServer.username = cred.username
iceServer.password = cred.password
Expand Down Expand Up @@ -159,7 +160,7 @@ function generateSha1Hmac (secret: any, msg: crypto.BinaryLike | crypto.KeyObjec
// If room has ice server with uri but different hmac, update hmac
// If changes would be made to room properties, push new room args
function link (room: Room, uri: string, username: string, password: string): void {
console.log('IceServerProvider: Linking room ' + room.uuid + ' to ice server ' + uri + '[' + username + ':' + password + ']')
logger.log('IceServerProvider: Linking room ' + room.uuid + ' to ice server ' + uri + '[' + username + ':' + password + ']')

let prop = room.properties.get('ice-servers')
if (prop === '') {
Expand Down Expand Up @@ -196,7 +197,7 @@ function link (room: Room, uri: string, username: string, password: string): voi
// Ensure room does not have an ice server with matching uri
// If changes would be made to room properties, push new room args
function unlink (room: Room, uri: string): void {
console.log('IceServerProvider: Unlinking room ' + room.uuid + ' from ice server ' + uri)
logger.log('IceServerProvider: Unlinking room ' + room.uuid + ' from ice server ' + uri)
const args = room.getRoomArgs()

// Find ice-servers property
Expand Down
34 changes: 17 additions & 17 deletions 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, logger } from 'ubiq'
import { EventEmitter } from 'events'
import { type ValidationError } from 'jsonschema'
import { z } from 'zod'
Expand Down Expand Up @@ -279,14 +279,14 @@ export class RoomServer extends EventEmitter {

addServer (server: IServerWrapper): void {
if (server.status === 'LISTENING') {
console.log('Added RoomServer port ' + server.port)
logger.log('Added RoomServer port ' + server.port)
this.servers.push(server)
server.onConnection.push(this.onConnection.bind(this))
}
}

onConnection (wrapped: IConnectionWrapper): void {
console.log('RoomServer: Client Connection from ' + wrapped.endpoint().address + ':' + wrapped.endpoint().port)
logger.log('RoomServer: Client Connection from ' + wrapped.endpoint().address + ':' + wrapped.endpoint().port)
// eslint-disable-next-line no-new
new RoomPeer(this, wrapped)
}
Expand All @@ -297,7 +297,7 @@ export class RoomServer extends EventEmitter {
if ((args.uuid != null) && args.uuid !== '') {
// Room join request by uuid
if (!Uuid.validate(args.uuid)) {
console.log(peer.uuid + ' attempted to join room with uuid ' + args.uuid + ' but the we were expecting an RFC4122 v4 uuid.')
logger.log(peer.uuid + ' attempted to join room with uuid ' + args.uuid + ' but the we were expecting an RFC4122 v4 uuid.')
peer.sendRejected(args, 'Could not join room with uuid ' + args.uuid + '. We require an RFC4122 v4 uuid.')
return
}
Expand All @@ -309,14 +309,14 @@ export class RoomServer extends EventEmitter {
room = this.roomDatabase.joincode(args.joincode)

if (room === null) {
console.log(peer.uuid + ' attempted to join room with code ' + args.joincode + ' but no such room exists')
logger.log(peer.uuid + ' attempted to join room with code ' + args.joincode + ' but no such room exists')
peer.sendRejected(args, 'Could not join room with code ' + args.joincode + '. No such room exists.')
return
}
}

if (room !== null && peer.room.uuid === room.uuid) {
console.log(peer.uuid + ' attempted to join room with code ' + args.joincode + ' but peer is already in room')
logger.log(peer.uuid + ' attempted to join room with code ' + args.joincode + ' but peer is already in room')
return
}

Expand Down Expand Up @@ -361,7 +361,7 @@ export class RoomServer extends EventEmitter {
this.stats.roomscreated++
this.emit('create', room)

console.log(room.uuid + ' created with joincode ' + joincode)
logger.log(room.uuid + ' created with joincode ' + joincode)
}

if (peer.room.uuid != null) {
Expand Down Expand Up @@ -391,7 +391,7 @@ export class RoomServer extends EventEmitter {
this.roomDatabase.add(room)
this.emit('create', room)

console.log(room.uuid + ' created with joincode ' + joincode)
logger.log(room.uuid + ' created with joincode ' + joincode)
}
return room
}
Expand Down Expand Up @@ -419,7 +419,7 @@ export class RoomServer extends EventEmitter {
this.emit('destroy', room)
this.roomDatabase.remove(room.uuid)
this.stats.rooms--
console.log('RoomServer: Deleting empty room ' + room.uuid)
logger.log('RoomServer: Deleting empty room ' + room.uuid)
}

getStats (): Statistics {
Expand Down Expand Up @@ -473,7 +473,7 @@ class RoomPeer {
const timeDifferenceMs = currentTime.getTime() - this.previousTime.getTime();

if (timeDifferenceMs >= 10000) {
console.log(`Peer ${this.uuid}: Timeout. Dropping.`);
logger.log(`Peer ${this.uuid}: Timeout. Dropping.`);
this.connection.close();
}
}
Expand Down Expand Up @@ -542,13 +542,13 @@ class RoomPeer {
}
break
default:
console.warn(`Received unknown server message ${object.type}`)
logger.warn(`Received unknown server message ${object.type}`)
};
} catch (e) {
if (e instanceof z.ZodError) {
console.log(`Peer ${this.uuid}: Error in message - ${JSON.stringify(e.issues)}`)
logger.log(`Peer ${this.uuid}: Error in message - ${JSON.stringify(e.issues)}`)
} else {
console.log(`Peer ${this.uuid}: Uknown error in server message`)
logger.log(`Peer ${this.uuid}: Uknown error in server message`)
}
}
} else {
Expand All @@ -559,9 +559,9 @@ class RoomPeer {
onValidationFailure (error: { validation: { errors: ValidationError[] }, json: any }): void {
error.validation.errors.forEach(error => {
// eslint-disable-next-line @typescript-eslint/no-base-to-string, @typescript-eslint/restrict-template-expressions
console.error(`Validation error in ${error.schema}: ${error.message}`)
logger.error(`Validation error in ${error.schema}: ${error.message}`)
})
console.error('Message Json: ' + JSON.stringify(error.json))
logger.error('Message Json: ' + JSON.stringify(error.json))
}

getPeerArgs (): PeerInfo {
Expand Down Expand Up @@ -746,7 +746,7 @@ export class Room {
peer.sendPeerAdded(existing) // And the new Peer about the existing one
}
};
console.log(peer.uuid + ' joined room ' + this.name)
logger.log(peer.uuid + ' joined room ' + this.name)
}

removePeer (peer: RoomPeer): void {
Expand All @@ -756,7 +756,7 @@ export class Room {
existing.sendPeerRemoved(peer) // Tell the remaining peers about the missing peer (no check here because the peer was already removed from the list)
peer.sendPeerRemoved(existing)
}
console.log(peer.uuid + ' left room ' + this.name)
logger.log(peer.uuid + ' left room ' + this.name)
this.checkRoom()
}

Expand Down
5 changes: 3 additions & 2 deletions Node/modules/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// status, allow gathering of statistics, and performing uptime tests.

import type { RoomServer } from './roomserver'
import { logger } from 'ubiq'
import https from 'https'
import path from 'path'
import fs from 'fs'
Expand Down Expand Up @@ -33,7 +34,7 @@ export class Status {
options.key = fs.readFileSync(path.resolve(config.key))
options.cert = fs.readFileSync(path.resolve(config.cert))
} catch (error) {
console.error('Unable to read certificate for status module. You will not be able to create secure connections to the status APIs.')
logger.error('Unable to read certificate for status module. You will not be able to create secure connections to the status APIs.')
}

const app = express()
Expand Down Expand Up @@ -100,7 +101,7 @@ export class Status {
})

https.createServer(options, app).listen(config.port, () => {
console.log(`Added status server on port ${config.port}`)
logger.log(`Added status server on port ${config.port}`)
})
}

Expand Down
Loading
Loading