Skip to content

Commit 02a0966

Browse files
authored
Refactor code to typscript (#256)
* Start on copying over typescript code from own fork * Replace tslint with eslint * Update to use new import * make second argument not optional * Upgrade libs * Add github action to compile and test the code * Remove dtslint * Remove dist folder before building * Fix the callback method * Remove test for nodejs 10 * Disable callbacks * Swap out some libs * Ignore internal message * Revert that * Implement suggestions from review * Fix workflow file: * Prepend ws protocol if none is present * minor fixes
1 parent 36633b3 commit 02a0966

31 files changed

+5121
-6634
lines changed

.eslintignore

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
node_modules
2-
bower_components
3-
.github
4-
.travis
5-
dist
6-
coverage
7-
.nyc_output
8-
samples
1+
node_modules/
2+
bower_components/
3+
.github/
4+
.travis/
5+
dist/
6+
browser-dist/
7+
coverage/
8+
.nyc_output/
9+
samples/
910
lib/API.js
11+
test/
12+
src/typings/obsWebsocket.ts
13+
scripts/
1014

1115
# Adding an exclusion for the webpack config to make node 4 travis builds easier.
1216
webpack.config.js

.eslintrc.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"plugins": ["@typescript-eslint"],
3+
"parser": "@typescript-eslint/parser",
4+
"env": {
5+
"es2021": true,
6+
"node": true
7+
},
8+
"extends": [
9+
"xo",
10+
"xo-typescript/space"
11+
],
12+
"parserOptions": {
13+
"ecmaVersion": 12,
14+
"sourceType": "module"
15+
},
16+
"rules": {
17+
"@typescript-eslint/no-implicit-any-catch": "off",
18+
"@typescript-eslint/no-unsafe-member-access": "off",
19+
"@typescript-eslint/no-unsafe-call": "off"
20+
}
21+
}

.github/workflows/build.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
node-version: [12.x, 14.x, 16.x]
20+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Use Node.js ${{ matrix.node-version }}
25+
uses: actions/setup-node@v2
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
- uses: actions/cache@v2
29+
with:
30+
path: ~/.npm
31+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
32+
restore-keys: |
33+
${{ runner.os }}-node-
34+
# we may need this, not sure
35+
# - run: npm install json -g
36+
- run: npm ci
37+
- run: npm run build
38+
env:
39+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
- run: npm test
41+
# Currently broken
42+
#- run: npm run node-coveralls

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ coverage
2323

2424
# Exclude build outputs (they'll get added automatically by CI).
2525
dist
26+
browser-dist
2627
types/index.d.ts
2728
CHANGELOG.md

.travis/tsconfig.json

-31
This file was deleted.

.travis/tslint.json

-17
This file was deleted.

README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ OBSWebSocket.JS allows Javascript-based connections to the Open Broadcaster plug
2828
## Installation
2929

3030
```sh
31+
# with npm
3132
npm install obs-websocket-js --save
3233

34+
# with yarn
35+
yarn add obs-websocket-js
36+
37+
# with bower
3338
bower install obs-websocket-js --save
3439
```
3540

@@ -46,7 +51,7 @@ The web distributable exposes a global named `OBSWebSocket`.
4651
In node...
4752

4853
```js
49-
const OBSWebSocket = require('obs-websocket-js');
54+
const { OBSWebSocket } = require('obs-websocket-js');
5055
```
5156

5257
Create a new WebSocket connection using the following.
@@ -69,9 +74,6 @@ _Note that all response objects will supply both the original [obs-websocket][li
6974
// Promise API
7075
obs.send('RequestName', {args}) // returns Promise
7176

72-
// Callback API
73-
obs.sendCallback('RequestName', {args}, callback(err, data)) // no return value
74-
7577
// The following are additional supported requests.
7678
obs.connect({ address: 'address', password: 'password' }) // returns Promise
7779
obs.disconnect();
@@ -112,7 +114,7 @@ obs.on('error', err => {
112114
#### Example
113115
See more examples in [`\samples`](samples).
114116
```js
115-
const OBSWebSocket = require('obs-websocket-js');
117+
const { OBSWebSocket } = require('obs-websocket-js');
116118

117119
const obs = new OBSWebSocket();
118120
obs.connect({
@@ -205,7 +207,7 @@ obs.on('SwitchScenes');
205207
});
206208

207209
// Use this instead:
208-
obs.sendCallback('StartStreaming', (error) => {
210+
obs.send('StartStreaming').catch(error => {
209211
// Code here...
210212
});
211213
```

lib/Socket.js

-179
This file was deleted.

0 commit comments

Comments
 (0)