Skip to content

Commit

Permalink
feat: if no hostname is set return relative WHIP resource URL (Eyevin…
Browse files Browse the repository at this point in the history
birme authored Feb 21, 2023
1 parent 6b0bea5 commit dd22f49
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 6 additions & 3 deletions packages/server/src/whip/whipEndpoint.ts
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ export class WhipEndpoint {
this.extPort = opts?.extPort || this.port;
this.interfaceIp = opts?.interfaceIp || "0.0.0.0";
this.useHttps = !!(opts?.https);
this.hostname = opts?.hostname || "localhost";
this.hostname = opts?.hostname;
this.enabledWrtcPlugins = opts?.enabledWrtcPlugins || [];
this.iceServers = opts?.iceServers || [];
this.tls = opts?.tls;
@@ -134,8 +134,11 @@ export class WhipEndpoint {
return this.iceServers;
}

getServerAddress(): string {
return (this.useHttps ? "https" : "http") + "://" + this.hostname + ":" + this.extPort;
getServerAddress(): string | undefined {
if (this.hostname) {
return (this.useHttps ? "https" : "http") + "://" + this.hostname + ":" + this.extPort;
}
return undefined;
}

listen() {
9 changes: 8 additions & 1 deletion packages/server/src/whip/whipFastifyApi.ts
Original file line number Diff line number Diff line change
@@ -65,9 +65,16 @@ export default function(fastify: FastifyInstance, opts, done) {
await resource.connect();
const sdpAnswer = await resource.sdpAnswer();

let locationUrl;
// If no hostname is configured we return relative WHIP resource URL
if (opts.instance.getServerAddress()) {
locationUrl = `${opts.instance.getServerAddress()}${opts.prefix}/whip/${type}/${resource.getId()}`;
} else {
locationUrl = `${opts.prefix}/whip/${type}/${resource.getId()}`;
}
reply.headers({
"Content-Type": "application/sdp",
"Location": `${opts.instance.getServerAddress()}${opts.prefix}/whip/${type}/${resource.getId()}`,
"Location": locationUrl,
"ETag": resource.getETag()
});

0 comments on commit dd22f49

Please sign in to comment.