Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we do not replace http unless it's in the scheme #805

Merged
merged 2 commits into from
Jul 26, 2023
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
5 changes: 5 additions & 0 deletions .changeset/tender-news-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Ensure we do not replace http unless it's in the scheme
16 changes: 16 additions & 0 deletions src/room/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest';
import { toWebsocketUrl } from './utils';

describe('toWebsocketUrl', () => {
it('leaves wss urls alone', () => {
expect(toWebsocketUrl('ws://mywebsite.com')).toEqual('ws://mywebsite.com');
});

it('converts https to wss', () => {
expect(toWebsocketUrl('https://mywebsite.com')).toEqual('wss://mywebsite.com');
});

it('does not convert other parts of URL', () => {
expect(toWebsocketUrl('https://httpsmywebsite.com')).toEqual('wss://httpsmywebsite.com');
});
});
4 changes: 2 additions & 2 deletions src/room/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,14 @@ export function unwrapConstraint(constraint: ConstrainDOMString): string {

export function toWebsocketUrl(url: string): string {
if (url.startsWith('http')) {
return url.replace('http', 'ws');
return url.replace(/^(http)/, 'ws');
}
return url;
}

export function toHttpUrl(url: string): string {
if (url.startsWith('ws')) {
return url.replace('ws', 'http');
return url.replace(/^(ws)/, 'http');
}
return url;
}