Skip to content

Commit

Permalink
Continued to polish Js part of the project; finished making updates f…
Browse files Browse the repository at this point in the history
…or Linter. Updated all the samples (and removed old ones). Fixed Rollup config. Updated bundle and made sure browser sample works.
  • Loading branch information
sebjf committed Nov 22, 2023
1 parent d945e5a commit 451c093
Show file tree
Hide file tree
Showing 15 changed files with 697 additions and 16,135 deletions.
16,103 changes: 404 additions & 15,699 deletions Browser/bundle.js

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions Browser/samples/hello/hello.js
@@ -1,4 +1,4 @@
import { WebSocketConnectionWrapper, NetworkId, NetworkScene, RoomClient, PeerConnectionManager, AvatarManager } from "/bundle.js"
import { WebSocketConnectionWrapper, NetworkId, NetworkScene, RoomClient, PeerConnectionManager, AvatarManager, ThreePointTrackedAvatar } from "/bundle.js"

// This creates a typical Browser WebSocket, with a wrapper that can
// parse Ubiq messages.
Expand Down Expand Up @@ -181,8 +181,9 @@ peerConnectionManager.addListener("OnPeerConnection", async component =>{
pc.onnegotiationneeded = async () => {
try {
component.makingOffer = true;
await pc.setLocalDescription();
component.sendSdp(pc.localDescription);
const offer = await pc.createOffer()
await pc.setLocalDescription(offer);
component.sendSdp(offer);
} catch (err) {
console.error(err);
} finally {
Expand Down Expand Up @@ -230,12 +231,17 @@ peerConnectionManager.addListener("OnPeerConnection", async component =>{
if (component.ignoreOffer) {
return;
}
component.isSettingRemoteAnswerPending = description.type == "answer";
await pc.setRemoteDescription(description); // SRD rolls back as needed
component.isSettingRemoteAnswerPending = false;
if (description.type == "offer") {
await pc.setLocalDescription();
component.sendSdp(pc.localDescription);
await pc.setRemoteDescription(description); // SRD rolls back as needed
const answer = await pc.createAnswer();
await pc.setLocalDescription(answer);
component.sendSdp(answer);
} else if (description.type == "answer"){
component.isSettingRemoteAnswerPending = true;
await pc.setRemoteDescription(description); // SRD rolls back as needed
component.isSettingRemoteAnswerPending = false;
} else {
throw new Error("Unknown WebRtc Signalling Message")
}
} else if (candidate) {
try {
Expand Down
4 changes: 4 additions & 0 deletions Node/.eslintrc.json
Expand Up @@ -8,6 +8,10 @@
"ecmaVersion": "latest",
"sourceType": "module"
},
"ignorePatterns": [
"/samples/**/*.js",
"rollup.config.js"
],
"rules": {
"@typescript-eslint/indent": ["error", 4],
"no-prototype-builtins": "off"
Expand Down
1 change: 1 addition & 0 deletions Node/components/logcollector.ts
Expand Up @@ -2,6 +2,7 @@ import { EventEmitter } from 'events'
import { Stream, type Readable, type Writable } from 'stream'
import { NetworkId, type INetworkComponent, type Message, type NetworkScene } from 'ubiq'
import { type RoomClient } from './roomclient'
import { Buffer } from 'buffer' // This import is needed for rollup to polyfill Buffer

class LogCollectorMessage {
type: number
Expand Down
4 changes: 2 additions & 2 deletions Node/components/roomclient.ts
Expand Up @@ -14,8 +14,8 @@ export class RoomPeer {

constructor (args: PeerInfo) {
this.uuid = args.uuid
this.sceneid = args.sceneid
this.clientid = args.clientid
this.sceneid = new NetworkId(args.sceneid)
this.clientid = new NetworkId(args.clientid)
this.properties = new Map()
for (let i = 0; i < args.keys.length; i++) {
this.properties.set(args.keys[i], args.values[i])
Expand Down
12 changes: 12 additions & 0 deletions Node/modules/status.ts
Expand Up @@ -8,6 +8,10 @@ import fs from 'fs'
import express, { type Request, type Response } from 'express'
import cookieParser from 'cookie-parser'

// Some calls are protected via API keys. These are UUIDs that should be provided
// in the apikeys member of the config object. If no API keys are defined, then
// the API is available to everyone.

interface StatusConfig {
port: number
cert: string
Expand Down Expand Up @@ -97,13 +101,21 @@ export class Status {
}

checkApiKey (req: Request, res: Response, next: any): void {
// Are we using API key protection at all?
if (this.apikeys.length <= 0) {
next()
return
}

// Is the API key in the query?
if (req.query.apikey !== undefined) {
if (this.apikeys.includes(req.query.apikey as string)) {
next()
return
}
}

// Or is it in the cookie?
if (req.cookies !== undefined) {
if (req.cookies.apikey !== undefined) {
if (this.apikeys.includes(req.cookies.apikey)) {
Expand Down

0 comments on commit 451c093

Please sign in to comment.