Skip to content
Open
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
14 changes: 13 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ export class MultipleThings {
* @param {String} name The mDNS server name
*/
constructor(things: Thing[], name: string) {
this.things = things;
this.things = things.slice();
this.name = name;
}

addThing(thing: Thing): number {
return this.things.push(thing) - 1;
}

/**
* Get the thing at the given index.
*
Expand Down Expand Up @@ -848,6 +852,14 @@ export class WebThingServer {
this.server.on('request', this.app);
}

addThing(thing: Thing): void {
if (this.things instanceof SingleThing) {
throw new Error('Cannot add new things when Webthings was instanciated with a SingleThing.');
}
const i = this.things.addThing(thing);
thing.setHrefPrefix(`${this.basePath}/${i}`);
}

/**
* Start listening for incoming connections.
*
Expand Down