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

Added instructions for static imports. #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,38 @@ Typescript definitions are included in this package, and are automatically gener

## Usage
#### Instantiation
The web distributable exposes a global named `OBSWebSocket`.
The web distributable exposes a global named `OBSWebSocket`.

```html
<script type='text/javascript' src='./dist/obs-websocket.js'></script>
```

In node...
In node...

```js
const OBSWebSocket = require('obs-websocket-js');
```

If you're working in a frontend framework and want to use static imports...

```js
import OBSWebSocket from '../../node_modules/obs-websocket-js/lib/OBSWebSocket.js'; //relative path may vary depending on location of node_modules directory
```

Create a new WebSocket connection using the following.
- Address is optional; defaults to `localhost` with a port of `4444`.
- Password is optional.
- Address is optional; defaults to `localhost` with a port of `4444`.
- Password is optional.

```js
const obs = new OBSWebSocket();
obs.connect({ address: 'localhost:4444', password: '$up3rSecretP@ssw0rd' });
```

#### Sending Requests
All requests support the following two Syntax options where both `err` and `data` will contain the raw response from the WebSocket plugin.
_Note that all response objects will supply both the original [obs-websocket][link-obswebsocket] response items in their original format (ex: `'response-item'`), but also camelCased (ex: `'responseItem'`) for convenience._
- RequestName must exactly match what is defined by the [`obs-websocket`][link-obswebsocket] plugin.
- `{args}` are optional. Note that both `request-type` and `message-id` will be bound automatically.
All requests support the following two Syntax options where both `err` and `data` will contain the raw response from the WebSocket plugin.
_Note that all response objects will supply both the original [obs-websocket][link-obswebsocket] response items in their original format (ex: `'response-item'`), but also camelCased (ex: `'responseItem'`) for convenience._
- RequestName must exactly match what is defined by the [`obs-websocket`][link-obswebsocket] plugin.
- `{args}` are optional. Note that both `request-type` and `message-id` will be bound automatically.
- To use callbacks instead of promises, use the `sendCallback` method instead of `send`.

```js
Expand All @@ -73,8 +79,8 @@ obs.disconnect();
```

#### Receiving Events
For all events, `data` will contain the raw response from the WebSocket plugin.
_Note that all response objects will supply both the original [obs-websocket][link-obswebsocket] response items in their original format (ex: `'response-item'`), but also camelCased (ex: `'responseItem'`) for convenience._
For all events, `data` will contain the raw response from the WebSocket plugin.
_Note that all response objects will supply both the original [obs-websocket][link-obswebsocket] response items in their original format (ex: `'response-item'`), but also camelCased (ex: `'responseItem'`) for convenience._
- EventName must exactly match what is defined by the [`obs-websocket`][link-obswebsocket] plugin.

```js
Expand Down