- Closes #2556 - Closes #2450 **Key intended features:** - go2rtc compatible - 100% test coverage to significantly improve ability to test, maintain and work around browser weirdnesses (e.g. Safari). - Written from the ground up in the style of the rest of the project. **To use:** - Change `live_provider` from `go2rtc` to `go2rtc-experimental`.
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { convertToWebSocketURL } from '../../src/utils/websocket-url';
|
|
|
|
// @vitest-environment jsdom
|
|
describe('convertToWebSocketURL', () => {
|
|
it('should convert http to ws', () => {
|
|
expect(convertToWebSocketURL('http://host:1984/api/ws?src=camera')).toBe(
|
|
'ws://host:1984/api/ws?src=camera',
|
|
);
|
|
});
|
|
|
|
it('should convert https to wss', () => {
|
|
expect(convertToWebSocketURL('https://host/api/ws?src=camera')).toBe(
|
|
'wss://host/api/ws?src=camera',
|
|
);
|
|
});
|
|
|
|
it('should convert a mixed-case scheme', () => {
|
|
expect(convertToWebSocketURL('HtTp://host/api/ws')).toBe('ws://host/api/ws');
|
|
});
|
|
|
|
it('should prepend the provided origin to a relative path', () => {
|
|
expect(convertToWebSocketURL('/api/ws?src=camera', 'https://ha:8123')).toBe(
|
|
'wss://ha:8123/api/ws?src=camera',
|
|
);
|
|
});
|
|
|
|
it('should prepend the location origin to a relative path by default', () => {
|
|
expect(convertToWebSocketURL('/api/ws?src=camera')).toBe(
|
|
'ws://localhost:3000/api/ws?src=camera',
|
|
);
|
|
});
|
|
|
|
it('should leave other schemes untouched', () => {
|
|
expect(convertToWebSocketURL('ws://host/api/ws')).toBe('ws://host/api/ws');
|
|
});
|
|
});
|