-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add options to SoundcraftUI, make WS ctor configurable
- Loading branch information
Showing
7 changed files
with
133 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
sidebar_position: 3 | ||
title: WebSocket implementation | ||
--- | ||
|
||
# Using a different WebSocket implementation | ||
|
||
This library uses the WebSocket protocol to communicate with the mixer. | ||
While this usually works well in a browser environment with the original `WebSocket` constructor available, things can get difficult on other platforms like Node.js. | ||
Under the hood, we use the [`modern-isomorphic-ws`](https://github.com/JoCat/modern-isomorphic-ws/) package to automatically fall back to `ws` on Node.js. | ||
|
||
There might be platforms or scenarios where this doesn't work as intended. | ||
If you want to use another WebSocket implementation or e.g. want explicitly use the DOM API, you can specify the WebSocket constructor in the options: | ||
|
||
```ts | ||
const conn = new SoundcraftUI({ | ||
targetIP: '192.168.1.123', | ||
webSocketCtor: WebSocket, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { SoundcraftUI } from './soundcraft-ui'; | ||
import { SoundcraftUIOptions } from './types'; | ||
|
||
describe('SoundcraftUI', () => { | ||
it('should be initialized with IP as string', () => { | ||
const conn = new SoundcraftUI('192.168.1.123'); | ||
expect(conn.options).toEqual({ targetIP: '192.168.1.123' }); | ||
}); | ||
|
||
it('should be initialized with IP in an options object', () => { | ||
const conn = new SoundcraftUI({ targetIP: '192.168.1.234' }); | ||
expect(conn.options).toEqual({ targetIP: '192.168.1.234' }); | ||
}); | ||
|
||
it('should throw error when mutating options', () => { | ||
const conn = new SoundcraftUI({ targetIP: '192.168.1.234' }); | ||
|
||
let error; | ||
try { | ||
(conn.options as SoundcraftUIOptions).targetIP = '0.0.0.0'; | ||
} catch (e) { | ||
error = e; | ||
} | ||
expect(error).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters