Skip to content

Commit

Permalink
Major version change '1.0.0' done
Browse files Browse the repository at this point in the history
  • Loading branch information
web3nelly committed Apr 6, 2023
1 parent 275bf0d commit 3fe7270
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 47 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
node_modules/
test/
coverage/
rollup.config.js
package-lock.json

# Ignore OS-related files
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Ignore development-related files and folders
node_modules/
test/
examples/
coverage/
rollup.config.js
package-lock.json
Expand Down
77 changes: 50 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# change-obs-scene

With just a few lines of code, automate changing your OBS scenes using the [@b3nelly/change-obs-scene](https://www.npmjs.com/package/@b3nelly/change-obs-scene?activeTab=readme) npm package.
With just a few lines of code, automate changing your OBS scenes using the [@b3nelly/change-obs-scene](https://www.npmjs.com/package/@b3nelly/change-obs-scene?activeTab=readme) npm package. 💜

## Dependancies

- [OBS](https://obsproject.com/)
- [Node.js](https://nodejs.org/)
- [NPM](https://www.npmjs.com/)
- [obs-websocket-js](https://www.npmjs.com/package/obs-websocket-js)

## Installation

Expand All @@ -22,41 +23,49 @@ npm install @b3nelly/change-obs-scene

- ![obs websocket server settings](https://github.com/b3nelly2/stream/blob/main/assets/obs-websocket-server-settings.png?raw=true)
- Don't forget to set your _Server Password_
- If you do not set a password, you do not need to pass the `obsWebSocketServerPassword` param to `changeScene()`

### Simple Usage Example

```js
const changeScene = require("@b3nelly/change-obs-scene").default;
const intervalInSeconds = 30; // 30 seconds per scene
changeScene(intervalInSeconds); // it's that simple.
```

### CommonJS (cjs) Usage Example

```js
const obsSwitchScenes =
require("@b3nelly/change-obs-scene/dist/obs-switch-scenes.cjs.js").default;
const changeScene = require("@b3nelly/change-obs-scene").default;

const obsSkipScenes = [];
const intervalInSeconds = 10;
const obsWebSocketServerURL = "ws://localhost:4455";
const intervalInSeconds = 30;
const obsWebSocketServerPassword = "your-password-here";
const obsWebSocketServerURL = "ws://localhost:4455";

obsSwitchScenes(
changeScene(
intervalInSeconds,
obsSkipScenes,
obsWebSocketServerPassword
obsWebSocketServerURL,
obsWebSocketServerPassword,
obsSkipScenes
);
```

### ECMAScript Module (esm) Usage Example

```js
import obsSwitchScenes from "@b3nelly/change-obs-scene/dist/obs-switch-scenes.esm.js";
import changeScene from "@b3nelly/change-obs-scene";

const obsSkipScenes = [];
const intervalInSeconds = 30;
const obsWebSocketServerURL = "ws://localhost:4455";
const obsWebSocketServerPassword = "your-password-here";
const obsWebSocketServerURL = "ws://localhost:4455";

obsSwitchScenes(
changeScene(
intervalInSeconds,
obsSkipScenes,
obsWebSocketServerPassword
obsWebSocketServerURL,
obsWebSocketServerPassword,
obsSkipScenes
);
```

Expand All @@ -73,22 +82,22 @@ obsSwitchScenes(
<script>
require.config({
paths: {
obsSwitchScenes:
changeScene:
"@b3nelly/change-obs-scene/dist/obs-switch-scenes.amd",
},
});
require(["obsSwitchScenes"], function (obsSwitchScenes) {
require(["changeScene"], function (changeScene) {
const obsSkipScenes = [];
const intervalInSeconds = 90;
const obsWebSocketServerURL = "ws://localhost:4455";
const obsWebSocketServerPassword = "your-password-here";
obsSwitchScenes.default(
changeScene(
intervalInSeconds,
obsSkipScenes,
obsWebSocketServerPassword
obsWebSocketServerURL,
obsWebSocketServerPassword,
obsSkipScenes
);
});
</script>
Expand All @@ -100,25 +109,39 @@ obsSwitchScenes(
## API

```js
obsSwitchScenes(
changeScene(
intervalInSeconds,
obsSkipScenes,
obsWebSocketServerPassword
obsWebSocketServerURL,
obsWebSocketServerPassword,
obsSkipScenes
);
```

- `intervalInSeconds` _(number, default: `60`)_: Number of seconds between each scene switch.
- `obsWebSocketServerURL` _(string, default: 'ws_://localhost:4455'): OBS WebSocket Server URL or IP.
- `obsWebSocketServerPassword` _(string, default: undefined)_: OBS WebSocket Server Password.
- `obsSkipScenes` _(Array<string>, default: [])_: An array of scene names to skip when switching scenes (scene name must match).
| Parameter | Type | Default | Description |
| --------------------------------------- | :-------------: | :----------------------: | ----------------------------------------------------- |
| `intervalInSeconds` (optional) | `number` | `60` | Number of seconds between each scene |
| `obsSkipScenes` (optional) | `Array<string>` | `[]` | An array of scene names to skip when switching scenes |
| `obsWebSocketServerPassword` (optional) | `string` | `undefined` | OBS WebSocket Server Password |
| `obsWebSocketServerURL` (optional) | `string` | `"ws_://localhost:4455"` | OBS WebSocket Server URL / IP |

## CLI

```shell
npm run cli
```

You will be prompted to enter in the `changeSence()` params. Leave param blank to use default value.

## Test
## Build

```shell
npm run test
npm run build
```

Running the `build` command will automatically create the `dist/` dir and create/update the `cjs`, `esm`, and `amd` files inside.

Configuration file [rollup.config.js](https://github.com/web3nelly/change-obs-scene/blob/275bf0d4d8e13b7ae7547e292f0d0997a192806b/rollup.config.js)

## Development Dependancies

- [@babel/core](https://www.npmjs.com/package/@babel/core)
Expand Down
20 changes: 14 additions & 6 deletions obs-switch-scenes.js → change-obs-scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@ const obs = new OBSWebSocket();
* Automatically Switch OBS Scene
*
* @param {number} [intervalInSeconds=60] Number of seconds to next scene.
* @param {string} [obsWebSocketServerURL='ws://localhost:4455'] OBS WebSocket Server URL or IP.
* @param {string} [obsWebSocketServerPassword=undefined] OBS WebSocket Server Password.
* @param {array[string]} [array] Add scene/s you would like skip using comma seperated string(scene name must match).
* @param {string} [obsWebSocketServerPassword=undefined] OBS WebSocket Server Password. NOTE, leave undefined if there is no password set.
* @param {string} [obsWebSocketServerURL='ws://localhost:4455'] OBS WebSocket Server URL or IP.
* @returns {null}
*/

const obsSwitchScenes = (
const changeScene = (
intervalInSeconds = 60,
obsWebSocketServerURL = "ws://localhost:4455",
obsWebSocketServerPassword = undefined,
obsSkipScenes = []
) => {
let currentSceneIndex;
if (
obsWebSocketServerPassword === null ||
obsWebSocketServerPassword === false ||
obsWebSocketServerPassword === ""
) {
obsWebSocketServerPassword = undefined;
}

obs.on("ConnectionOpened", () => {
console.log("Connection Opened");
Expand All @@ -34,7 +40,7 @@ const obsSwitchScenes = (
switchScene(scenesData, intervalInSeconds);
})
.catch((error) => {
console.error("Error on GetSceneList call:", error);
console.error("Error on GetSceneList call:", error.code, error.message);
});
});

Expand All @@ -47,6 +53,8 @@ const obsSwitchScenes = (
}
);

let currentSceneIndex;

const switchScene = (scenesData, intervalInSecs) => {
setInterval(() => {
currentSceneIndex = getNextSceneIndex(
Expand Down Expand Up @@ -80,4 +88,4 @@ const obsSwitchScenes = (
};
};

export default obsSwitchScenes;
export default changeScene;
1 change: 1 addition & 0 deletions dist/change-obs-scene.amd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/change-obs-scene.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/change-obs-scene.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dist/obs-switch-scenes.amd.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/obs-switch-scenes.cjs.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/obs-switch-scenes.esm.js

This file was deleted.

4 changes: 2 additions & 2 deletions test.js → examples/cli.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import obsSwitchScenes from "./dist/obs-switch-scenes.esm.js";
import changeScene from "@b3nelly/change-obs-scene";
import readline from "readline";

const obsSkipScenes = [];
Expand Down Expand Up @@ -50,7 +50,7 @@ const askPassword = () => {
obsWebSocketServerPassword = await askPassword();
rl.close();

obsSwitchScenes(
changeScene(
intervalInSeconds,
obsWebSocketServerURL,
obsWebSocketServerPassword,
Expand Down
5 changes: 5 additions & 0 deletions examples/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import changeScene from "@b3nelly/change-obs-scene"; // https://github.com/web3nelly/change-obs-scene

const intervalInSeconds = 30; // 30 seconds per scene

changeScene(intervalInSeconds);
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@b3nelly/change-obs-scene",
"version": "0.1.4",
"description": "With just a few lines of code, automate changing your OBS scenes.",
"version": "1.0.0",
"description": "With just a few lines of code, automate changing your OBS scenes. Happy streaming! 💜",
"author": "web3nelly",
"license": "MIT",
"type": "module",
"main": "obs-switch-scenes.js",
"main": "change-obs-scene.js",
"scripts": {
"build": "rollup -c",
"test": "node --experimental-modules test.js"
"cli": "node --experimental-modules examples/cli.js"
},
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ const require = createRequire(import.meta.url);
const { default: OBSWebSocket } = require("obs-websocket-js");

export default {
input: "obs-switch-scenes.js",
input: "change-obs-scene.js",
output: [
{
file: "dist/obs-switch-scenes.cjs.js",
file: "dist/change-obs-scene.cjs.js",
format: "cjs",
},
{
file: "dist/obs-switch-scenes.esm.js",
file: "dist/change-obs-scene.esm.js",
format: "esm",
},
{
file: "dist/obs-switch-scenes.amd.js",
file: "dist/change-obs-scene.amd.js",
format: "amd",
amd: {
id: "OBSWebSocket",
Expand Down

0 comments on commit 3fe7270

Please sign in to comment.