Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RFC: v5 Update #241

t2t2 announced in Announcements
Jun 12, 2021 · 6 comments · 11 replies
Discussion options

Hi

As noted in obs-websocket 4.9.1 release notes, the next release (5.0) will completely change the protocol. After question flew by in obs discord about 5.0.0 support @tt2468 reached out to @haganbmj if he's still working on this. As his interest in the project has dwindled they decided to transfer the repo to obs-websocket-community-projects and asked @Panger95, @t2t2 and @VodBox to maintain it.

Since the codebase has aged quite a bit and 5.0 will be a major release this gives a good chance to do a larger update.

I'll put the ideas as individual comments in this thread, but major changes will be converting the codebase to typescript, providing an esm/modern build and API changes (some as needed by 5.0 changes, others to clean up code). Please comment on anything you feel strongly about.

You must be logged in to vote

Replies: 6 comments 11 replies

Comment options

t2t2
Jun 12, 2021
Maintainer Author

Typescript conversion, packaging and bundling:

  • Use microbundle for building/bundling
  • Dependencies:
    • events doesn't have the best typings, maybe eventemitter3 (seems to be smaller also)
    • Check others for bundle size differences (sha.js vs crypto-js)
You must be logged in to vote
4 replies
Comment options

t2t2 Jun 12, 2021
Maintainer Author

Tested bundle sizes for sha256 calculations using vite to build following files:

// src/crypto-js.ts
import sha256 from 'crypto-js/sha256'
import Base64 from 'crypto-js/enc-base64'
const test1 = 'asd'
const test2 = 'qwe'
console.log('crypto', Base64.stringify(sha256(test1 + test2)))
// src/sha-js.ts
// @ts-expect-error Could not find a declaration file for module 'sha.js/sha256' (This is with @types/sha.js)
import SHA256 from 'sha.js/sha256'
const test1 = 'asd'
const test2 = 'qwe'
console.log('sha.js', new SHA256().update(test1).update(test2).digest('base64'))
// src/sha-js-full.ts
import SHA from 'sha.js'
const test1 = 'asd'
const test2 = 'qwe'
console.log('sha.js', new SHA.sha256().update(test1).update(test2).digest('base64'))

Also tried hash.js but it didn't have typings and base64 digest support

// vite.config.js
import {resolve} from 'path'
export default {
 build: {
 rollupOptions: {
 input: {
 'crypto-js': resolve(__dirname, 'crypto-js.html'),
 'sha-js': resolve(__dirname, 'sha-js.html'),
 'sha-js-full': resolve(__dirname, 'sha-js-full.html')
 },
 output: {
 manualChunks: false // By default compiles all modules in node_modules across different entrypoints to one vendor.js output file, which we don't want for this test
 }
 }
 }
}

Build:

> tsc && vite build
vite v2.3.7 building for production...
✓ 38 modules transformed.
dist/assets/favicon.17e50649.svg 1.49kb
dist/crypto-js.html 0.49kb
dist/sha-js.html 0.55kb
dist/sha-js-full.html 0.55kb
dist/assets/___vite-browser-external_commonjs-proxy.c0efdbca.js 0.51kb / brotli: 0.25kb
dist/assets/sha-js.5033671a.js 0.17kb / brotli: 0.13kb
dist/assets/sha256.21c2fb84.js 4.26kb / brotli: 1.64kb
dist/assets/crypto-js.16b1e2ed.js 6.02kb / brotli: 2.28kb
dist/assets/sha-js-full.aee2e7cc.js 7.99kb / brotli: 2.63kb

Since sha-js and sha-js-full both use sha.js/sha256 internally the build system extracted it as a separate artifact, therefore real size for those should add sha256.1fdfd88f.js

Build crypto-js sha.js/sha256 sha.js
Size: 6.02kb / brotli: 2.28kb 4.43kb / brotli: 1.77kb 12.25kb / brotli: 4.27kb

However when checking output there was one more issue:

Uncaught TypeError: can't access property "from", o is undefined
 <anonymous> http://localhost:5000/assets/sha256.21c2fb84.js:2
 <anonymous> http://localhost:5000/assets/sha256.21c2fb84.js:2
sha256.21c2fb84.js:2:194

Turns out sha.js uses safe-buffer which requires buffer, which is native in node, webpack automatically polyfills but rollup doesn't, so adding npm install buffer

vite v2.3.7 building for production...
✓ 47 modules transformed.
dist/assets/favicon.17e50649.svg 1.49kb
dist/crypto-js.html 0.39kb
dist/sha-js.html 0.45kb
dist/sha-js-full.html 0.46kb
dist/assets/sha-js.4275ad59.js 0.11kb / brotli: 0.10kb
dist/assets/crypto-js.377ea946.js 6.43kb / brotli: 2.41kb
dist/assets/sha-js-full.d607ba88.js 7.93kb / brotli: 2.60kb
dist/assets/sha256.ae6f968a.js 31.06kb / brotli: 8.59kb
Build crypto-js sha.js/sha256 sha.js
Size: 6.43kb / brotli: 2.41kb 31.17kb / brotli: 8.69kb 38.99kb / brotli: 11.19kb

So for best size and typescript support should switch from sha.js to crypto-js

Comment options

t2t2 Jun 12, 2021
Maintainer Author

After posting this I did notice thread about webpack 5 warning about polyfilling crypto module: brix/crypto-js#354

This shouldn't really be an issue since it's fallback for getting secure number generator:

https://github.com/brix/crypto-js/blob/971c31f0c931f913d22a76ed488d9216ac04e306/src/core.js#L38

But since files aren't separated by browser and node usage it is throwing a waning. Option here is to either have instructions in readme about configuring webpack, or PRing a fix, but activity in that repo is also dead.

Looking through npm another option is jsSHA, stats:

// src/jssha.ts
import jsSHA256 from 'jssha/dist/sha256'
const test1 = 'asd'
const test2 = 'qwe'
const obj = new jsSHA256('SHA-256', 'TEXT')
obj.update(test1)
obj.update(test2)
console.log('crypto', obj.getHash('B64'))
vite v2.3.7 building for production...
✓ 15 modules transformed.
dist/assets/favicon.17e50649.svg 1.49kb
dist/jssha.html 0.39kb
dist/crypto-js.html 0.39kb
dist/assets/crypto-js.377ea946.js 6.43kb / brotli: 2.41kb
dist/assets/jssha.6c2f99ad.js 9.54kb / brotli: 3.31kb
Comment options

I tried to use eventemitter3 but we cannot supply our own types there as that is required for the lib to function properlty

Comment options

I tried to use eventemitter3 but we cannot supply our own types there as that is required for the lib to function properlty

I think they fixed this, I may be wrong though

Comment options

t2t2
Jun 12, 2021
Maintainer Author

API Changes: Convert from async connect(args = {}) to async connect(address = 'ws://localhost:4444', password?: string, options?: IdentifyMessageFields)

More of a stylistic choice but would be small size decrease and closer to WebSocket params

You must be logged in to vote
5 replies
Comment options

Remove the hardcode of ws://localhost:4444 and instead change to an optional wss://localhost:4444 or ws://localhost:4444

Comment options

there is a secure boolean atm that changes ws:// to wss://

Comment options

Niek Jun 15, 2021
Maintainer

I added the secure back then to support both secure and non-secure without breaking changes. But an address override is much better IMHO.

Comment options

I think we have to keep the non-override as some systems like @t2t2 use the regular ws protocol I believe

Comment options

The solution I came up with will prepend ws:// to the address if no prefix is present 5a91a3d

Comment options

t2t2
Jun 12, 2021
Maintainer Author

API Changes: Remove sendCallback

  • Anyone who does want callbacks can use .send(...).then((res) => { ... }, (error) => { ... }) syntax. (which sendCallback does anyway)
  • Most modern codebases would async/await promises, making it bloat (and classes can't be treeshaken)
You must be logged in to vote
1 reply
Comment options

Removed in this commit 3c6f88d

Comment options

Potentially make error logging more intuitive. Currently you will get a lot of uncaught exception errors because by default only errors on the initial socket connection will be caught. Any subsequent errors will need to currently be emitted to a catch all error handler and will be considered uncaught without this handler.

This may require a ton of additional code and I'm not sure how specific we should get with caught errors at the moment.

You must be logged in to vote
0 replies
Comment options

t2t2
Jun 12, 2021
Maintainer Author

obs-websocket 5.0 protocol changes:

From attempting to implement a client, likely new API would be:

And the rest from base eventemitter class for event related needs

You must be logged in to vote
0 replies
Comment options

t2t2
Jun 12, 2021
Maintainer Author

Node.js: Follow Node.js LTS EOL schedule and up minimum version to v12

You must be logged in to vote
1 reply
Comment options

Completed in the typescript rewrite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /