Skip to content

Commit 8187c20

Browse files
Feat: custom ws server (#18)
* feat: custom ws server * chore: update deps * chore: version up
1 parent d2bcfa6 commit 8187c20

File tree

6 files changed

+67
-16
lines changed

6 files changed

+67
-16
lines changed

actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export function getActions() {
171171

172172
panning: {
173173
name: 'Local: Set Audio Pan',
174-
description: 'Sets the stereo pannning of all incoming audio streams',
174+
description: 'Sets the stereo panning of all incoming audio streams',
175175
options: [
176176
{
177177
type: 'number',

companion/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "vdo-ninja",
44
"shortname": "VDO.Ninja",
55
"description": "vdo-ninja",
6-
"version": "2.1.0",
6+
"version": "2.2.0",
77
"license": "MIT",
88
"repository": "git+https://github.com/bitfocus/companion-module-vdo-ninja.git",
99
"bugs": "https://github.com/bitfocus/companion-module-vdo-ninja/issues",

index.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getActions } from './actions.js'
33
import { getPresets } from './presets.js'
44
import { getVariables, updateVariables } from './variables.js'
55
import { getFeedbacks } from './feedbacks.js'
6+
import { upgradeScripts } from './upgrades.js'
67

78
import WebSocket from 'ws'
89

@@ -47,11 +48,31 @@ class VDONinjaInstance extends InstanceBase {
4748
label: 'API ID',
4849
width: 6,
4950
},
51+
{
52+
type: 'checkbox',
53+
id: 'wsCustom',
54+
label: 'Custom Websockets Server (Advanced)',
55+
default: false,
56+
width: 6,
57+
},
58+
{
59+
type: 'textinput',
60+
id: 'wsServer',
61+
label: 'Custom Websockets Server Domain',
62+
default: 'api.vdo.ninja',
63+
tooltip:
64+
'Only use this if you are self-hosting your own websockets server. Only include the domain, not "wss://" or port',
65+
width: 6,
66+
isVisible: (options) => options.wsCustom,
67+
},
5068
]
5169
}
5270

5371
async configUpdated(config) {
5472
this.config = config
73+
if (this.reconnect) {
74+
clearInterval(this.reconnect)
75+
}
5576
this.initWebSocket()
5677
}
5778

@@ -85,7 +106,12 @@ class VDONinjaInstance extends InstanceBase {
85106
delete this.ws
86107
}
87108

88-
this.ws = new WebSocket(`wss://api.vdo.ninja:443`)
109+
let serverUrl = 'api.vdo.ninja'
110+
if (this.config.wsCustom && this.config.wsServer) {
111+
serverUrl = this.config.wsServer
112+
}
113+
114+
this.ws = new WebSocket(`wss://${serverUrl}:443`)
89115

90116
this.ws.on('open', () => {
91117
if (!this.connected) {
@@ -115,7 +141,7 @@ class VDONinjaInstance extends InstanceBase {
115141
this.connected = false
116142
this.updateStatus('connection_failure')
117143
if (data?.code == 'ENOTFOUND') {
118-
this.log('error', `Unable to reach api.vdo.ninja`)
144+
this.log('error', `Unable to reach ${serverUrl}`)
119145
} else {
120146
this.log('error', `WebSocket ${data}`)
121147
}
@@ -251,4 +277,4 @@ class VDONinjaInstance extends InstanceBase {
251277
}
252278
}
253279

254-
runEntrypoint(VDONinjaInstance, [])
280+
runEntrypoint(VDONinjaInstance, upgradeScripts)

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "vdo-ninja",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"main": "index.js",
55
"type": "module",
66
"scripts": {
77
"format": "prettier -w ."
88
},
99
"license": "MIT",
1010
"dependencies": {
11-
"@companion-module/base": "~1.5.1",
12-
"ws": "^8.14.2"
11+
"@companion-module/base": "~1.6.0",
12+
"ws": "^8.15.1"
1313
},
1414
"repository": {
1515
"type": "git",

upgrades.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const upgradeScripts = [
2+
function (context, props) {
3+
//customWebsocketsConfig
4+
let changed = {
5+
updatedConfig: null,
6+
updatedActions: [],
7+
updatedFeedbacks: [],
8+
}
9+
if (props.config !== null) {
10+
let config = props.config
11+
if (config.wsCustom == undefined || config.wsCustom == null) {
12+
config.wsCustom = false
13+
config.wsServer = 'api.vdo.ninja'
14+
changed.updatedConfig = config
15+
}
16+
}
17+
return changed
18+
},
19+
]

yarn.lock

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf"
88
integrity sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==
99

10-
"@companion-module/base@~1.5.1":
11-
version "1.5.1"
12-
resolved "https://registry.yarnpkg.com/@companion-module/base/-/base-1.5.1.tgz#20612ba8adbe04ed2220ded9acb99c4cd877c304"
13-
integrity sha512-gpUtE7121CuPJkZMEoqh1GU6QwDoqmj4WvjI/fqyeTrqejKcKz/oSgMxSMeh7T1Gf02a5OOTpJ+aYWBlNB0BKw==
10+
"@companion-module/base@~1.6.0":
11+
version "1.6.0"
12+
resolved "https://registry.yarnpkg.com/@companion-module/base/-/base-1.6.0.tgz#1caa1b310855a757a0a55eb4b1f1b301f37615e3"
13+
integrity sha512-KnsgHtgmB36t2wlBSYyRgw4eSrm6rJXoBWClBURfssk9OgochaJtWwPLuA/SgjLAxPOnTTNt4PvHgzcVv6MjYg==
1414
dependencies:
1515
"@sentry/node" "^7.63.0"
1616
"@sentry/tracing" "^7.63.0"
1717
ajv "^8.12.0"
18+
colord "^2.9.3"
1819
ejson "^2.2.3"
1920
eventemitter3 "^4.0.7"
2021
mimic-fn "^3.0.0"
@@ -711,6 +712,11 @@ color-name@~1.1.4:
711712
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
712713
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
713714

715+
colord@^2.9.3:
716+
version "2.9.3"
717+
resolved "https://registry.yarnpkg.com/colord/-/colord-2.9.3.tgz#4f8ce919de456f1d5c1c368c307fe20f3e59fb43"
718+
integrity sha512-jeC1axXpnb0/2nn/Y1LPuLdgXBLH7aDcHu4KEKfqw3CUhX7ZpfBSlPKyqXE6btIgEzfWtrX3/tyBCaCvXvMkOw==
719+
714720
colorette@^2.0.14:
715721
version "2.0.19"
716722
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.19.tgz#cdf044f47ad41a0f4b56b3a0d5b4e6e1a2d5a798"
@@ -2178,10 +2184,10 @@ wrappy@1:
21782184
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
21792185
integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==
21802186

2181-
ws@^8.14.2:
2182-
version "8.14.2"
2183-
resolved "https://registry.yarnpkg.com/ws/-/ws-8.14.2.tgz#6c249a806eb2db7a20d26d51e7709eab7b2e6c7f"
2184-
integrity sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==
2187+
ws@^8.15.1:
2188+
version "8.15.1"
2189+
resolved "https://registry.yarnpkg.com/ws/-/ws-8.15.1.tgz#271ba33a45ca0cc477940f7f200cd7fba7ee1997"
2190+
integrity sha512-W5OZiCjXEmk0yZ66ZN82beM5Sz7l7coYxpRkzS+p9PP+ToQry8szKh+61eNktr7EA9DOwvFGhfC605jDHbP6QQ==
21852191

21862192
yallist@^4.0.0:
21872193
version "4.0.0"

0 commit comments

Comments
 (0)