mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Compare commits
227 Commits
Author | SHA1 | Date | |
---|---|---|---|
ef5480dd7b | |||
de13707f8b | |||
7b81b81a3e | |||
2854c4e1b5 | |||
1848442e91 | |||
7a19b168b7 | |||
9adea8bab4 | |||
1db18e12b3 | |||
3be4c8ae0e | |||
437f4df84c | |||
974d6b48b2 | |||
db2b1e2dc7 | |||
98656b5d2f | |||
3c7570d814 | |||
fc3e30a826 | |||
2f0476b43c | |||
e310c7d744 | |||
8a649b89c8 | |||
95f52987ef | |||
82b8c66d51 | |||
83fb1843ee | |||
58b10069ab | |||
9cda739672 | |||
276bba050b | |||
147e49b362 | |||
bc338c1f4a | |||
e8fbb18a71 | |||
682c349831 | |||
14b311f6ab | |||
8a40f355c8 | |||
ae2f90c5c2 | |||
7aff773e2c | |||
0cdfa6e7f6 | |||
fc637eef6d | |||
b4c3141170 | |||
41257f7af5 | |||
b204f3ec90 | |||
b4926b3535 | |||
77d63e9848 | |||
94dcd58c2e | |||
689ce16f1b | |||
edc64b8336 | |||
03db5bfd8d | |||
9ad340ab02 | |||
962e26040d | |||
b07884c1da | |||
bad0fb62ed | |||
28e522ce97 | |||
c206cdfa4c | |||
c31ec077f5 | |||
afc6a60746 | |||
0a495b67e6 | |||
37ea7073d5 | |||
feaeef5a70 | |||
5586670d38 | |||
65a9139ffe | |||
3d76f078cd | |||
a1de1b11bc | |||
b5a3e3a4f0 | |||
d7b0ad4916 | |||
2a80a6b217 | |||
9df72f54d5 | |||
ef75ca36c9 | |||
84c0b698f5 | |||
3d9a4ef1e6 | |||
cf51fdceef | |||
85a52ab01f | |||
f2792c0b40 | |||
97109087a4 | |||
953f07f21f | |||
03f1035690 | |||
a561c60f7e | |||
7963b328f9 | |||
3b7e216409 | |||
9ae43a6f75 | |||
6b86de1fb9 | |||
4e6d4ac437 | |||
3b197651cc | |||
c675f1c20c | |||
e87955d59a | |||
c718d8d803 | |||
454a68d1b7 | |||
45f6f74cbe | |||
cb7412a457 | |||
a9fc82365c | |||
edc0fed9e2 | |||
1c718963ea | |||
cd40ccdb9d | |||
80e1dc2446 | |||
d03c4cc4b9 | |||
7bd434e755 | |||
640bcb90c6 | |||
08e86a1378 | |||
fefcc3937a | |||
25210dfa52 | |||
56fbb7b9cf | |||
c55d33b956 | |||
0c5bce101e | |||
0a50e2a95c | |||
5ad940924b | |||
6eb49930bf | |||
3a0d5fb190 | |||
8c2eee2e25 | |||
2e19c5f08a | |||
548b53437f | |||
e1ca9a8029 | |||
389ef2aea9 | |||
357691bad5 | |||
beadb56b05 | |||
745fb5ea29 | |||
58434cac3b | |||
c34dff17ff | |||
73f00ca195 | |||
40503b4212 | |||
4ada388828 | |||
e2d261259d | |||
677e393f47 | |||
e5dae8f5a7 | |||
650de119a4 | |||
6d7975afeb | |||
811e3f8cc8 | |||
4f3be34db1 | |||
b160fd2320 | |||
002bf08b97 | |||
a6bab968f5 | |||
408b336057 | |||
7e5716185e | |||
6d47bd6477 | |||
989c8b1857 | |||
06e9e0afab | |||
d75523c111 | |||
dacec803c6 | |||
0ae4416242 | |||
079d7eb6ca | |||
b764b4d0e5 | |||
2c2d61d908 | |||
6a323b9371 | |||
d76ff16162 | |||
952f3a586a | |||
3ecb9702ef | |||
563936ea08 | |||
13cd2704ae | |||
ae83d9dca1 | |||
66a059ecdf | |||
53936a4f76 | |||
488a095fdf | |||
1878de9f6b | |||
2a2f3441ef | |||
53c939a97f | |||
8d7ed32fc2 | |||
a1fa5dc3cb | |||
4b9a84ccee | |||
650957b6d1 | |||
6e21d041fe | |||
e2b70fd795 | |||
2d49bcc437 | |||
8b3dce3256 | |||
8cf6a1e72c | |||
a3ce7197ac | |||
5da1e55f8e | |||
661fd4efa8 | |||
047e6e11bf | |||
db8bc1af2d | |||
1386e4f91c | |||
11e2717809 | |||
57bc0a2b95 | |||
8efb30c4ee | |||
969feefcc5 | |||
db1527ab9b | |||
e88a60fa50 | |||
7ab3e38da7 | |||
7b0b836809 | |||
c8e7cfcd7b | |||
c516c89c97 | |||
c2937d7857 | |||
fe644cfa82 | |||
e84e5388a5 | |||
5e11d0ea13 | |||
a3ecb6e0e9 | |||
1d30f13fd8 | |||
b9ae28483c | |||
6a6d316e09 | |||
22d2ee6bbd | |||
68e55613fc | |||
1d44d3a109 | |||
11a641cc0d | |||
7570fbf7a4 | |||
67f7e28867 | |||
9b2d30b4d5 | |||
399815525f | |||
191cfa08d5 | |||
fcf1fa8aff | |||
73302cb060 | |||
70a8533f5e | |||
fe724db12d | |||
096a8ec6ba | |||
cc5f9c9aa7 | |||
3e14b41600 | |||
ccc2bd8667 | |||
45f86b17f1 | |||
90aebecc5b | |||
b0170ef671 | |||
d418b4e624 | |||
47505547af | |||
de2e73c9d4 | |||
ab1a43163b | |||
2556dd320f | |||
2120381c0e | |||
dc06900f7f | |||
7571dd5042 | |||
d6caa872b8 | |||
2e9829ddd1 | |||
9621ea90f7 | |||
f58da1254b | |||
a6ba7f8feb | |||
9c89f12275 | |||
41181f7260 | |||
7251862ecf | |||
c0512d5b5f | |||
b9731dff21 | |||
3981abc5ca | |||
6aef437f58 | |||
9b7752896a | |||
d074027610 | |||
b137148186 | |||
e1f6260034 | |||
b24cbaa904 |
9
.editorconfig
Normal file
9
.editorconfig
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[*]
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.{c,cpp,h,hpp}]
|
||||||
|
indent_style = tab
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
|||||||
[submodule "deps/mbedtls"]
|
|
||||||
path = deps/mbedtls
|
|
||||||
url = https://github.com/ARMmbed/mbedtls
|
|
22
.travis.yml
22
.travis.yml
@ -32,14 +32,6 @@ matrix:
|
|||||||
after_success:
|
after_success:
|
||||||
- docker exec -it xenial /root/obs-websocket/CI/package-xenial.sh
|
- docker exec -it xenial /root/obs-websocket/CI/package-xenial.sh
|
||||||
|
|
||||||
- os: osx
|
|
||||||
env: _macos_build
|
|
||||||
osx_image: xcode8.3
|
|
||||||
before_install: "./CI/install-dependencies-osx.sh"
|
|
||||||
script: "./CI/build-osx.sh"
|
|
||||||
after_success:
|
|
||||||
- ./CI/package-osx.sh
|
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
- provider: s3
|
- provider: s3
|
||||||
region: eu-central-1
|
region: eu-central-1
|
||||||
@ -51,19 +43,7 @@ deploy:
|
|||||||
acl: public_read
|
acl: public_read
|
||||||
on:
|
on:
|
||||||
repo: Palakis/obs-websocket
|
repo: Palakis/obs-websocket
|
||||||
condition:
|
condition:
|
||||||
- "$TRAVIS_OS_NAME = linux"
|
- "$TRAVIS_OS_NAME = linux"
|
||||||
- "-d /home/travis/package"
|
- "-d /home/travis/package"
|
||||||
all_branches: true
|
all_branches: true
|
||||||
- provider: s3
|
|
||||||
region: eu-central-1
|
|
||||||
bucket: obs-websocket-osx-builds
|
|
||||||
access_key_id: "$AWS_ID"
|
|
||||||
secret_access_key: "$AWS_SECRET"
|
|
||||||
local_dir: release
|
|
||||||
skip_cleanup: true
|
|
||||||
acl: public_read
|
|
||||||
on:
|
|
||||||
repo: Palakis/obs-websocket
|
|
||||||
condition: "$TRAVIS_OS_NAME = osx"
|
|
||||||
all_branches: true
|
|
||||||
|
34
BUILDING.md
34
BUILDING.md
@ -1,6 +1,9 @@
|
|||||||
# Compiling obs-websocket
|
# Compiling obs-websocket
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
You'll need [QT 5.7.0](https://download.qt.io/official_releases/qt/5.7/5.7.0/), CMake, and a working development environment for OBS Studio installed on your computer.
|
You'll need [Qt 5.10.x](https://download.qt.io/official_releases/qt/5.10/),
|
||||||
|
[CMake](https://cmake.org/download/), and a working [development environment for
|
||||||
|
OBS Studio](https://obsproject.com/wiki/install-instructions) installed on your
|
||||||
|
computer.
|
||||||
|
|
||||||
## Windows
|
## Windows
|
||||||
In cmake-gui, you'll have to set the following variables :
|
In cmake-gui, you'll have to set the following variables :
|
||||||
@ -22,8 +25,31 @@ sudo make install
|
|||||||
```
|
```
|
||||||
|
|
||||||
## OS X
|
## OS X
|
||||||
*To do*
|
As a prerequisite, you will need Xcode for your current OSX version, the command line tools, and [Homebrew](https://brew.sh/).
|
||||||
|
Homebrew's setup will guide you in getting your system set up, you should be good to go once Homebrew is successfully up and running.
|
||||||
|
|
||||||
|
Use of the Travis macOS CI scripts is recommended. Please note that these
|
||||||
|
scripts install new software and can change several settings on your system. An
|
||||||
|
existing obs-studio development environment is not required, as
|
||||||
|
`install-build-obs-macos.sh` will install it for you. If you already have a
|
||||||
|
working obs-studio development environment and have built obs-studio, you can
|
||||||
|
skip that script.
|
||||||
|
|
||||||
|
Of course, you're encouraged to dig through the contents of these scripts to
|
||||||
|
look for issues or specificities.
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone --recursive https://github.com/Palakis/obs-websocket.git
|
||||||
|
cd obs-websocket
|
||||||
|
./CI/install-dependencies-macos.sh
|
||||||
|
./CI/install-build-obs-macos.sh
|
||||||
|
./CI/build-macos.sh
|
||||||
|
./CI/package-macos.sh
|
||||||
|
```
|
||||||
|
This will result in a ready-to-use `obs-websocket.pkg` installer in the `release` subfolder.
|
||||||
|
|
||||||
## Automated Builds
|
## Automated Builds
|
||||||
- Windows : [](https://ci.appveyor.com/project/Palakis/obs-websocket/history)
|
|
||||||
- Linux & OS X : [](https://travis-ci.org/Palakis/obs-websocket)
|
- Windows: [](https://ci.appveyor.com/project/Palakis/obs-websocket/history)
|
||||||
|
- Linux: [](https://travis-ci.org/Palakis/obs-websocket)
|
||||||
|
- macOS: [](https://dev.azure.com/Palakis/obs-websocket/_build)
|
||||||
|
28
CI/build-macos.sh
Executable file
28
CI/build-macos.sh
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
OSTYPE=$(uname)
|
||||||
|
|
||||||
|
if [ "${OSTYPE}" != "Darwin" ]; then
|
||||||
|
echo "[obs-websocket - Error] macOS build script can be run on Darwin-type OS only."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
HAS_CMAKE=$(type cmake 2>/dev/null)
|
||||||
|
|
||||||
|
if [ "${HAS_CMAKE}" = "" ]; then
|
||||||
|
echo "[obs-websocket - Error] CMake not installed - please run 'install-dependencies-macos.sh' first."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#export QT_PREFIX="$(find /usr/local/Cellar/qt5 -d 1 | tail -n 1)"
|
||||||
|
|
||||||
|
echo "[obs-websocket] Building 'obs-websocket' for macOS."
|
||||||
|
mkdir -p build && cd build
|
||||||
|
cmake .. \
|
||||||
|
-DQTDIR=/usr/local/opt/qt \
|
||||||
|
-DLIBOBS_INCLUDE_DIR=../../obs-studio/libobs \
|
||||||
|
-DLIBOBS_LIB=../../obs-studio/libobs \
|
||||||
|
-DOBS_FRONTEND_LIB="$(pwd)/../../obs-studio/build/UI/obs-frontend-api/libobs-frontend-api.dylib" \
|
||||||
|
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||||
|
-DCMAKE_INSTALL_PREFIX=/usr \
|
||||||
|
&& make -j4
|
@ -1,12 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
#export QT_PREFIX="$(find /usr/local/Cellar/qt5 -d 1 | tail -n 1)"
|
|
||||||
|
|
||||||
mkdir build && cd build
|
|
||||||
cmake .. \
|
|
||||||
-DQTDIR=/usr/local/opt/qt \
|
|
||||||
-DLIBOBS_INCLUDE_DIR=../../obs-studio/libobs \
|
|
||||||
-DOBS_FRONTEND_LIB="$(pwd)/../../obs-studio/build/UI/obs-frontend-api/libobs-frontend-api.dylib" \
|
|
||||||
-DCMAKE_INSTALL_PREFIX=/usr \
|
|
||||||
&& make -j4
|
|
@ -4,5 +4,5 @@ set -ex
|
|||||||
cd /root/obs-websocket
|
cd /root/obs-websocket
|
||||||
|
|
||||||
mkdir build && cd build
|
mkdir build && cd build
|
||||||
cmake -DLIBOBS_INCLUDE_DIR="../../obs-studio/libobs" -DCMAKE_INSTALL_PREFIX=/usr ..
|
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
|
||||||
make -j4
|
make -j4
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
echo "-- Generating documentation."
|
echo "-- Generating documentation."
|
||||||
echo "-- Node version: $(node -v)"
|
echo "-- Node version: $(node -v)"
|
||||||
echo "-- NPM version: $(npm -v)"
|
echo "-- NPM version: $(npm -v)"
|
||||||
@ -10,13 +11,13 @@ npm run build
|
|||||||
echo "-- Documentation successfully generated."
|
echo "-- Documentation successfully generated."
|
||||||
|
|
||||||
if git diff --quiet; then
|
if git diff --quiet; then
|
||||||
echo "-- No documentation changes to commit."
|
echo "-- No documentation changes to commit."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "master" ]; then
|
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "4.x-current" ]; then
|
||||||
echo "-- Skipping documentation deployment because this is either a pull request or a non-master branch."
|
echo "-- Skipping documentation deployment because this is either a pull request or a non-master branch."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
REMOTE_URL="$(git config remote.origin.url)"
|
REMOTE_URL="$(git config remote.origin.url)"
|
||||||
|
41
CI/install-build-obs-macos.sh
Executable file
41
CI/install-build-obs-macos.sh
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
OSTYPE=$(uname)
|
||||||
|
|
||||||
|
if [ "${OSTYPE}" != "Darwin" ]; then
|
||||||
|
echo "[obs-websocket - Error] macOS obs-studio build script can be run on Darwin-type OS only."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
HAS_CMAKE=$(type cmake 2>/dev/null)
|
||||||
|
HAS_GIT=$(type git 2>/dev/null)
|
||||||
|
|
||||||
|
if [ "${HAS_CMAKE}" = "" ]; then
|
||||||
|
echo "[obs-websocket - Error] CMake not installed - please run 'install-dependencies-macos.sh' first."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${HAS_GIT}" = "" ]; then
|
||||||
|
echo "[obs-websocket - Error] Git not installed - please install Xcode developer tools or via Homebrew."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[obs-websocket] Downloading and unpacking OBS dependencies"
|
||||||
|
wget --quiet --retry-connrefused --waitretry=1 https://obs-nightly.s3.amazonaws.com/osx-deps-2018-08-09.tar.gz
|
||||||
|
tar -xf ./osx-deps-2018-08-09.tar.gz -C /tmp
|
||||||
|
|
||||||
|
# Build obs-studio
|
||||||
|
cd ..
|
||||||
|
echo "[obs-websocket] Cloning obs-studio from GitHub.."
|
||||||
|
git clone https://github.com/obsproject/obs-studio
|
||||||
|
cd obs-studio
|
||||||
|
OBSLatestTag=$(git describe --tags --abbrev=0)
|
||||||
|
git checkout $OBSLatestTag
|
||||||
|
mkdir build && cd build
|
||||||
|
echo "[obs-websocket] Building obs-studio.."
|
||||||
|
cmake .. \
|
||||||
|
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 \
|
||||||
|
-DDISABLE_PLUGINS=true \
|
||||||
|
-DDepsPath=/tmp/obsdeps \
|
||||||
|
-DCMAKE_PREFIX_PATH=/usr/local/opt/qt/lib/cmake \
|
||||||
|
&& make -j4
|
129
CI/install-build-obs.cmd
Normal file
129
CI/install-build-obs.cmd
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
@echo off
|
||||||
|
SETLOCAL EnableDelayedExpansion
|
||||||
|
|
||||||
|
REM Check if obs-studio build exists.
|
||||||
|
REM If the obs-studio directory does exist, check if the last OBS tag built
|
||||||
|
REM matches the latest OBS tag.
|
||||||
|
REM If the tags match, do not build obs-studio.
|
||||||
|
REM If the tags do not match, build obs-studio.
|
||||||
|
REM If the obs-studio directory doesn't exist, build obs-studio.
|
||||||
|
echo Checking for obs-studio build...
|
||||||
|
|
||||||
|
set OBSLatestTagPrePull=0
|
||||||
|
set OBSLatestTagPostPull=0
|
||||||
|
echo Latest tag pre-pull: %OBSLatestTagPrePull%
|
||||||
|
echo Latest tag post-pull: %OBSLatestTagPostPull%
|
||||||
|
|
||||||
|
REM Set up the build flag as undefined.
|
||||||
|
set "BuildOBS="
|
||||||
|
|
||||||
|
REM Check the last tag successfully built by CI.
|
||||||
|
if exist C:\projects\obs-studio-last-tag-built.txt (
|
||||||
|
set /p OBSLastTagBuilt=<C:\projects\obs-studio-last-tag-built.txt
|
||||||
|
) else (
|
||||||
|
set OBSLastTagBuilt=0
|
||||||
|
)
|
||||||
|
|
||||||
|
REM If obs-studio directory exists, run git pull and get the latest tag number.
|
||||||
|
if exist C:\projects\obs-studio\ (
|
||||||
|
echo obs-studio directory exists
|
||||||
|
echo Updating tag info
|
||||||
|
cd C:\projects\obs-studio\
|
||||||
|
git describe --tags --abbrev=0 > C:\projects\latest-obs-studio-tag-pre-pull.txt
|
||||||
|
set /p OBSLatestTagPrePull=<C:\projects\latest-obs-studio-tag-pre-pull.txt
|
||||||
|
git checkout master
|
||||||
|
git pull
|
||||||
|
git describe --tags --abbrev=0 > C:\projects\latest-obs-studio-tag-post-pull.txt
|
||||||
|
set /p OBSLatestTagPostPull=<C:\projects\latest-obs-studio-tag-post-pull.txt
|
||||||
|
set /p OBSLatestTag=<C:\projects\latest-obs-studio-tag-post-pull.txt
|
||||||
|
echo %OBSLatestTagPostPull%> C:\projects\latest-obs-studio-tag.txt
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Check the obs-studio tags for mismatches.
|
||||||
|
REM If a new tag was pulled, set the build flag.
|
||||||
|
if not %OBSLatestTagPrePull%==%OBSLatestTagPostPull% (
|
||||||
|
echo Latest tag pre-pull: %OBSLatestTagPrePull%
|
||||||
|
echo Latest tag post-pull: %OBSLatestTagPostPull%
|
||||||
|
echo Tags do not match. Need to rebuild OBS.
|
||||||
|
set BuildOBS=true
|
||||||
|
)
|
||||||
|
|
||||||
|
REM If the latest git tag doesn't match the last built tag, set the build flag.
|
||||||
|
if not %OBSLatestTagPostPull%==%OBSLastTagBuilt% (
|
||||||
|
echo Last built OBS tag: %OBSLastTagBuilt%
|
||||||
|
echo Latest tag post-pull: %OBSLatestTagPostPull%
|
||||||
|
echo Tags do not match. Need to rebuild OBS.
|
||||||
|
set BuildOBS=true
|
||||||
|
)
|
||||||
|
|
||||||
|
REM If obs-studio directory does not exist, clone the git repo, get the latest
|
||||||
|
REM tag number, and set the build flag.
|
||||||
|
if not exist C:\projects\obs-studio (
|
||||||
|
echo obs-studio directory does not exist
|
||||||
|
git clone https://github.com/obsproject/obs-studio
|
||||||
|
cd C:\projects\obs-studio\
|
||||||
|
git describe --tags --abbrev=0 > C:\projects\obs-studio-latest-tag.txt
|
||||||
|
set /p OBSLatestTag=<C:\projects\obs-studio-latest-tag.txt
|
||||||
|
set BuildOBS=true
|
||||||
|
)
|
||||||
|
|
||||||
|
REM If the needed obs-studio libs for this build_config do not exist,
|
||||||
|
REM set the build flag.
|
||||||
|
if not exist C:\projects\obs-studio\build32\libobs\%build_config%\obs.lib (
|
||||||
|
echo obs-studio\build32\libobs\%build_config%\obs.lib does not exist
|
||||||
|
set BuildOBS=true
|
||||||
|
)
|
||||||
|
if not exist C:\projects\obs-studio\build32\UI\obs-frontend-api\%build_config%\obs-frontend-api.lib (
|
||||||
|
echo obs-studio\build32\UI\obs-frontend-api\%build_config%\obs-frontend-api.lib does not exist
|
||||||
|
set BuildOBS=true
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Some debug info
|
||||||
|
echo:
|
||||||
|
echo Latest tag pre-pull: %OBSLatestTagPrePull%
|
||||||
|
echo Latest tag post-pull: %OBSLatestTagPostPull%
|
||||||
|
echo Latest tag: %OBSLatestTag%
|
||||||
|
echo Last built OBS tag: %OBSLastTagBuilt%
|
||||||
|
|
||||||
|
if defined BuildOBS (
|
||||||
|
echo BuildOBS: true
|
||||||
|
) else (
|
||||||
|
echo BuildOBS: false
|
||||||
|
)
|
||||||
|
echo:
|
||||||
|
|
||||||
|
REM If the build flag is set, build obs-studio.
|
||||||
|
if defined BuildOBS (
|
||||||
|
echo Building obs-studio...
|
||||||
|
echo git checkout %OBSLatestTag%
|
||||||
|
git checkout %OBSLatestTag%
|
||||||
|
echo:
|
||||||
|
echo Removing previous build dirs...
|
||||||
|
if exist build rmdir /s /q C:\projects\obs-studio\build
|
||||||
|
if exist build32 rmdir /s /q C:\projects\obs-studio\build32
|
||||||
|
if exist build64 rmdir /s /q C:\projects\obs-studio\build64
|
||||||
|
echo Making new build dirs...
|
||||||
|
mkdir build
|
||||||
|
mkdir build32
|
||||||
|
mkdir build64
|
||||||
|
echo Running cmake for obs-studio %OBSLatestTag% 32-bit...
|
||||||
|
cd ./build32
|
||||||
|
cmake -G "Visual Studio 14 2015" -DDISABLE_PLUGINS=true -DCOPIED_DEPENDENCIES=false -DCOPY_DEPENDENCIES=true ..
|
||||||
|
echo:
|
||||||
|
echo:
|
||||||
|
echo Running cmake for obs-studio %OBSLatestTag% 64-bit...
|
||||||
|
cd ../build64
|
||||||
|
cmake -G "Visual Studio 14 2015 Win64" -DDISABLE_PLUGINS=true -DCOPIED_DEPENDENCIES=false -DCOPY_DEPENDENCIES=true ..
|
||||||
|
echo:
|
||||||
|
echo:
|
||||||
|
echo Building obs-studio %OBSLatestTag% 32-bit ^(Build Config: %build_config%^)...
|
||||||
|
call msbuild /m /p:Configuration=%build_config% C:\projects\obs-studio\build32\obs-studio.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
||||||
|
echo Building obs-studio %OBSLatestTag% 64-bit ^(Build Config: %build_config%^)...
|
||||||
|
call msbuild /m /p:Configuration=%build_config% C:\projects\obs-studio\build64\obs-studio.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
||||||
|
cd ..
|
||||||
|
git describe --tags --abbrev=0 > C:\projects\obs-studio-last-tag-built.txt
|
||||||
|
set /p OBSLastTagBuilt=<C:\projects\obs-studio-last-tag-built.txt
|
||||||
|
) else (
|
||||||
|
echo Last OBS tag built is: %OBSLastTagBuilt%
|
||||||
|
echo No need to rebuild OBS.
|
||||||
|
)
|
61
CI/install-dependencies-macos.sh
Executable file
61
CI/install-dependencies-macos.sh
Executable file
@ -0,0 +1,61 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
OSTYPE=$(uname)
|
||||||
|
|
||||||
|
if [ "${OSTYPE}" != "Darwin" ]; then
|
||||||
|
echo "[obs-websocket - Error] macOS install dependencies script can be run on Darwin-type OS only."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
HAS_BREW=$(type brew 2>/dev/null)
|
||||||
|
|
||||||
|
if [ "${HAS_BREW}" = "" ]; then
|
||||||
|
echo "[obs-websocket - Error] Please install Homebrew (https://www.brew.sh/) to build obs-websocket on macOS."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# OBS Studio deps
|
||||||
|
echo "[obs-websocket] Updating Homebrew.."
|
||||||
|
brew update >/dev/null
|
||||||
|
echo "[obs-websocket] Checking installed Homebrew formulas.."
|
||||||
|
BREW_PACKAGES=$(brew list)
|
||||||
|
BREW_DEPENDENCIES="jack speexdsp ccache swig mbedtls"
|
||||||
|
|
||||||
|
for DEPENDENCY in ${BREW_DEPENDENCIES}; do
|
||||||
|
if echo "${BREW_PACKAGES}" | grep -q "^${DEPENDENCY}\$"; then
|
||||||
|
echo "[obs-websocket] Upgrading OBS-Studio dependency '${DEPENDENCY}'.."
|
||||||
|
brew upgrade ${DEPENDENCY} 2>/dev/null
|
||||||
|
else
|
||||||
|
echo "[obs-websocket] Installing OBS-Studio dependency '${DEPENDENCY}'.."
|
||||||
|
brew install ${DEPENDENCY} 2>/dev/null
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# qtwebsockets deps
|
||||||
|
echo "[obs-websocket] Installing obs-websocket dependency 'QT 5.10.1'.."
|
||||||
|
# =!= NOTICE =!=
|
||||||
|
# When building QT5 from sources on macOS 10.13+, use local qt5 formula:
|
||||||
|
# brew install ./CI/macos/qt.rb
|
||||||
|
# Pouring from the bottle is much quicker though, so use bottle for now.
|
||||||
|
# =!= NOTICE =!=
|
||||||
|
|
||||||
|
brew install https://gist.githubusercontent.com/DDRBoxman/b3956fab6073335a4bf151db0dcbd4ad/raw/ed1342a8a86793ea8c10d8b4d712a654da121ace/qt.rb
|
||||||
|
|
||||||
|
# Pin this version of QT5 to avoid `brew upgrade`
|
||||||
|
# upgrading it to incompatible version
|
||||||
|
brew pin qt
|
||||||
|
|
||||||
|
# Fetch and install Packages app
|
||||||
|
# =!= NOTICE =!=
|
||||||
|
# Installs a LaunchDaemon under /Library/LaunchDaemons/fr.whitebox.packages.build.dispatcher.plist
|
||||||
|
# =!= NOTICE =!=
|
||||||
|
|
||||||
|
HAS_PACKAGES=$(type packagesbuild 2>/dev/null)
|
||||||
|
|
||||||
|
if [ "${HAS_PACKAGES}" = "" ]; then
|
||||||
|
echo "[obs-websocket] Installing Packaging app (might require password due to 'sudo').."
|
||||||
|
curl -o './Packages.pkg' --retry-connrefused -s --retry-delay 1 'https://s3-us-west-2.amazonaws.com/obs-nightly/Packages.pkg'
|
||||||
|
sudo installer -pkg ./Packages.pkg -target /
|
||||||
|
fi
|
@ -1,28 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
# OBS Studio deps
|
|
||||||
brew update
|
|
||||||
brew install ffmpeg
|
|
||||||
brew install libav
|
|
||||||
|
|
||||||
# qtwebsockets deps
|
|
||||||
brew install qt5
|
|
||||||
#echo "Qt path: $(find /usr/local/Cellar/qt5 -d 1 | tail -n 1)"
|
|
||||||
|
|
||||||
# Build obs-studio
|
|
||||||
cd ..
|
|
||||||
git clone --recursive https://github.com/jp9000/obs-studio
|
|
||||||
cd obs-studio
|
|
||||||
git checkout 19.0.3
|
|
||||||
mkdir build && cd build
|
|
||||||
cmake .. \
|
|
||||||
-DCMAKE_PREFIX_PATH=/usr/local/opt/qt/lib/cmake \
|
|
||||||
&& make -j4
|
|
||||||
|
|
||||||
sudo make install
|
|
||||||
|
|
||||||
# Packages app
|
|
||||||
cd ..
|
|
||||||
curl -L -O https://www.slepin.fr/obs-websocket/ci/Packages.pkg -f --retry 5 -C -
|
|
||||||
sudo installer -pkg ./Packages.pkg -target /
|
|
@ -1,57 +1,19 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
# OBS Studio deps
|
add-apt-repository -y ppa:obsproject/obs-studio
|
||||||
apt-get -qq update
|
apt-get -qq update
|
||||||
apt-get install -y \
|
|
||||||
libc-dev-bin libc6-dev \
|
|
||||||
git \
|
|
||||||
build-essential
|
|
||||||
|
|
||||||
apt-get install -y \
|
apt-get install -y \
|
||||||
build-essential \
|
libc-dev-bin \
|
||||||
checkinstall \
|
libc6-dev git \
|
||||||
cmake \
|
build-essential \
|
||||||
libasound2-dev \
|
checkinstall \
|
||||||
libavcodec-dev \
|
cmake \
|
||||||
libavdevice-dev \
|
obs-studio \
|
||||||
libavfilter-dev \
|
libqt5websockets5-dev
|
||||||
libavformat-dev \
|
|
||||||
libavutil-dev \
|
|
||||||
libcurl4-openssl-dev \
|
|
||||||
libfontconfig-dev \
|
|
||||||
libfreetype6-dev \
|
|
||||||
libgl1-mesa-dev \
|
|
||||||
libjack-jackd2-dev \
|
|
||||||
libjansson-dev \
|
|
||||||
libpulse-dev \
|
|
||||||
libqt5x11extras5-dev \
|
|
||||||
libspeexdsp-dev \
|
|
||||||
libswresample-dev \
|
|
||||||
libswscale-dev \
|
|
||||||
libudev-dev \
|
|
||||||
libv4l-dev \
|
|
||||||
libvlc-dev \
|
|
||||||
libx11-dev \
|
|
||||||
libx264-dev \
|
|
||||||
libxcb-shm0-dev \
|
|
||||||
libxcb-xinerama0-dev \
|
|
||||||
libxcomposite-dev \
|
|
||||||
libxinerama-dev \
|
|
||||||
pkg-config \
|
|
||||||
qtbase5-dev
|
|
||||||
|
|
||||||
# obs-websocket deps
|
# Dirty hack
|
||||||
apt-get install -y libqt5websockets5-dev
|
wget -O /usr/include/obs/obs-frontend-api.h https://raw.githubusercontent.com/obsproject/obs-studio/master/UI/obs-frontend-api/obs-frontend-api.h
|
||||||
|
|
||||||
# Build obs-studio
|
|
||||||
cd /root
|
|
||||||
git clone https://github.com/jp9000/obs-studio ./obs-studio
|
|
||||||
cd obs-studio
|
|
||||||
git checkout 19.0.3
|
|
||||||
mkdir build && cd build
|
|
||||||
cmake -DUNIX_STRUCTURE=1 -DCMAKE_INSTALL_PREFIX=/usr ..
|
|
||||||
make -j4
|
|
||||||
make install
|
|
||||||
|
|
||||||
ldconfig
|
ldconfig
|
||||||
|
6
CI/install-setup-qt.cmd
Normal file
6
CI/install-setup-qt.cmd
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
@echo off
|
||||||
|
|
||||||
|
REM Set default values to use AppVeyor's built-in Qt.
|
||||||
|
set QTDIR32=C:\Qt\5.10.1\msvc2015
|
||||||
|
set QTDIR64=C:\Qt\5.10.1\msvc2015_64
|
||||||
|
set QTCompileVersion=5.10.1
|
@ -635,7 +635,7 @@
|
|||||||
<key>OVERWRITE_PERMISSIONS</key>
|
<key>OVERWRITE_PERMISSIONS</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>VERSION</key>
|
<key>VERSION</key>
|
||||||
<string>4.0.0</string>
|
<string>4.5.1</string>
|
||||||
</dict>
|
</dict>
|
||||||
<key>PROJECT_COMMENTS</key>
|
<key>PROJECT_COMMENTS</key>
|
||||||
<dict>
|
<dict>
|
163
CI/macos/qt.rb
Normal file
163
CI/macos/qt.rb
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
# Patches for Qt must be at the very least submitted to Qt's Gerrit codereview
|
||||||
|
# rather than their bug-report Jira. The latter is rarely reviewed by Qt.
|
||||||
|
class Qt < Formula
|
||||||
|
desc "Cross-platform application and UI framework"
|
||||||
|
homepage "https://www.qt.io/"
|
||||||
|
url "https://download.qt.io/archive/qt/5.10/5.10.1/single/qt-everywhere-src-5.10.1.tar.xz"
|
||||||
|
mirror "https://mirrorservice.org/sites/download.qt-project.org/official_releases/qt/5.10/5.10.1/single/qt-everywhere-src-5.10.1.tar.xz"
|
||||||
|
sha256 "05ffba7b811b854ed558abf2be2ddbd3bb6ddd0b60ea4b5da75d277ac15e740a"
|
||||||
|
head "https://code.qt.io/qt/qt5.git", :branch => "5.10.1", :shallow => false
|
||||||
|
|
||||||
|
bottle do
|
||||||
|
sha256 "8b4bad005596a5f8790150fe455db998ac2406f4e0f04140d6656205d844d266" => :high_sierra
|
||||||
|
sha256 "9c488554935fb573554a4e36d36d3c81e47245b7fefc4b61edef894e67ba1740" => :sierra
|
||||||
|
sha256 "c0407afba5951df6cc4c6f6c1c315972bd41c99cecb4e029919c4c15ab6f7bdc" => :el_capitan
|
||||||
|
end
|
||||||
|
|
||||||
|
keg_only "Qt 5 has CMake issues when linked"
|
||||||
|
|
||||||
|
option "with-docs", "Build documentation"
|
||||||
|
option "with-examples", "Build examples"
|
||||||
|
|
||||||
|
deprecated_option "with-mysql" => "with-mysql-client"
|
||||||
|
|
||||||
|
# OS X 10.7 Lion is still supported in Qt 5.5, but is no longer a reference
|
||||||
|
# configuration and thus untested in practice. Builds on OS X 10.7 have been
|
||||||
|
# reported to fail: <https://github.com/Homebrew/homebrew/issues/45284>.
|
||||||
|
depends_on :macos => :mountain_lion
|
||||||
|
|
||||||
|
depends_on "pkg-config" => :build
|
||||||
|
depends_on :xcode => :build
|
||||||
|
depends_on "mysql-client" => :optional
|
||||||
|
depends_on "postgresql" => :optional
|
||||||
|
|
||||||
|
# Restore `.pc` files for framework-based build of Qt 5 on OS X. This
|
||||||
|
# partially reverts <https://codereview.qt-project.org/#/c/140954/> merged
|
||||||
|
# between the 5.5.1 and 5.6.0 releases. (Remove this as soon as feasible!)
|
||||||
|
#
|
||||||
|
# Core formulae known to fail without this patch (as of 2016-10-15):
|
||||||
|
# * gnuplot (with `--with-qt` option)
|
||||||
|
# * mkvtoolnix (with `--with-qt` option, silent build failure)
|
||||||
|
# * poppler (with `--with-qt` option)
|
||||||
|
patch do
|
||||||
|
url "https://raw.githubusercontent.com/Homebrew/formula-patches/e8fe6567/qt5/restore-pc-files.patch"
|
||||||
|
sha256 "48ff18be2f4050de7288bddbae7f47e949512ac4bcd126c2f504be2ac701158b"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Fix compile error on macOS 10.13 around QFixed:
|
||||||
|
# https://github.com/Homebrew/homebrew-core/issues/27095
|
||||||
|
# https://bugreports.qt.io/browse/QTBUG-67545
|
||||||
|
patch do
|
||||||
|
url "https://raw.githubusercontent.com/z00m1n/formula-patches/0de0e229/qt/QTBUG-67545.patch"
|
||||||
|
sha256 "4a115097c7582c7dce4207f5500d13feb8c990eb8a05a43f41953985976ebe6c"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Fix compile error on macOS 10.13 caused by qtlocation dependency
|
||||||
|
# mapbox-gl-native using Boost 1.62.0 does not build with C++ 17:
|
||||||
|
# https://github.com/Homebrew/homebrew-core/issues/27095
|
||||||
|
# https://bugreports.qt.io/browse/QTBUG-67810
|
||||||
|
patch do
|
||||||
|
url "https://raw.githubusercontent.com/z00m1n/formula-patches/a1a1f0dd/qt/QTBUG-67810.patch"
|
||||||
|
sha256 "8ee0bf71df1043f08ebae3aa35036be29c4d9ebff8a27e3b0411a6bd635e9382"
|
||||||
|
end
|
||||||
|
|
||||||
|
def install
|
||||||
|
args = %W[
|
||||||
|
-verbose
|
||||||
|
-prefix #{prefix}
|
||||||
|
-release
|
||||||
|
-opensource -confirm-license
|
||||||
|
-system-zlib
|
||||||
|
-qt-libpng
|
||||||
|
-qt-libjpeg
|
||||||
|
-qt-freetype
|
||||||
|
-qt-pcre
|
||||||
|
-nomake tests
|
||||||
|
-no-rpath
|
||||||
|
-pkg-config
|
||||||
|
-dbus-runtime
|
||||||
|
-no-assimp
|
||||||
|
]
|
||||||
|
|
||||||
|
args << "-nomake" << "examples" if build.without? "examples"
|
||||||
|
|
||||||
|
if build.with? "mysql-client"
|
||||||
|
args << "-plugin-sql-mysql"
|
||||||
|
(buildpath/"brew_shim/mysql_config").write <<~EOS
|
||||||
|
#!/bin/sh
|
||||||
|
if [ x"$1" = x"--libs" ]; then
|
||||||
|
mysql_config --libs | sed "s/-lssl -lcrypto//"
|
||||||
|
else
|
||||||
|
exec mysql_config "$@"
|
||||||
|
fi
|
||||||
|
EOS
|
||||||
|
chmod 0755, "brew_shim/mysql_config"
|
||||||
|
args << "-mysql_config" << buildpath/"brew_shim/mysql_config"
|
||||||
|
end
|
||||||
|
|
||||||
|
args << "-plugin-sql-psql" if build.with? "postgresql"
|
||||||
|
|
||||||
|
system "./configure", *args
|
||||||
|
system "make"
|
||||||
|
ENV.deparallelize
|
||||||
|
system "make", "install"
|
||||||
|
|
||||||
|
if build.with? "docs"
|
||||||
|
system "make", "docs"
|
||||||
|
system "make", "install_docs"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Some config scripts will only find Qt in a "Frameworks" folder
|
||||||
|
frameworks.install_symlink Dir["#{lib}/*.framework"]
|
||||||
|
|
||||||
|
# The pkg-config files installed suggest that headers can be found in the
|
||||||
|
# `include` directory. Make this so by creating symlinks from `include` to
|
||||||
|
# the Frameworks' Headers folders.
|
||||||
|
Pathname.glob("#{lib}/*.framework/Headers") do |path|
|
||||||
|
include.install_symlink path => path.parent.basename(".framework")
|
||||||
|
end
|
||||||
|
|
||||||
|
# Move `*.app` bundles into `libexec` to expose them to `brew linkapps` and
|
||||||
|
# because we don't like having them in `bin`.
|
||||||
|
# (Note: This move breaks invocation of Assistant via the Help menu
|
||||||
|
# of both Designer and Linguist as that relies on Assistant being in `bin`.)
|
||||||
|
libexec.mkpath
|
||||||
|
Pathname.glob("#{bin}/*.app") { |app| mv app, libexec }
|
||||||
|
end
|
||||||
|
|
||||||
|
def caveats; <<~EOS
|
||||||
|
We agreed to the Qt opensource license for you.
|
||||||
|
If this is unacceptable you should uninstall.
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
|
||||||
|
test do
|
||||||
|
(testpath/"hello.pro").write <<~EOS
|
||||||
|
QT += core
|
||||||
|
QT -= gui
|
||||||
|
TARGET = hello
|
||||||
|
CONFIG += console
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
TEMPLATE = app
|
||||||
|
SOURCES += main.cpp
|
||||||
|
EOS
|
||||||
|
|
||||||
|
(testpath/"main.cpp").write <<~EOS
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
qDebug() << "Hello World!";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EOS
|
||||||
|
|
||||||
|
system bin/"qmake", testpath/"hello.pro"
|
||||||
|
system "make"
|
||||||
|
assert_predicate testpath/"hello", :exist?
|
||||||
|
assert_predicate testpath/"main.o", :exist?
|
||||||
|
system "./hello"
|
||||||
|
end
|
||||||
|
end
|
@ -2,44 +2,50 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "-- Preparing package build"
|
OSTYPE=$(uname)
|
||||||
export QT_CELLAR_PREFIX="$(find /usr/local/Cellar/qt -d 1 | tail -n 1)"
|
|
||||||
|
if [ "${OSTYPE}" != "Darwin" ]; then
|
||||||
|
echo "[obs-websocket - Error] macOS package script can be run on Darwin-type OS only."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[obs-websocket] Preparing package build"
|
||||||
|
export QT_CELLAR_PREFIX="$(/usr/bin/find /usr/local/Cellar/qt -d 1 | sort -t '.' -k 1,1n -k 2,2n -k 3,3n | tail -n 1)"
|
||||||
|
|
||||||
export WS_LIB="/usr/local/opt/qt/lib/QtWebSockets.framework/QtWebSockets"
|
export WS_LIB="/usr/local/opt/qt/lib/QtWebSockets.framework/QtWebSockets"
|
||||||
export NET_LIB="/usr/local/opt/qt/lib/QtNetwork.framework/QtNetwork"
|
export NET_LIB="/usr/local/opt/qt/lib/QtNetwork.framework/QtNetwork"
|
||||||
|
|
||||||
export GIT_HASH=$(git rev-parse --short HEAD)
|
export GIT_HASH=$(git rev-parse --short HEAD)
|
||||||
|
export GIT_BRANCH_OR_TAG=$(git name-rev --name-only HEAD | awk -F/ '{print $NF}')
|
||||||
|
|
||||||
export VERSION="$GIT_HASH-$TRAVIS_BRANCH"
|
export VERSION="$GIT_HASH-$GIT_BRANCH_OR_TAG"
|
||||||
export LATEST_VERSION="$TRAVIS_BRANCH"
|
export LATEST_VERSION="$GIT_BRANCH_OR_TAG"
|
||||||
if [ -n "${TRAVIS_TAG}" ]; then
|
|
||||||
export VERSION="$TRAVIS_TAG"
|
|
||||||
export LATEST_VERSION="$TRAVIS_TAG"
|
|
||||||
fi
|
|
||||||
|
|
||||||
export FILENAME="obs-websocket-$VERSION.pkg"
|
export FILENAME="obs-websocket-$VERSION.pkg"
|
||||||
export LATEST_FILENAME="obs-websocket-latest-$LATEST_VERSION.pkg"
|
export LATEST_FILENAME="obs-websocket-latest-$LATEST_VERSION.pkg"
|
||||||
|
|
||||||
echo "-- Copying Qt dependencies"
|
echo "[obs-websocket] Copying Qt dependencies"
|
||||||
cp $WS_LIB ./build
|
if [ ! -f ./build/$(basename $WS_LIB) ]; then cp $WS_LIB ./build; fi
|
||||||
cp $NET_LIB ./build
|
if [ ! -f ./build/$(basename $NET_LIB) ]; then cp $NET_LIB ./build; fi
|
||||||
|
|
||||||
chmod +rw ./build/QtWebSockets ./build/QtNetwork
|
chmod +rw ./build/QtWebSockets ./build/QtNetwork
|
||||||
|
|
||||||
echo "-- Modifying QtNetwork"
|
echo "[obs-websocket] Modifying QtNetwork"
|
||||||
install_name_tool \
|
install_name_tool \
|
||||||
|
-id @rpath/QtNetwork \
|
||||||
-change /usr/local/opt/qt/lib/QtNetwork.framework/Versions/5/QtNetwork @rpath/QtNetwork \
|
-change /usr/local/opt/qt/lib/QtNetwork.framework/Versions/5/QtNetwork @rpath/QtNetwork \
|
||||||
-change $QT_CELLAR_PREFIX/lib/QtCore.framework/Versions/5/QtCore @rpath/QtCore \
|
-change $QT_CELLAR_PREFIX/lib/QtCore.framework/Versions/5/QtCore @rpath/QtCore \
|
||||||
./build/QtNetwork
|
./build/QtNetwork
|
||||||
|
|
||||||
echo "-- Modifying QtWebSockets"
|
echo "[obs-websocket] Modifying QtWebSockets"
|
||||||
install_name_tool \
|
install_name_tool \
|
||||||
|
-id @rpath/QtWebSockets \
|
||||||
-change /usr/local/opt/qt/lib/QtWebSockets.framework/Versions/5/QtWebSockets @rpath/QtWebSockets \
|
-change /usr/local/opt/qt/lib/QtWebSockets.framework/Versions/5/QtWebSockets @rpath/QtWebSockets \
|
||||||
-change $QT_CELLAR_PREFIX/lib/QtNetwork.framework/Versions/5/QtNetwork @rpath/QtNetwork \
|
-change $QT_CELLAR_PREFIX/lib/QtNetwork.framework/Versions/5/QtNetwork @rpath/QtNetwork \
|
||||||
-change $QT_CELLAR_PREFIX/lib/QtCore.framework/Versions/5/QtCore @rpath/QtCore \
|
-change $QT_CELLAR_PREFIX/lib/QtCore.framework/Versions/5/QtCore @rpath/QtCore \
|
||||||
./build/QtWebSockets
|
./build/QtWebSockets
|
||||||
|
|
||||||
echo "-- Modifying obs-websocket.so"
|
echo "[obs-websocket] Modifying obs-websocket.so"
|
||||||
install_name_tool \
|
install_name_tool \
|
||||||
-change /usr/local/opt/qt/lib/QtWebSockets.framework/Versions/5/QtWebSockets @rpath/QtWebSockets \
|
-change /usr/local/opt/qt/lib/QtWebSockets.framework/Versions/5/QtWebSockets @rpath/QtWebSockets \
|
||||||
-change /usr/local/opt/qt/lib/QtWidgets.framework/Versions/5/QtWidgets @rpath/QtWidgets \
|
-change /usr/local/opt/qt/lib/QtWidgets.framework/Versions/5/QtWidgets @rpath/QtWidgets \
|
||||||
@ -49,18 +55,18 @@ install_name_tool \
|
|||||||
./build/obs-websocket.so
|
./build/obs-websocket.so
|
||||||
|
|
||||||
# Check if replacement worked
|
# Check if replacement worked
|
||||||
echo "-- Dependencies for QtNetwork"
|
echo "[obs-websocket] Dependencies for QtNetwork"
|
||||||
otool -L ./build/QtNetwork
|
otool -L ./build/QtNetwork
|
||||||
echo "-- Dependencies for QtWebSockets"
|
echo "[obs-websocket] Dependencies for QtWebSockets"
|
||||||
otool -L ./build/QtWebSockets
|
otool -L ./build/QtWebSockets
|
||||||
echo "-- Dependencies for obs-websocket"
|
echo "[obs-websocket] Dependencies for obs-websocket"
|
||||||
otool -L ./build/obs-websocket.so
|
otool -L ./build/obs-websocket.so
|
||||||
|
|
||||||
chmod -w ./build/QtWebSockets ./build/QtNetwork
|
chmod -w ./build/QtWebSockets ./build/QtNetwork
|
||||||
|
|
||||||
echo "-- Actual package build"
|
echo "[obs-websocket] Actual package build"
|
||||||
packagesbuild ./CI/osx/obs-websocket.pkgproj
|
packagesbuild ./CI/macos/obs-websocket.pkgproj
|
||||||
|
|
||||||
echo "-- Renaming obs-websocket.pkg to $FILENAME"
|
echo "[obs-websocket] Renaming obs-websocket.pkg to $FILENAME"
|
||||||
mv ./release/obs-websocket.pkg ./release/$FILENAME
|
mv ./release/obs-websocket.pkg ./release/$FILENAME
|
||||||
cp ./release/$FILENAME ./release/$LATEST_FILENAME
|
cp ./release/$FILENAME ./release/$LATEST_FILENAME
|
116
CMakeLists.txt
116
CMakeLists.txt
@ -6,55 +6,60 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
set(CMAKE_AUTOUIC ON)
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
|
||||||
|
if (WIN32 OR APPLE)
|
||||||
include(external/FindLibObs.cmake)
|
include(external/FindLibObs.cmake)
|
||||||
|
endif()
|
||||||
|
|
||||||
find_package(LibObs REQUIRED)
|
find_package(LibObs REQUIRED)
|
||||||
find_package(Qt5Core REQUIRED)
|
find_package(Qt5Core REQUIRED)
|
||||||
find_package(Qt5WebSockets REQUIRED)
|
find_package(Qt5WebSockets REQUIRED)
|
||||||
find_package(Qt5Widgets REQUIRED)
|
find_package(Qt5Widgets REQUIRED)
|
||||||
|
|
||||||
add_subdirectory(deps/mbedtls EXCLUDE_FROM_ALL)
|
set(obs-websocket_SOURCES
|
||||||
set(ENABLE_PROGRAMS false)
|
src/obs-websocket.cpp
|
||||||
|
src/WSServer.cpp
|
||||||
set(obs-websocket_SOURCES
|
src/WSRequestHandler.cpp
|
||||||
obs-websocket.cpp
|
src/WSRequestHandler_General.cpp
|
||||||
WSServer.cpp
|
src/WSRequestHandler_Profiles.cpp
|
||||||
WSRequestHandler.cpp
|
src/WSRequestHandler_Recording.cpp
|
||||||
WSEvents.cpp
|
src/WSRequestHandler_ReplayBuffer.cpp
|
||||||
Config.cpp
|
src/WSRequestHandler_SceneCollections.cpp
|
||||||
Utils.cpp
|
src/WSRequestHandler_Scenes.cpp
|
||||||
forms/settings-dialog.cpp)
|
src/WSRequestHandler_SceneItems.cpp
|
||||||
|
src/WSRequestHandler_Sources.cpp
|
||||||
|
src/WSRequestHandler_Streaming.cpp
|
||||||
|
src/WSRequestHandler_StudioMode.cpp
|
||||||
|
src/WSRequestHandler_Transitions.cpp
|
||||||
|
src/WSEvents.cpp
|
||||||
|
src/Config.cpp
|
||||||
|
src/Utils.cpp
|
||||||
|
src/forms/settings-dialog.cpp)
|
||||||
|
|
||||||
set(obs-websocket_HEADERS
|
set(obs-websocket_HEADERS
|
||||||
obs-websocket.h
|
src/obs-websocket.h
|
||||||
WSServer.h
|
src/WSServer.h
|
||||||
WSRequestHandler.h
|
src/WSRequestHandler.h
|
||||||
WSEvents.h
|
src/WSEvents.h
|
||||||
Config.h
|
src/Config.h
|
||||||
Utils.h
|
src/Utils.h
|
||||||
forms/settings-dialog.h)
|
src/forms/settings-dialog.h)
|
||||||
|
|
||||||
# --- Platform-independent build settings ---
|
# --- Platform-independent build settings ---
|
||||||
add_library(obs-websocket MODULE
|
add_library(obs-websocket MODULE
|
||||||
${obs-websocket_SOURCES}
|
${obs-websocket_SOURCES}
|
||||||
${obs-websocket_HEADERS})
|
${obs-websocket_HEADERS})
|
||||||
|
|
||||||
add_dependencies(obs-websocket mbedcrypto)
|
include_directories(
|
||||||
|
|
||||||
include_directories(
|
|
||||||
"${LIBOBS_INCLUDE_DIR}/../UI/obs-frontend-api"
|
"${LIBOBS_INCLUDE_DIR}/../UI/obs-frontend-api"
|
||||||
${Qt5Core_INCLUDES}
|
${Qt5Core_INCLUDES}
|
||||||
${Qt5WebSockets_INCLUDES}
|
${Qt5WebSockets_INCLUDES}
|
||||||
${Qt5Widgets_INCLUDES}
|
${Qt5Widgets_INCLUDES})
|
||||||
${mbedcrypto_INCLUDES}
|
|
||||||
"${CMAKE_SOURCE_DIR}/deps/mbedtls/include")
|
|
||||||
|
|
||||||
target_link_libraries(obs-websocket
|
target_link_libraries(obs-websocket
|
||||||
libobs
|
libobs
|
||||||
Qt5::Core
|
Qt5::Core
|
||||||
Qt5::WebSockets
|
Qt5::WebSockets
|
||||||
Qt5::Widgets
|
Qt5::Widgets)
|
||||||
mbedcrypto)
|
|
||||||
|
|
||||||
# --- End of section ---
|
# --- End of section ---
|
||||||
|
|
||||||
@ -62,7 +67,7 @@ target_link_libraries(obs-websocket
|
|||||||
if(WIN32)
|
if(WIN32)
|
||||||
if(NOT DEFINED OBS_FRONTEND_LIB)
|
if(NOT DEFINED OBS_FRONTEND_LIB)
|
||||||
set(OBS_FRONTEND_LIB "OBS_FRONTEND_LIB-NOTFOUND" CACHE FILEPATH "OBS frontend library")
|
set(OBS_FRONTEND_LIB "OBS_FRONTEND_LIB-NOTFOUND" CACHE FILEPATH "OBS frontend library")
|
||||||
message(FATAL_ERROR "Could not find OBS Frontend API\'s library !")
|
message(FATAL_ERROR "Could not find OBS Frontend API's library !")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||||
@ -80,36 +85,45 @@ if(WIN32)
|
|||||||
target_link_libraries(obs-websocket
|
target_link_libraries(obs-websocket
|
||||||
"${OBS_FRONTEND_LIB}")
|
"${OBS_FRONTEND_LIB}")
|
||||||
|
|
||||||
add_custom_command(TARGET obs-websocket POST_BUILD
|
|
||||||
COMMAND if $<CONFIG:Release>==1 ("${CMAKE_COMMAND}" -E copy
|
|
||||||
"${QTDIR}/bin/Qt5WebSockets.dll"
|
|
||||||
"${QTDIR}/bin/Qt5Network.dll"
|
|
||||||
"${CMAKE_BINARY_DIR}/$<CONFIG>")
|
|
||||||
|
|
||||||
COMMAND if $<CONFIG:Debug>==1 ("${CMAKE_COMMAND}" -E copy
|
|
||||||
"${QTDIR}/bin/Qt5WebSocketsd.dll"
|
|
||||||
"${QTDIR}/bin/Qt5Networkd.dll"
|
|
||||||
"${CMAKE_BINARY_DIR}/$<CONFIG>")
|
|
||||||
)
|
|
||||||
|
|
||||||
# --- Release package helper ---
|
# --- Release package helper ---
|
||||||
# The "release" folder has a structure similar OBS' one on Windows
|
# The "release" folder has a structure similar OBS' one on Windows
|
||||||
set(RELEASE_DIR "${PROJECT_SOURCE_DIR}/release")
|
set(RELEASE_DIR "${PROJECT_SOURCE_DIR}/release")
|
||||||
|
|
||||||
add_custom_command(TARGET obs-websocket POST_BUILD
|
add_custom_command(TARGET obs-websocket POST_BUILD
|
||||||
|
# If config is Release, package release files
|
||||||
COMMAND if $<CONFIG:Release>==1 (
|
COMMAND if $<CONFIG:Release>==1 (
|
||||||
"${CMAKE_COMMAND}" -E make_directory
|
"${CMAKE_COMMAND}" -E make_directory
|
||||||
"${RELEASE_DIR}/data/obs-plugins/obs-websocket"
|
"${RELEASE_DIR}/data/obs-plugins/obs-websocket"
|
||||||
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}")
|
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}")
|
||||||
|
|
||||||
COMMAND if $<CONFIG:Release>==1 ("${CMAKE_COMMAND}" -E copy_directory
|
COMMAND if $<CONFIG:Release>==1 ("${CMAKE_COMMAND}" -E copy_directory
|
||||||
"${PROJECT_SOURCE_DIR}/data"
|
"${PROJECT_SOURCE_DIR}/data"
|
||||||
"${RELEASE_DIR}/data/obs-plugins/obs-websocket")
|
"${RELEASE_DIR}/data/obs-plugins/obs-websocket")
|
||||||
|
|
||||||
COMMAND if $<CONFIG:Release>==1 ("${CMAKE_COMMAND}" -E copy
|
COMMAND if $<CONFIG:Release>==1 ("${CMAKE_COMMAND}" -E copy
|
||||||
"$<TARGET_FILE:obs-websocket>"
|
"$<TARGET_FILE:obs-websocket>"
|
||||||
"${QTDIR}/bin/Qt5WebSockets.dll"
|
"${QTDIR}/bin/Qt5WebSockets.dll"
|
||||||
"${QTDIR}/bin/Qt5Network.dll"
|
"${QTDIR}/bin/Qt5Network.dll"
|
||||||
|
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}")
|
||||||
|
|
||||||
|
# If config is RelWithDebInfo, package release files
|
||||||
|
COMMAND if $<CONFIG:RelWithDebInfo>==1 (
|
||||||
|
"${CMAKE_COMMAND}" -E make_directory
|
||||||
|
"${RELEASE_DIR}/data/obs-plugins/obs-websocket"
|
||||||
|
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}")
|
||||||
|
|
||||||
|
COMMAND if $<CONFIG:RelWithDebInfo>==1 ("${CMAKE_COMMAND}" -E copy_directory
|
||||||
|
"${PROJECT_SOURCE_DIR}/data"
|
||||||
|
"${RELEASE_DIR}/data/obs-plugins/obs-websocket")
|
||||||
|
|
||||||
|
COMMAND if $<CONFIG:RelWithDebInfo>==1 ("${CMAKE_COMMAND}" -E copy
|
||||||
|
"$<TARGET_FILE:obs-websocket>"
|
||||||
|
"${QTDIR}/bin/Qt5WebSockets.dll"
|
||||||
|
"${QTDIR}/bin/Qt5Network.dll"
|
||||||
|
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}")
|
||||||
|
|
||||||
|
COMMAND if $<CONFIG:RelWithDebInfo>==1 ("${CMAKE_COMMAND}" -E copy
|
||||||
|
"$<TARGET_PDB_FILE:obs-websocket>"
|
||||||
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}")
|
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}")
|
||||||
|
|
||||||
# Copy to obs-studio dev environment for immediate testing
|
# Copy to obs-studio dev environment for immediate testing
|
||||||
@ -120,6 +134,11 @@ if(WIN32)
|
|||||||
"${QTDIR}/bin/Qt5Networkd.dll"
|
"${QTDIR}/bin/Qt5Networkd.dll"
|
||||||
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/obs-plugins/${ARCH_NAME}")
|
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/obs-plugins/${ARCH_NAME}")
|
||||||
|
|
||||||
|
COMMAND if $<CONFIG:Debug>==1 (
|
||||||
|
"${CMAKE_COMMAND}" -E copy
|
||||||
|
"$<TARGET_PDB_FILE:obs-websocket>"
|
||||||
|
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/obs-plugins/${ARCH_NAME}")
|
||||||
|
|
||||||
COMMAND if $<CONFIG:Debug>==1 (
|
COMMAND if $<CONFIG:Debug>==1 (
|
||||||
"${CMAKE_COMMAND}" -E make_directory
|
"${CMAKE_COMMAND}" -E make_directory
|
||||||
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/data/obs-plugins/obs-websocket")
|
"${LIBOBS_INCLUDE_DIR}/../${OBS_BUILDDIR_ARCH}/rundir/$<CONFIG>/data/obs-plugins/obs-websocket")
|
||||||
@ -138,15 +157,19 @@ endif()
|
|||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
|
||||||
target_compile_options(mbedcrypto PRIVATE -fPIC)
|
|
||||||
set_target_properties(obs-websocket PROPERTIES PREFIX "")
|
set_target_properties(obs-websocket PROPERTIES PREFIX "")
|
||||||
target_link_libraries(obs-websocket
|
target_link_libraries(obs-websocket
|
||||||
obs-frontend-api)
|
obs-frontend-api)
|
||||||
|
|
||||||
file(GLOB locale_files data/locale/*.ini)
|
file(GLOB locale_files data/locale/*.ini)
|
||||||
|
execute_process(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE UNAME_MACHINE)
|
||||||
|
|
||||||
install(TARGETS obs-websocket
|
install(TARGETS obs-websocket
|
||||||
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/obs-plugins")
|
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/obs-plugins")
|
||||||
|
# Dirty fix for Ubuntu
|
||||||
|
install(TARGETS obs-websocket
|
||||||
|
LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/${UNAME_MACHINE}-linux-gnu/obs-plugins")
|
||||||
|
|
||||||
install(FILES ${locale_files}
|
install(FILES ${locale_files}
|
||||||
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/obs/obs-plugins/obs-websocket/locale")
|
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/obs/obs-plugins/obs-websocket/locale")
|
||||||
endif()
|
endif()
|
||||||
@ -156,6 +179,7 @@ endif()
|
|||||||
if(APPLE)
|
if(APPLE)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -fvisibility=default")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -fvisibility=default")
|
||||||
|
|
||||||
|
set(CMAKE_SKIP_RPATH TRUE)
|
||||||
set_target_properties(obs-websocket PROPERTIES PREFIX "")
|
set_target_properties(obs-websocket PROPERTIES PREFIX "")
|
||||||
target_link_libraries(obs-websocket "${OBS_FRONTEND_LIB}")
|
target_link_libraries(obs-websocket "${OBS_FRONTEND_LIB}")
|
||||||
endif()
|
endif()
|
||||||
|
184
Config.cpp
184
Config.cpp
@ -1,184 +0,0 @@
|
|||||||
/*
|
|
||||||
obs-websocket
|
|
||||||
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <mbedtls/base64.h>
|
|
||||||
#include <mbedtls/sha256.h>
|
|
||||||
#include <obs-frontend-api.h>
|
|
||||||
#include <util/config-file.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#define SECTION_NAME "WebsocketAPI"
|
|
||||||
#define PARAM_ENABLE "ServerEnabled"
|
|
||||||
#define PARAM_PORT "ServerPort"
|
|
||||||
#define PARAM_DEBUG "DebugEnabled"
|
|
||||||
#define PARAM_AUTHREQUIRED "AuthRequired"
|
|
||||||
#define PARAM_SECRET "AuthSecret"
|
|
||||||
#define PARAM_SALT "AuthSalt"
|
|
||||||
|
|
||||||
#include "Config.h"
|
|
||||||
|
|
||||||
Config* Config::_instance = new Config();
|
|
||||||
|
|
||||||
Config::Config() :
|
|
||||||
ServerEnabled(true),
|
|
||||||
ServerPort(4444),
|
|
||||||
DebugEnabled(false),
|
|
||||||
AuthRequired(false),
|
|
||||||
Secret(""),
|
|
||||||
Salt(""),
|
|
||||||
SettingsLoaded(false) {
|
|
||||||
// OBS Config defaults
|
|
||||||
config_t* obs_config = obs_frontend_get_global_config();
|
|
||||||
if (obs_config) {
|
|
||||||
config_set_default_bool(obs_config,
|
|
||||||
SECTION_NAME, PARAM_ENABLE, ServerEnabled);
|
|
||||||
config_set_default_uint(obs_config,
|
|
||||||
SECTION_NAME, PARAM_PORT, ServerPort);
|
|
||||||
|
|
||||||
config_set_default_bool(obs_config,
|
|
||||||
SECTION_NAME, PARAM_DEBUG, DebugEnabled);
|
|
||||||
|
|
||||||
config_set_default_bool(obs_config,
|
|
||||||
SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired);
|
|
||||||
config_set_default_string(obs_config,
|
|
||||||
SECTION_NAME, PARAM_SECRET, Secret);
|
|
||||||
config_set_default_string(obs_config,
|
|
||||||
SECTION_NAME, PARAM_SALT, Salt);
|
|
||||||
}
|
|
||||||
|
|
||||||
mbedtls_entropy_init(&entropy);
|
|
||||||
mbedtls_ctr_drbg_init(&rng);
|
|
||||||
mbedtls_ctr_drbg_seed(&rng, mbedtls_entropy_func, &entropy, nullptr, 0);
|
|
||||||
|
|
||||||
SessionChallenge = GenerateSalt();
|
|
||||||
}
|
|
||||||
|
|
||||||
Config::~Config() {
|
|
||||||
mbedtls_ctr_drbg_free(&rng);
|
|
||||||
mbedtls_entropy_free(&entropy);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Config::Load() {
|
|
||||||
config_t* obs_config = obs_frontend_get_global_config();
|
|
||||||
|
|
||||||
ServerEnabled = config_get_bool(obs_config, SECTION_NAME, PARAM_ENABLE);
|
|
||||||
ServerPort = config_get_uint(obs_config, SECTION_NAME, PARAM_PORT);
|
|
||||||
|
|
||||||
DebugEnabled = config_get_bool(obs_config, SECTION_NAME, PARAM_DEBUG);
|
|
||||||
|
|
||||||
AuthRequired = config_get_bool(obs_config, SECTION_NAME, PARAM_AUTHREQUIRED);
|
|
||||||
Secret = config_get_string(obs_config, SECTION_NAME, PARAM_SECRET);
|
|
||||||
Salt = config_get_string(obs_config, SECTION_NAME, PARAM_SALT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Config::Save() {
|
|
||||||
config_t* obs_config = obs_frontend_get_global_config();
|
|
||||||
|
|
||||||
config_set_bool(obs_config, SECTION_NAME, PARAM_ENABLE, ServerEnabled);
|
|
||||||
config_set_uint(obs_config, SECTION_NAME, PARAM_PORT, ServerPort);
|
|
||||||
|
|
||||||
config_set_bool(obs_config, SECTION_NAME, PARAM_DEBUG, DebugEnabled);
|
|
||||||
|
|
||||||
config_set_bool(obs_config, SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired);
|
|
||||||
config_set_string(obs_config, SECTION_NAME, PARAM_SECRET, Secret);
|
|
||||||
config_set_string(obs_config, SECTION_NAME, PARAM_SALT, Salt);
|
|
||||||
|
|
||||||
config_save(obs_config);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* Config::GenerateSalt() {
|
|
||||||
// Generate 32 random chars
|
|
||||||
unsigned char* random_chars = (unsigned char*)bzalloc(32);
|
|
||||||
mbedtls_ctr_drbg_random(&rng, random_chars, 32);
|
|
||||||
|
|
||||||
// Convert the 32 random chars to a base64 string
|
|
||||||
char* salt = (char*)bzalloc(64);
|
|
||||||
size_t salt_bytes;
|
|
||||||
mbedtls_base64_encode(
|
|
||||||
(unsigned char*)salt, 64, &salt_bytes,
|
|
||||||
random_chars, 32);
|
|
||||||
|
|
||||||
bfree(random_chars);
|
|
||||||
return salt;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* Config::GenerateSecret(const char* password, const char* salt) {
|
|
||||||
// Concatenate the password and the salt
|
|
||||||
std::string passAndSalt = "";
|
|
||||||
passAndSalt += password;
|
|
||||||
passAndSalt += salt;
|
|
||||||
|
|
||||||
// Generate a SHA256 hash of the password
|
|
||||||
unsigned char* challengeHash = (unsigned char*)bzalloc(32);
|
|
||||||
mbedtls_sha256(
|
|
||||||
(unsigned char*)passAndSalt.c_str(), passAndSalt.length(),
|
|
||||||
challengeHash, 0);
|
|
||||||
|
|
||||||
// Encode SHA256 hash to Base64
|
|
||||||
char* challenge = (char*)bzalloc(64);
|
|
||||||
size_t challenge_bytes = 0;
|
|
||||||
mbedtls_base64_encode(
|
|
||||||
(unsigned char*)challenge, 64, &challenge_bytes,
|
|
||||||
challengeHash, 32);
|
|
||||||
|
|
||||||
bfree(challengeHash);
|
|
||||||
return challenge;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Config::SetPassword(const char* password) {
|
|
||||||
const char* new_salt = GenerateSalt();
|
|
||||||
const char* new_challenge = GenerateSecret(password, new_salt);
|
|
||||||
|
|
||||||
this->Salt = new_salt;
|
|
||||||
this->Secret = new_challenge;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Config::CheckAuth(const char* response) {
|
|
||||||
// Concatenate auth secret with the challenge sent to the user
|
|
||||||
std::string challengeAndResponse = "";
|
|
||||||
challengeAndResponse += this->Secret;
|
|
||||||
challengeAndResponse += this->SessionChallenge;
|
|
||||||
|
|
||||||
// Generate a SHA256 hash of challengeAndResponse
|
|
||||||
unsigned char* hash = (unsigned char*)bzalloc(32);
|
|
||||||
mbedtls_sha256(
|
|
||||||
(unsigned char*)challengeAndResponse.c_str(),
|
|
||||||
challengeAndResponse.length(),
|
|
||||||
hash, 0);
|
|
||||||
|
|
||||||
// Encode the SHA256 hash to Base64
|
|
||||||
char* expected_response = (char*)bzalloc(64);
|
|
||||||
size_t base64_size = 0;
|
|
||||||
mbedtls_base64_encode(
|
|
||||||
(unsigned char*)expected_response, 64, &base64_size,
|
|
||||||
hash, 32);
|
|
||||||
|
|
||||||
bool authSuccess = false;
|
|
||||||
if (strcmp(expected_response, response) == 0) {
|
|
||||||
SessionChallenge = GenerateSalt();
|
|
||||||
authSuccess = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bfree(hash);
|
|
||||||
bfree(expected_response);
|
|
||||||
return authSuccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
Config* Config::Current() {
|
|
||||||
return _instance;
|
|
||||||
}
|
|
57
Config.h
57
Config.h
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
obs-websocket
|
|
||||||
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CONFIG_H
|
|
||||||
#define CONFIG_H
|
|
||||||
|
|
||||||
#include <mbedtls/entropy.h>
|
|
||||||
#include <mbedtls/ctr_drbg.h>
|
|
||||||
|
|
||||||
class Config {
|
|
||||||
public:
|
|
||||||
Config();
|
|
||||||
~Config();
|
|
||||||
void Load();
|
|
||||||
void Save();
|
|
||||||
|
|
||||||
void SetPassword(const char* password);
|
|
||||||
bool CheckAuth(const char* userChallenge);
|
|
||||||
const char* GenerateSalt();
|
|
||||||
static const char* GenerateSecret(
|
|
||||||
const char* password, const char* salt);
|
|
||||||
|
|
||||||
bool ServerEnabled;
|
|
||||||
uint64_t ServerPort;
|
|
||||||
|
|
||||||
bool DebugEnabled;
|
|
||||||
|
|
||||||
bool AuthRequired;
|
|
||||||
const char* Secret;
|
|
||||||
const char* Salt;
|
|
||||||
const char* SessionChallenge;
|
|
||||||
bool SettingsLoaded;
|
|
||||||
|
|
||||||
static Config* Current();
|
|
||||||
|
|
||||||
private:
|
|
||||||
static Config* _instance;
|
|
||||||
mbedtls_entropy_context entropy;
|
|
||||||
mbedtls_ctr_drbg_context rng;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CONFIG_H
|
|
15
README.md
15
README.md
@ -41,16 +41,21 @@ See the [build instructions](BUILDING.md).
|
|||||||
In order of appearance:
|
In order of appearance:
|
||||||
- [Brendan H.](https://github.com/haganbmj) : Code contributions and gooder English in the Protocol specification
|
- [Brendan H.](https://github.com/haganbmj) : Code contributions and gooder English in the Protocol specification
|
||||||
- [Mikhail Swift](https://github.com/mikhailswift) : Code contributions
|
- [Mikhail Swift](https://github.com/mikhailswift) : Code contributions
|
||||||
- [Tobias Frahmer](https://github.com/Frahmer) : German translation
|
- [Tobias Frahmer](https://github.com/Frahmer) : German localization
|
||||||
- [Genture](https://github.com/Genteure) : Simplified Chinese and Traditional Chinese translations
|
- [Genture](https://github.com/Genteure) : Simplified Chinese and Traditional Chinese localizations
|
||||||
- [Larissa Gabilan](https://github.com/laris151) : Portuguese translation
|
- [Larissa Gabilan](https://github.com/laris151) : Portuguese localization
|
||||||
- [Andy Asquelt](https://github.com/asquelt) : Polish translation
|
- [Andy Asquelt](https://github.com/asquelt) : Polish localization
|
||||||
- [Marcel Haazen](https://github.com/inpothet) : Dutch translation
|
- [Marcel Haazen](https://github.com/inpothet) : Dutch localization
|
||||||
- [Peter Antonvich](https://github.com/pantonvich) : Code contributions
|
- [Peter Antonvich](https://github.com/pantonvich) : Code contributions
|
||||||
- [yinzara](https://github.com/yinzara) : Code contributions
|
- [yinzara](https://github.com/yinzara) : Code contributions
|
||||||
- [Chris Angelico](https://github.com/Rosuav) : Code contributions
|
- [Chris Angelico](https://github.com/Rosuav) : Code contributions
|
||||||
- [Guillaume "Elektordi" Genty](https://github.com/Elektordi) : Code contributions
|
- [Guillaume "Elektordi" Genty](https://github.com/Elektordi) : Code contributions
|
||||||
- [Marwin M](https://github.com/dragonbane0) : Code contributions
|
- [Marwin M](https://github.com/dragonbane0) : Code contributions
|
||||||
|
- [Logan S.](https://github.com/lsdaniel) : Code contributions
|
||||||
|
- [RainbowEK](https://github.com/RainbowEK) : Code contributions
|
||||||
|
- [RytoEX](https://github.com/RytoEX) : CI script and code contributions
|
||||||
|
- [Theodore Stoddard](https://github.com/TStod) : Code contributions
|
||||||
|
- [Philip Loche](https://github.com/PicoCentauri) : Code contributions
|
||||||
|
|
||||||
And also: special thanks to supporters of the project!
|
And also: special thanks to supporters of the project!
|
||||||
|
|
||||||
|
531
Utils.cpp
531
Utils.cpp
@ -1,531 +0,0 @@
|
|||||||
/*
|
|
||||||
obs-websocket
|
|
||||||
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <QMainWindow>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QUrl>
|
|
||||||
#include <obs-frontend-api.h>
|
|
||||||
#include <obs.hpp>
|
|
||||||
#include "obs-websocket.h"
|
|
||||||
|
|
||||||
#include "Utils.h"
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(OBSScene);
|
|
||||||
|
|
||||||
obs_data_array_t* string_list_to_array(char** strings, char* key) {
|
|
||||||
if (!strings)
|
|
||||||
return obs_data_array_create();
|
|
||||||
|
|
||||||
obs_data_array_t* list = obs_data_array_create();
|
|
||||||
|
|
||||||
char* value = "";
|
|
||||||
for (int i = 0; value != nullptr; i++) {
|
|
||||||
value = strings[i];
|
|
||||||
|
|
||||||
obs_data_t* item = obs_data_create();
|
|
||||||
obs_data_set_string(item, key, value);
|
|
||||||
|
|
||||||
if (value)
|
|
||||||
obs_data_array_push_back(list, item);
|
|
||||||
|
|
||||||
obs_data_release(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_data_array_t* Utils::GetSceneItems(obs_source_t* source) {
|
|
||||||
obs_data_array_t* items = obs_data_array_create();
|
|
||||||
obs_scene_t* scene = obs_scene_from_source(source);
|
|
||||||
|
|
||||||
if (!scene)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
obs_scene_enum_items(scene, [](
|
|
||||||
obs_scene_t* scene,
|
|
||||||
obs_sceneitem_t* currentItem,
|
|
||||||
void* param)
|
|
||||||
{
|
|
||||||
obs_data_array_t* data = static_cast<obs_data_array_t*>(param);
|
|
||||||
|
|
||||||
obs_data_t* item_data = GetSceneItemData(currentItem);
|
|
||||||
obs_data_array_insert(data, 0, item_data);
|
|
||||||
|
|
||||||
obs_data_release(item_data);
|
|
||||||
return true;
|
|
||||||
}, items);
|
|
||||||
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_data_t* Utils::GetSceneItemData(obs_sceneitem_t* item) {
|
|
||||||
if (!item)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
vec2 pos;
|
|
||||||
obs_sceneitem_get_pos(item, &pos);
|
|
||||||
|
|
||||||
vec2 scale;
|
|
||||||
obs_sceneitem_get_scale(item, &scale);
|
|
||||||
|
|
||||||
obs_source_t* item_source = obs_sceneitem_get_source(item);
|
|
||||||
float item_width = float(obs_source_get_width(item_source));
|
|
||||||
float item_height = float(obs_source_get_height(item_source));
|
|
||||||
|
|
||||||
obs_data_t* data = obs_data_create();
|
|
||||||
obs_data_set_string(data, "name",
|
|
||||||
obs_source_get_name(obs_sceneitem_get_source(item)));
|
|
||||||
obs_data_set_string(data, "type",
|
|
||||||
obs_source_get_id(obs_sceneitem_get_source(item)));
|
|
||||||
obs_data_set_double(data, "volume",
|
|
||||||
obs_source_get_volume(obs_sceneitem_get_source(item)));
|
|
||||||
obs_data_set_double(data, "x", pos.x);
|
|
||||||
obs_data_set_double(data, "y", pos.y);
|
|
||||||
obs_data_set_int(data, "source_cx", (int)item_width);
|
|
||||||
obs_data_set_int(data, "source_cy", (int)item_height);
|
|
||||||
obs_data_set_double(data, "cx", item_width* scale.x);
|
|
||||||
obs_data_set_double(data, "cy", item_height* scale.y);
|
|
||||||
obs_data_set_bool(data, "render", obs_sceneitem_visible(item));
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_sceneitem_t* Utils::GetSceneItemFromName(obs_source_t* source, const char* name) {
|
|
||||||
struct current_search {
|
|
||||||
const char* query;
|
|
||||||
obs_sceneitem_t* result;
|
|
||||||
};
|
|
||||||
|
|
||||||
current_search search;
|
|
||||||
search.query = name;
|
|
||||||
search.result = nullptr;
|
|
||||||
|
|
||||||
obs_scene_t* scene = obs_scene_from_source(source);
|
|
||||||
if (scene == nullptr)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
obs_scene_enum_items(scene, [](
|
|
||||||
obs_scene_t* scene,
|
|
||||||
obs_sceneitem_t* currentItem,
|
|
||||||
void* param)
|
|
||||||
{
|
|
||||||
current_search* search = static_cast<current_search*>(param);
|
|
||||||
|
|
||||||
const char* currentItemName =
|
|
||||||
obs_source_get_name(obs_sceneitem_get_source(currentItem));
|
|
||||||
|
|
||||||
if (strcmp(currentItemName, search->query) == 0) {
|
|
||||||
search->result = currentItem;
|
|
||||||
obs_sceneitem_addref(search->result);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}, &search);
|
|
||||||
|
|
||||||
return search.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_source_t* Utils::GetTransitionFromName(const char* search_name) {
|
|
||||||
obs_source_t* found_transition = NULL;
|
|
||||||
|
|
||||||
obs_frontend_source_list transition_list = {};
|
|
||||||
obs_frontend_get_transitions(&transition_list);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < transition_list.sources.num; i++) {
|
|
||||||
obs_source_t* transition = transition_list.sources.array[i];
|
|
||||||
|
|
||||||
const char* transition_name = obs_source_get_name(transition);
|
|
||||||
if (strcmp(transition_name, search_name) == 0)
|
|
||||||
{
|
|
||||||
found_transition = transition;
|
|
||||||
obs_source_addref(found_transition);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_frontend_source_list_free(&transition_list);
|
|
||||||
|
|
||||||
return found_transition;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_source_t* Utils::GetSceneFromNameOrCurrent(const char* scene_name) {
|
|
||||||
obs_source_t* scene = nullptr;
|
|
||||||
|
|
||||||
if (!scene_name || !strlen(scene_name))
|
|
||||||
scene = obs_frontend_get_current_scene();
|
|
||||||
else
|
|
||||||
scene = obs_get_source_by_name(scene_name);
|
|
||||||
|
|
||||||
return scene;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_data_array_t* Utils::GetScenes() {
|
|
||||||
obs_frontend_source_list sceneList = {};
|
|
||||||
obs_frontend_get_scenes(&sceneList);
|
|
||||||
|
|
||||||
obs_data_array_t* scenes = obs_data_array_create();
|
|
||||||
for (size_t i = 0; i < sceneList.sources.num; i++) {
|
|
||||||
obs_source_t* scene = sceneList.sources.array[i];
|
|
||||||
|
|
||||||
obs_data_t* scene_data = GetSceneData(scene);
|
|
||||||
obs_data_array_push_back(scenes, scene_data);
|
|
||||||
|
|
||||||
obs_data_release(scene_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_frontend_source_list_free(&sceneList);
|
|
||||||
|
|
||||||
return scenes;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_data_t* Utils::GetSceneData(obs_source* source) {
|
|
||||||
obs_data_array_t* scene_items = GetSceneItems(source);
|
|
||||||
|
|
||||||
obs_data_t* sceneData = obs_data_create();
|
|
||||||
obs_data_set_string(sceneData, "name", obs_source_get_name(source));
|
|
||||||
obs_data_set_array(sceneData, "sources", scene_items);
|
|
||||||
|
|
||||||
obs_data_array_release(scene_items);
|
|
||||||
return sceneData;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_data_array_t* Utils::GetSceneCollections() {
|
|
||||||
char** scene_collections = obs_frontend_get_scene_collections();
|
|
||||||
obs_data_array_t* list = string_list_to_array(scene_collections, "sc-name");
|
|
||||||
|
|
||||||
bfree(scene_collections);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_data_array_t* Utils::GetProfiles() {
|
|
||||||
char** profiles = obs_frontend_get_profiles();
|
|
||||||
obs_data_array_t* list = string_list_to_array(profiles, "profile-name");
|
|
||||||
|
|
||||||
bfree(profiles);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSpinBox* Utils::GetTransitionDurationControl() {
|
|
||||||
QMainWindow* window = (QMainWindow*)obs_frontend_get_main_window();
|
|
||||||
return window->findChild<QSpinBox*>("transitionDuration");
|
|
||||||
}
|
|
||||||
|
|
||||||
int Utils::GetTransitionDuration() {
|
|
||||||
QSpinBox* control = GetTransitionDurationControl();
|
|
||||||
if (control)
|
|
||||||
return control->value();
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Utils::SetTransitionDuration(int ms) {
|
|
||||||
QSpinBox* control = GetTransitionDurationControl();
|
|
||||||
if (control && ms >= 0)
|
|
||||||
control->setValue(ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::SetTransitionByName(const char* transition_name) {
|
|
||||||
obs_source_t* transition = GetTransitionFromName(transition_name);
|
|
||||||
|
|
||||||
if (transition) {
|
|
||||||
obs_frontend_set_current_transition(transition);
|
|
||||||
obs_source_release(transition);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QPushButton* Utils::GetPreviewModeButtonControl() {
|
|
||||||
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
|
||||||
return main->findChild<QPushButton*>("modeSwitch");
|
|
||||||
}
|
|
||||||
|
|
||||||
QListWidget* Utils::GetSceneListControl() {
|
|
||||||
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
|
||||||
return main->findChild<QListWidget*>("scenes");
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_scene_t* Utils::SceneListItemToScene(QListWidgetItem* item) {
|
|
||||||
if (!item)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
QVariant item_data = item->data(static_cast<int>(Qt::UserRole));
|
|
||||||
return item_data.value<OBSScene>();
|
|
||||||
}
|
|
||||||
|
|
||||||
QLayout* Utils::GetPreviewLayout() {
|
|
||||||
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
|
||||||
return main->findChild<QLayout*>("previewLayout");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::IsPreviewModeActive() {
|
|
||||||
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
|
||||||
|
|
||||||
// Clue 1 : "Studio Mode" button is toggled on
|
|
||||||
bool buttonToggledOn = GetPreviewModeButtonControl()->isChecked();
|
|
||||||
|
|
||||||
// Clue 2 : Preview layout has more than one item
|
|
||||||
int previewChildCount = GetPreviewLayout()->count();
|
|
||||||
blog(LOG_INFO, "preview layout children count : %d", previewChildCount);
|
|
||||||
|
|
||||||
return buttonToggledOn || (previewChildCount >= 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Utils::EnablePreviewMode() {
|
|
||||||
if (!IsPreviewModeActive())
|
|
||||||
GetPreviewModeButtonControl()->click();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Utils::DisablePreviewMode() {
|
|
||||||
if (IsPreviewModeActive())
|
|
||||||
GetPreviewModeButtonControl()->click();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Utils::TogglePreviewMode() {
|
|
||||||
GetPreviewModeButtonControl()->click();
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_scene_t* Utils::GetPreviewScene() {
|
|
||||||
if (IsPreviewModeActive()) {
|
|
||||||
QListWidget* sceneList = GetSceneListControl();
|
|
||||||
QList<QListWidgetItem*> selected = sceneList->selectedItems();
|
|
||||||
|
|
||||||
// Qt::UserRole == QtUserRole::OBSRef
|
|
||||||
obs_scene_t* scene = Utils::SceneListItemToScene(selected.first());
|
|
||||||
|
|
||||||
obs_scene_addref(scene);
|
|
||||||
return scene;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::SetPreviewScene(const char* name) {
|
|
||||||
if (IsPreviewModeActive()) {
|
|
||||||
QListWidget* sceneList = GetSceneListControl();
|
|
||||||
QList<QListWidgetItem*> matchingItems =
|
|
||||||
sceneList->findItems(name, Qt::MatchExactly);
|
|
||||||
|
|
||||||
if (matchingItems.count() > 0) {
|
|
||||||
sceneList->setCurrentItem(matchingItems.first());
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Utils::TransitionToProgram() {
|
|
||||||
if (!IsPreviewModeActive())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// WARNING : if the layout created in OBS' CreateProgramOptions() changes
|
|
||||||
// then this won't work as expected
|
|
||||||
|
|
||||||
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
|
||||||
|
|
||||||
// The program options widget is the second item in the left-to-right layout
|
|
||||||
QWidget* programOptions = GetPreviewLayout()->itemAt(1)->widget();
|
|
||||||
|
|
||||||
// The "Transition" button lies in the mainButtonLayout
|
|
||||||
// which is the first itemin the program options' layout
|
|
||||||
QLayout* mainButtonLayout = programOptions->layout()->itemAt(1)->layout();
|
|
||||||
QWidget* transitionBtnWidget = mainButtonLayout->itemAt(0)->widget();
|
|
||||||
|
|
||||||
// Try to cast that widget into a button
|
|
||||||
QPushButton* transitionBtn = qobject_cast<QPushButton*>(transitionBtnWidget);
|
|
||||||
|
|
||||||
// Perform a click on that button
|
|
||||||
transitionBtn->click();
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* Utils::OBSVersionString() {
|
|
||||||
uint32_t version = obs_get_version();
|
|
||||||
|
|
||||||
uint8_t major, minor, patch;
|
|
||||||
major = (version >> 24) & 0xFF;
|
|
||||||
minor = (version >> 16) & 0xFF;
|
|
||||||
patch = version & 0xFF;
|
|
||||||
|
|
||||||
char* result = (char*)bmalloc(sizeof(char) * 12);
|
|
||||||
sprintf(result, "%d.%d.%d", major, minor, patch);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
QSystemTrayIcon* Utils::GetTrayIcon() {
|
|
||||||
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
|
||||||
return main->findChildren<QSystemTrayIcon*>().first();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Utils::SysTrayNotify(QString &text,
|
|
||||||
QSystemTrayIcon::MessageIcon icon, QString title) {
|
|
||||||
if (!QSystemTrayIcon::supportsMessages())
|
|
||||||
return;
|
|
||||||
|
|
||||||
QSystemTrayIcon* trayIcon = GetTrayIcon();
|
|
||||||
if (trayIcon)
|
|
||||||
trayIcon->showMessage(title, text, icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Utils::FormatIPAddress(QHostAddress &addr) {
|
|
||||||
QRegExp v4regex("(::ffff:)(((\\d).){3})", Qt::CaseInsensitive);
|
|
||||||
QString addrString = addr.toString();
|
|
||||||
if (addrString.contains(v4regex)) {
|
|
||||||
addrString = QHostAddress(addr.toIPv4Address()).toString();
|
|
||||||
}
|
|
||||||
return addrString;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* Utils::GetRecordingFolder() {
|
|
||||||
config_t* profile = obs_frontend_get_profile_config();
|
|
||||||
const char* outputMode = config_get_string(profile, "Output", "Mode");
|
|
||||||
|
|
||||||
if (strcmp(outputMode, "Advanced") == 0) {
|
|
||||||
// Advanced mode
|
|
||||||
return config_get_string(profile, "AdvOut", "RecFilePath");
|
|
||||||
} else {
|
|
||||||
// Simple mode
|
|
||||||
return config_get_string(profile, "SimpleOutput", "FilePath");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::SetRecordingFolder(const char* path) {
|
|
||||||
if (!QDir(path).exists())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
config_t* profile = obs_frontend_get_profile_config();
|
|
||||||
const char* outputMode = config_get_string(profile, "Output", "Mode");
|
|
||||||
|
|
||||||
if (strcmp(outputMode, "Advanced") == 0) {
|
|
||||||
config_set_string(profile, "AdvOut", "RecFilePath", path);
|
|
||||||
} else {
|
|
||||||
config_set_string(profile, "SimpleOutput", "FilePath", path);
|
|
||||||
}
|
|
||||||
|
|
||||||
config_save(profile);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString* Utils::ParseDataToQueryString(obs_data_t* data) {
|
|
||||||
QString* query = nullptr;
|
|
||||||
if (data) {
|
|
||||||
obs_data_item_t* item = obs_data_first(data);
|
|
||||||
if (item) {
|
|
||||||
query = new QString();
|
|
||||||
bool isFirst = true;
|
|
||||||
do {
|
|
||||||
if (!obs_data_item_has_user_value(item))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!isFirst)
|
|
||||||
query->append('&');
|
|
||||||
else
|
|
||||||
isFirst = false;
|
|
||||||
|
|
||||||
const char* attrName = obs_data_item_get_name(item);
|
|
||||||
query->append(attrName).append("=");
|
|
||||||
|
|
||||||
switch (obs_data_item_gettype(item)) {
|
|
||||||
case OBS_DATA_BOOLEAN:
|
|
||||||
query->append(obs_data_item_get_bool(item)?"true":"false");
|
|
||||||
break;
|
|
||||||
case OBS_DATA_NUMBER:
|
|
||||||
switch (obs_data_item_numtype(item))
|
|
||||||
{
|
|
||||||
case OBS_DATA_NUM_DOUBLE:
|
|
||||||
query->append(
|
|
||||||
QString::number(obs_data_item_get_double(item)));
|
|
||||||
break;
|
|
||||||
case OBS_DATA_NUM_INT:
|
|
||||||
query->append(
|
|
||||||
QString::number(obs_data_item_get_int(item)));
|
|
||||||
break;
|
|
||||||
case OBS_DATA_NUM_INVALID:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case OBS_DATA_STRING:
|
|
||||||
query->append(QUrl::toPercentEncoding(
|
|
||||||
QString(obs_data_item_get_string(item))));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//other types are not supported
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (obs_data_item_next(&item));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs_hotkey_t* Utils::FindHotkeyByName(const char* name) {
|
|
||||||
struct current_search {
|
|
||||||
const char* query;
|
|
||||||
obs_hotkey_t* result;
|
|
||||||
};
|
|
||||||
|
|
||||||
current_search search;
|
|
||||||
search.query = name;
|
|
||||||
search.result = nullptr;
|
|
||||||
|
|
||||||
obs_enum_hotkeys([](void* data, obs_hotkey_id id, obs_hotkey_t* hotkey) {
|
|
||||||
current_search* search = static_cast<current_search*>(data);
|
|
||||||
|
|
||||||
const char* hk_name = obs_hotkey_get_name(hotkey);
|
|
||||||
if (strcmp(hk_name, search->query) == 0) {
|
|
||||||
search->result = hotkey;
|
|
||||||
blog(LOG_INFO, "Utils::FindHotkeyByName: found %s", hk_name);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}, &search);
|
|
||||||
|
|
||||||
return search.result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::ReplayBufferEnabled() {
|
|
||||||
config_t* profile = obs_frontend_get_profile_config();
|
|
||||||
const char* outputMode = config_get_string(profile, "Output", "Mode");
|
|
||||||
|
|
||||||
if (strcmp(outputMode, "Simple") == 0) {
|
|
||||||
return config_get_bool(profile, "SimpleOutput", "RecRB");
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::RPHotkeySet() {
|
|
||||||
obs_output_t* rp_output = obs_frontend_get_replay_buffer_output();
|
|
||||||
|
|
||||||
obs_data_t *hotkeys = obs_hotkeys_save_output(rp_output);
|
|
||||||
obs_data_array_t *bindings = obs_data_get_array(hotkeys,
|
|
||||||
"ReplayBuffer.Save");
|
|
||||||
|
|
||||||
size_t count = obs_data_array_count(bindings);
|
|
||||||
|
|
||||||
obs_data_array_release(bindings);
|
|
||||||
obs_data_release(hotkeys);
|
|
||||||
obs_output_release(rp_output);
|
|
||||||
|
|
||||||
return (count > 0);
|
|
||||||
}
|
|
86
Utils.h
86
Utils.h
@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
obs-websocket
|
|
||||||
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef UTILS_H
|
|
||||||
#define UTILS_H
|
|
||||||
|
|
||||||
#include <QSpinBox>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QLayout>
|
|
||||||
#include <QListWidget>
|
|
||||||
#include <QSystemTrayIcon>
|
|
||||||
#include <QHostAddress>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <obs-module.h>
|
|
||||||
#include <util/config-file.h>
|
|
||||||
|
|
||||||
class Utils {
|
|
||||||
public:
|
|
||||||
static obs_data_array_t* GetSceneItems(obs_source_t* source);
|
|
||||||
static obs_data_t* GetSceneItemData(obs_scene_item* item);
|
|
||||||
static obs_sceneitem_t* GetSceneItemFromName(
|
|
||||||
obs_source_t* source, const char* name);
|
|
||||||
static obs_source_t* GetTransitionFromName(const char* search_name);
|
|
||||||
static obs_source_t* GetSceneFromNameOrCurrent(const char* scene_name);
|
|
||||||
|
|
||||||
static obs_data_array_t* GetScenes();
|
|
||||||
static obs_data_t* GetSceneData(obs_source* source);
|
|
||||||
|
|
||||||
static obs_data_array_t* GetSceneCollections();
|
|
||||||
static obs_data_array_t* GetProfiles();
|
|
||||||
|
|
||||||
static QSpinBox* GetTransitionDurationControl();
|
|
||||||
static int GetTransitionDuration();
|
|
||||||
static void SetTransitionDuration(int ms);
|
|
||||||
|
|
||||||
static bool SetTransitionByName(const char* transition_name);
|
|
||||||
|
|
||||||
static QPushButton* GetPreviewModeButtonControl();
|
|
||||||
static QLayout* GetPreviewLayout();
|
|
||||||
static QListWidget* GetSceneListControl();
|
|
||||||
static obs_scene_t* SceneListItemToScene(QListWidgetItem* item);
|
|
||||||
|
|
||||||
static bool IsPreviewModeActive();
|
|
||||||
static void EnablePreviewMode();
|
|
||||||
static void DisablePreviewMode();
|
|
||||||
static void TogglePreviewMode();
|
|
||||||
|
|
||||||
static obs_scene_t* GetPreviewScene();
|
|
||||||
static bool SetPreviewScene(const char* name);
|
|
||||||
static void TransitionToProgram();
|
|
||||||
|
|
||||||
static const char* OBSVersionString();
|
|
||||||
|
|
||||||
static QSystemTrayIcon* GetTrayIcon();
|
|
||||||
static void SysTrayNotify(
|
|
||||||
QString &text,
|
|
||||||
QSystemTrayIcon::MessageIcon n,
|
|
||||||
QString title = QString("obs-websocket"));
|
|
||||||
|
|
||||||
static QString FormatIPAddress(QHostAddress &addr);
|
|
||||||
static const char* GetRecordingFolder();
|
|
||||||
static bool SetRecordingFolder(const char* path);
|
|
||||||
|
|
||||||
static QString* ParseDataToQueryString(obs_data_t * data);
|
|
||||||
static obs_hotkey_t* FindHotkeyByName(const char* name);
|
|
||||||
static bool ReplayBufferEnabled();
|
|
||||||
static bool RPHotkeySet();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // UTILS_H
|
|
887
WSEvents.cpp
887
WSEvents.cpp
@ -1,887 +0,0 @@
|
|||||||
/**
|
|
||||||
* obs-websocket
|
|
||||||
* Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
|
||||||
* Copyright (C) 2017 Brendan Hagan <https://github.com/haganbmj>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <util/platform.h>
|
|
||||||
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QPushButton>
|
|
||||||
|
|
||||||
#include "Config.h"
|
|
||||||
#include "Utils.h"
|
|
||||||
#include "WSEvents.h"
|
|
||||||
|
|
||||||
#include "obs-websocket.h"
|
|
||||||
|
|
||||||
bool transition_is_cut(obs_source_t* transition) {
|
|
||||||
if (!transition)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (obs_source_get_type(transition) == OBS_SOURCE_TYPE_TRANSITION
|
|
||||||
&& strcmp(obs_source_get_id(transition), "cut_transition") == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* ns_to_timestamp(uint64_t ns) {
|
|
||||||
uint64_t ms = ns / (1000 * 1000);
|
|
||||||
uint64_t secs = ms / 1000;
|
|
||||||
uint64_t minutes = secs / 60;
|
|
||||||
|
|
||||||
uint64_t hours_part = minutes / 60;
|
|
||||||
uint64_t minutes_part = minutes % 60;
|
|
||||||
uint64_t secs_part = secs % 60;
|
|
||||||
uint64_t ms_part = ms % 1000;
|
|
||||||
|
|
||||||
char* ts = (char*)bmalloc(64);
|
|
||||||
sprintf(ts, "%02d:%02d:%02d.%03d",
|
|
||||||
hours_part, minutes_part, secs_part, ms_part);
|
|
||||||
|
|
||||||
return ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
WSEvents* WSEvents::Instance = nullptr;
|
|
||||||
|
|
||||||
WSEvents::WSEvents(WSServer* srv) {
|
|
||||||
_srv = srv;
|
|
||||||
obs_frontend_add_event_callback(WSEvents::FrontendEventHandler, this);
|
|
||||||
|
|
||||||
QSpinBox* duration_control = Utils::GetTransitionDurationControl();
|
|
||||||
connect(duration_control, SIGNAL(valueChanged(int)),
|
|
||||||
this, SLOT(TransitionDurationChanged(int)));
|
|
||||||
|
|
||||||
QTimer* statusTimer = new QTimer();
|
|
||||||
connect(statusTimer, SIGNAL(timeout()),
|
|
||||||
this, SLOT(StreamStatus()));
|
|
||||||
statusTimer->start(2000); // equal to frontend's constant BITRATE_UPDATE_SECONDS
|
|
||||||
|
|
||||||
QListWidget* sceneList = Utils::GetSceneListControl();
|
|
||||||
connect(sceneList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
|
|
||||||
this, SLOT(SelectedSceneChanged(QListWidgetItem*, QListWidgetItem*)));
|
|
||||||
|
|
||||||
QPushButton* modeSwitch = Utils::GetPreviewModeButtonControl();
|
|
||||||
connect(modeSwitch, SIGNAL(clicked(bool)), this, SLOT(ModeSwitchClicked(bool)));
|
|
||||||
|
|
||||||
transition_handler = nullptr;
|
|
||||||
scene_handler = nullptr;
|
|
||||||
|
|
||||||
QTimer::singleShot(1000, this, SLOT(deferredInitOperations()));
|
|
||||||
|
|
||||||
_streaming_active = false;
|
|
||||||
_recording_active = false;
|
|
||||||
|
|
||||||
_stream_starttime = 0;
|
|
||||||
_rec_starttime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
WSEvents::~WSEvents() {
|
|
||||||
obs_frontend_remove_event_callback(WSEvents::FrontendEventHandler, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSEvents::deferredInitOperations() {
|
|
||||||
obs_source_t* transition = obs_frontend_get_current_transition();
|
|
||||||
connectTransitionSignals(transition);
|
|
||||||
obs_source_release(transition);
|
|
||||||
|
|
||||||
obs_source_t* scene = obs_frontend_get_current_scene();
|
|
||||||
connectSceneSignals(scene);
|
|
||||||
obs_source_release(scene);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private_data) {
|
|
||||||
WSEvents* owner = static_cast<WSEvents*>(private_data);
|
|
||||||
|
|
||||||
if (!owner->_srv)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// TODO : implement SourceOrderChanged and RepopulateSources
|
|
||||||
|
|
||||||
if (event == OBS_FRONTEND_EVENT_SCENE_CHANGED) {
|
|
||||||
owner->OnSceneChange();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED) {
|
|
||||||
owner->OnSceneListChange();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED) {
|
|
||||||
owner->OnSceneCollectionChange();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_LIST_CHANGED) {
|
|
||||||
owner->OnSceneCollectionListChange();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_TRANSITION_CHANGED) {
|
|
||||||
owner->OnTransitionChange();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_TRANSITION_LIST_CHANGED) {
|
|
||||||
owner->OnTransitionListChange();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_PROFILE_CHANGED) {
|
|
||||||
owner->OnProfileChange();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED) {
|
|
||||||
owner->OnProfileListChange();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_STREAMING_STARTING) {
|
|
||||||
owner->OnStreamStarting();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_STREAMING_STARTED) {
|
|
||||||
owner->_streaming_active = true;
|
|
||||||
owner->OnStreamStarted();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_STREAMING_STOPPING) {
|
|
||||||
owner->OnStreamStopping();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_STREAMING_STOPPED) {
|
|
||||||
owner->_streaming_active = false;
|
|
||||||
owner->OnStreamStopped();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_RECORDING_STARTING) {
|
|
||||||
owner->OnRecordingStarting();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_RECORDING_STARTED) {
|
|
||||||
owner->_recording_active = true;
|
|
||||||
owner->OnRecordingStarted();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_RECORDING_STOPPING) {
|
|
||||||
owner->OnRecordingStopping();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_RECORDING_STOPPED) {
|
|
||||||
owner->_recording_active = false;
|
|
||||||
owner->OnRecordingStopped();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING) {
|
|
||||||
owner->OnReplayStarting();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED) {
|
|
||||||
owner->OnReplayStarted();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING) {
|
|
||||||
owner->OnReplayStopping();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED) {
|
|
||||||
owner->OnReplayStopped();
|
|
||||||
}
|
|
||||||
else if (event == OBS_FRONTEND_EVENT_EXIT) {
|
|
||||||
owner->OnExit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSEvents::broadcastUpdate(const char* updateType,
|
|
||||||
obs_data_t* additionalFields = NULL) {
|
|
||||||
obs_data_t* update = obs_data_create();
|
|
||||||
obs_data_set_string(update, "update-type", updateType);
|
|
||||||
|
|
||||||
const char* ts = nullptr;
|
|
||||||
if (_streaming_active) {
|
|
||||||
ts = ns_to_timestamp(os_gettime_ns() - _stream_starttime);
|
|
||||||
obs_data_set_string(update, "stream-timecode", ts);
|
|
||||||
bfree((void*)ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_recording_active) {
|
|
||||||
ts = ns_to_timestamp(os_gettime_ns() - _rec_starttime);
|
|
||||||
obs_data_set_string(update, "rec-timecode", ts);
|
|
||||||
bfree((void*)ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (additionalFields != NULL)
|
|
||||||
obs_data_apply(update, additionalFields);
|
|
||||||
|
|
||||||
const char *json = obs_data_get_json(update);
|
|
||||||
_srv->broadcast(json);
|
|
||||||
if (Config::Current()->DebugEnabled)
|
|
||||||
blog(LOG_DEBUG, "Update << '%s'", json);
|
|
||||||
|
|
||||||
obs_data_release(update);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSEvents::connectTransitionSignals(obs_source_t* transition) {
|
|
||||||
if (transition_handler) {
|
|
||||||
signal_handler_disconnect(transition_handler,
|
|
||||||
"transition_start", OnTransitionBegin, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!transition_is_cut(transition)) {
|
|
||||||
transition_handler = obs_source_get_signal_handler(transition);
|
|
||||||
signal_handler_connect(transition_handler,
|
|
||||||
"transition_start", OnTransitionBegin, this);
|
|
||||||
} else {
|
|
||||||
transition_handler = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSEvents::connectSceneSignals(obs_source_t* scene) {
|
|
||||||
if (scene_handler) {
|
|
||||||
signal_handler_disconnect(scene_handler,
|
|
||||||
"reorder", OnSceneReordered, this);
|
|
||||||
signal_handler_disconnect(scene_handler,
|
|
||||||
"item_add", OnSceneItemAdd, this);
|
|
||||||
signal_handler_disconnect(scene_handler,
|
|
||||||
"item_remove", OnSceneItemDelete, this);
|
|
||||||
signal_handler_disconnect(scene_handler,
|
|
||||||
"item_visible", OnSceneItemVisibilityChanged, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO : connect to all scenes, not just the current one.
|
|
||||||
scene_handler = obs_source_get_signal_handler(scene);
|
|
||||||
signal_handler_connect(scene_handler,
|
|
||||||
"reorder", OnSceneReordered, this);
|
|
||||||
signal_handler_connect(scene_handler,
|
|
||||||
"item_add", OnSceneItemAdd, this);
|
|
||||||
signal_handler_connect(scene_handler,
|
|
||||||
"item_remove", OnSceneItemDelete, this);
|
|
||||||
signal_handler_connect(scene_handler,
|
|
||||||
"item_visible", OnSceneItemVisibilityChanged, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t WSEvents::GetStreamingTime() {
|
|
||||||
if (_streaming_active)
|
|
||||||
return (os_gettime_ns() - _stream_starttime);
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* WSEvents::GetStreamingTimecode() {
|
|
||||||
return ns_to_timestamp(GetStreamingTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t WSEvents::GetRecordingTime() {
|
|
||||||
if (_recording_active)
|
|
||||||
return (os_gettime_ns() - _rec_starttime);
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* WSEvents::GetRecordingTimecode() {
|
|
||||||
return ns_to_timestamp(GetRecordingTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates a scene change.
|
|
||||||
*
|
|
||||||
* @return {String} `scene-name` The new scene.
|
|
||||||
* @return {Array} `sources` List of sources in the new scene.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name SwitchScenes
|
|
||||||
* @category scenes
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::OnSceneChange() {
|
|
||||||
obs_data_t* data = obs_data_create();
|
|
||||||
|
|
||||||
obs_source_t* current_scene = obs_frontend_get_current_scene();
|
|
||||||
obs_data_array_t* scene_items = Utils::GetSceneItems(current_scene);
|
|
||||||
connectSceneSignals(current_scene);
|
|
||||||
|
|
||||||
obs_data_set_string(data, "scene-name", obs_source_get_name(current_scene));
|
|
||||||
obs_data_set_array(data, "sources", scene_items);
|
|
||||||
|
|
||||||
broadcastUpdate("SwitchScenes", data);
|
|
||||||
|
|
||||||
obs_data_array_release(scene_items);
|
|
||||||
obs_source_release(current_scene);
|
|
||||||
obs_data_release(data);
|
|
||||||
|
|
||||||
// Dirty fix : OBS blocks signals when swapping scenes in Studio Mode
|
|
||||||
// after transition end, so SelectedSceneChanged is never called...
|
|
||||||
if (Utils::IsPreviewModeActive()) {
|
|
||||||
QListWidget* list = Utils::GetSceneListControl();
|
|
||||||
SelectedSceneChanged(list->currentItem(), nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The scene list has been modified.
|
|
||||||
* Scenes have been added, removed, or renamed.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name ScenesChanged
|
|
||||||
* @category scenes
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::OnSceneListChange() {
|
|
||||||
broadcastUpdate("ScenesChanged");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when switching to another scene collection or when renaming the current scene collection.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name SceneCollectionChanged
|
|
||||||
* @category scenes
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnSceneCollectionChange() {
|
|
||||||
broadcastUpdate("SceneCollectionChanged");
|
|
||||||
|
|
||||||
scene_handler = nullptr;
|
|
||||||
transition_handler = nullptr;
|
|
||||||
|
|
||||||
OnTransitionListChange();
|
|
||||||
OnTransitionChange();
|
|
||||||
|
|
||||||
OnSceneListChange();
|
|
||||||
OnSceneChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when a scene collection is created, added, renamed, or removed.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name SceneCollectionListChanged
|
|
||||||
* @category scenes
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnSceneCollectionListChange() {
|
|
||||||
broadcastUpdate("SceneCollectionListChanged");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The active transition has been changed.
|
|
||||||
*
|
|
||||||
* @return {String} `transition-name` The name of the new active transition.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name SwitchTransition
|
|
||||||
* @category transitions
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnTransitionChange() {
|
|
||||||
obs_source_t* current_transition = obs_frontend_get_current_transition();
|
|
||||||
connectTransitionSignals(current_transition);
|
|
||||||
|
|
||||||
obs_data_t* data = obs_data_create();
|
|
||||||
obs_data_set_string(data, "transition-name",
|
|
||||||
obs_source_get_name(current_transition));
|
|
||||||
|
|
||||||
broadcastUpdate("SwitchTransition", data);
|
|
||||||
|
|
||||||
obs_data_release(data);
|
|
||||||
obs_source_release(current_transition);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The list of available transitions has been modified.
|
|
||||||
* Transitions have been added, removed, or renamed.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name TransitionListChanged
|
|
||||||
* @category transitions
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnTransitionListChange() {
|
|
||||||
broadcastUpdate("TransitionListChanged");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when switching to another profile or when renaming the current profile.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name ProfileChanged
|
|
||||||
* @category profiles
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnProfileChange() {
|
|
||||||
broadcastUpdate("ProfileChanged");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when a profile is created, added, renamed, or removed.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name ProfileListChanged
|
|
||||||
* @category profiles
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnProfileListChange() {
|
|
||||||
broadcastUpdate("ProfileListChanged");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A request to start streaming has been issued.
|
|
||||||
*
|
|
||||||
* @return {boolean} `preview-only` Always false (retrocompatibility).
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name StreamStarting
|
|
||||||
* @category streaming
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::OnStreamStarting() {
|
|
||||||
obs_data_t* data = obs_data_create();
|
|
||||||
obs_data_set_bool(data, "preview-only", false);
|
|
||||||
|
|
||||||
broadcastUpdate("StreamStarting", data);
|
|
||||||
|
|
||||||
obs_data_release(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Streaming started successfully.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name StreamStarted
|
|
||||||
* @category streaming
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::OnStreamStarted() {
|
|
||||||
_stream_starttime = os_gettime_ns();
|
|
||||||
_lastBytesSent = 0;
|
|
||||||
broadcastUpdate("StreamStarted");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A request to stop streaming has been issued.
|
|
||||||
*
|
|
||||||
* @return {boolean} `preview-only` Always false (retrocompatibility).
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name StreamStopping
|
|
||||||
* @category streaming
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::OnStreamStopping() {
|
|
||||||
obs_data_t* data = obs_data_create();
|
|
||||||
obs_data_set_bool(data, "preview-only", false);
|
|
||||||
|
|
||||||
broadcastUpdate("StreamStopping", data);
|
|
||||||
|
|
||||||
obs_data_release(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Streaming stopped successfully.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name StreamStopped
|
|
||||||
* @category streaming
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::OnStreamStopped() {
|
|
||||||
_stream_starttime = 0;
|
|
||||||
broadcastUpdate("StreamStopped");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A request to start recording has been issued.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name RecordingStarting
|
|
||||||
* @category recording
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::OnRecordingStarting() {
|
|
||||||
broadcastUpdate("RecordingStarting");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recording started successfully.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name RecordingStarted
|
|
||||||
* @category recording
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::OnRecordingStarted() {
|
|
||||||
_rec_starttime = os_gettime_ns();
|
|
||||||
broadcastUpdate("RecordingStarted");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A request to stop recording has been issued.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name RecordingStopping
|
|
||||||
* @category recording
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::OnRecordingStopping() {
|
|
||||||
broadcastUpdate("RecordingStopping");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recording stopped successfully.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name RecordingStopped
|
|
||||||
* @category recording
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::OnRecordingStopped() {
|
|
||||||
_rec_starttime = 0;
|
|
||||||
broadcastUpdate("RecordingStopped");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A request to start the replay buffer has been issued.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name ReplayStarting
|
|
||||||
* @category replay buffer
|
|
||||||
* @since 4.2.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnReplayStarting() {
|
|
||||||
broadcastUpdate("ReplayStarting");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replay Buffer started successfully
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name ReplayStarted
|
|
||||||
* @category replay buffer
|
|
||||||
* @since 4.2.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnReplayStarted() {
|
|
||||||
broadcastUpdate("ReplayStarted");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A request to start the replay buffer has been issued.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name ReplayStopping
|
|
||||||
* @category replay buffer
|
|
||||||
* @since 4.2.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnReplayStopping() {
|
|
||||||
broadcastUpdate("ReplayStopping");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replay Buffer stopped successfully
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name ReplayStopped
|
|
||||||
* @category replay buffer
|
|
||||||
* @since 4.2.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnReplayStopped() {
|
|
||||||
broadcastUpdate("ReplayStopped");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OBS is exiting.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name Exiting
|
|
||||||
* @category other
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::OnExit() {
|
|
||||||
broadcastUpdate("Exiting");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emit every 2 seconds.
|
|
||||||
*
|
|
||||||
* @return {boolean} `streaming` Current streaming state.
|
|
||||||
* @return {boolean} `recording` Current recording state.
|
|
||||||
* @return {boolean} `preview-only` Always false (retrocompatibility).
|
|
||||||
* @return {int} `bytes-per-sec` Amount of data per second (in bytes) transmitted by the stream encoder.
|
|
||||||
* @return {int} `kbits-per-sec` Amount of data per second (in kilobits) transmitted by the stream encoder.
|
|
||||||
* @return {double} `strain` Percentage of dropped frames.
|
|
||||||
* @return {int} `total-stream-time` Total time (in seconds) since the stream started.
|
|
||||||
* @return {int} `num-total-frames` Total number of frames transmitted since the stream started.
|
|
||||||
* @return {int} `num-dropped-frames` Number of frames dropped by the encoder since the stream started.
|
|
||||||
* @return {double} `fps` Current framerate.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name StreamStatus
|
|
||||||
* @category streaming
|
|
||||||
* @since 0.3
|
|
||||||
*/
|
|
||||||
void WSEvents::StreamStatus() {
|
|
||||||
bool streaming_active = obs_frontend_streaming_active();
|
|
||||||
bool recording_active = obs_frontend_recording_active();
|
|
||||||
|
|
||||||
obs_output_t* stream_output = obs_frontend_get_streaming_output();
|
|
||||||
|
|
||||||
if (!stream_output || !streaming_active) {
|
|
||||||
if (stream_output) {
|
|
||||||
obs_output_release(stream_output);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t bytes_sent = obs_output_get_total_bytes(stream_output);
|
|
||||||
uint64_t bytes_sent_time = os_gettime_ns();
|
|
||||||
|
|
||||||
if (bytes_sent < _lastBytesSent)
|
|
||||||
bytes_sent = 0;
|
|
||||||
|
|
||||||
if (bytes_sent == 0)
|
|
||||||
_lastBytesSent = 0;
|
|
||||||
|
|
||||||
uint64_t bytes_between = bytes_sent - _lastBytesSent;
|
|
||||||
double time_passed =
|
|
||||||
double(bytes_sent_time - _lastBytesSentTime) / 1000000000.0;
|
|
||||||
|
|
||||||
uint64_t bytes_per_sec = bytes_between / time_passed;
|
|
||||||
|
|
||||||
_lastBytesSent = bytes_sent;
|
|
||||||
_lastBytesSentTime = bytes_sent_time;
|
|
||||||
|
|
||||||
uint64_t totalStreamTime =
|
|
||||||
(os_gettime_ns() - _stream_starttime) / 1000000000;
|
|
||||||
|
|
||||||
int total_frames = obs_output_get_total_frames(stream_output);
|
|
||||||
int dropped_frames = obs_output_get_frames_dropped(stream_output);
|
|
||||||
|
|
||||||
float strain = obs_output_get_congestion(stream_output);
|
|
||||||
|
|
||||||
obs_data_t* data = obs_data_create();
|
|
||||||
obs_data_set_bool(data, "streaming", streaming_active);
|
|
||||||
obs_data_set_bool(data, "recording", recording_active);
|
|
||||||
obs_data_set_int(data, "bytes-per-sec", bytes_per_sec);
|
|
||||||
obs_data_set_int(data, "kbits-per-sec", (bytes_per_sec * 8) / 1024);
|
|
||||||
obs_data_set_int(data, "total-stream-time", totalStreamTime);
|
|
||||||
obs_data_set_int(data, "num-total-frames", total_frames);
|
|
||||||
obs_data_set_int(data, "num-dropped-frames", dropped_frames);
|
|
||||||
obs_data_set_double(data, "fps", obs_get_active_fps());
|
|
||||||
obs_data_set_double(data, "strain", strain);
|
|
||||||
obs_data_set_bool(data, "preview-only", false); // Retrocompat with OBSRemote
|
|
||||||
|
|
||||||
broadcastUpdate("StreamStatus", data);
|
|
||||||
|
|
||||||
obs_data_release(data);
|
|
||||||
obs_output_release(stream_output);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The active transition duration has been changed.
|
|
||||||
*
|
|
||||||
* @return {int} `new-duration` New transition duration.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name TransitionDurationChanged
|
|
||||||
* @category transitions
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::TransitionDurationChanged(int ms) {
|
|
||||||
obs_data_t* fields = obs_data_create();
|
|
||||||
obs_data_set_int(fields, "new-duration", ms);
|
|
||||||
|
|
||||||
broadcastUpdate("TransitionDurationChanged", fields);
|
|
||||||
obs_data_release(fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A transition (other than "cut") has begun.
|
|
||||||
*
|
|
||||||
* @return {String} `name` Transition name.
|
|
||||||
* @return {int} `duration` Transition duration (in milliseconds).
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name TransitionBegin
|
|
||||||
* @category transitions
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnTransitionBegin(void* param, calldata_t* data) {
|
|
||||||
UNUSED_PARAMETER(data);
|
|
||||||
WSEvents* instance = static_cast<WSEvents*>(param);
|
|
||||||
|
|
||||||
obs_source_t* current_transition = obs_frontend_get_current_transition();
|
|
||||||
const char* name = obs_source_get_name(current_transition);
|
|
||||||
int duration = Utils::GetTransitionDuration();
|
|
||||||
|
|
||||||
obs_data_t* fields = obs_data_create();
|
|
||||||
obs_data_set_string(fields, "name", name);
|
|
||||||
obs_data_set_int(fields, "duration", duration);
|
|
||||||
|
|
||||||
instance->broadcastUpdate("TransitionBegin", fields);
|
|
||||||
obs_data_release(fields);
|
|
||||||
obs_source_release(current_transition);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scene items have been reordered.
|
|
||||||
*
|
|
||||||
* @return {String} `scene-name` Name of the scene where items have been reordered.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name SourceOrderChanged
|
|
||||||
* @category sources
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnSceneReordered(void* param, calldata_t* data) {
|
|
||||||
WSEvents* instance = static_cast<WSEvents*>(param);
|
|
||||||
|
|
||||||
obs_scene_t* scene = nullptr;
|
|
||||||
calldata_get_ptr(data, "scene", &scene);
|
|
||||||
|
|
||||||
obs_data_t* fields = obs_data_create();
|
|
||||||
obs_data_set_string(fields, "scene-name",
|
|
||||||
obs_source_get_name(obs_scene_get_source(scene)));
|
|
||||||
|
|
||||||
instance->broadcastUpdate("SourceOrderChanged", fields);
|
|
||||||
obs_data_release(fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An item has been added to the current scene.
|
|
||||||
*
|
|
||||||
* @return {String} `scene-name` Name of the scene.
|
|
||||||
* @return {String} `item-name` Name of the item added to the scene.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name SceneItemAdded
|
|
||||||
* @category sources
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnSceneItemAdd(void* param, calldata_t* data) {
|
|
||||||
WSEvents* instance = static_cast<WSEvents*>(param);
|
|
||||||
|
|
||||||
obs_scene_t* scene = nullptr;
|
|
||||||
calldata_get_ptr(data, "scene", &scene);
|
|
||||||
|
|
||||||
obs_sceneitem_t* scene_item = nullptr;
|
|
||||||
calldata_get_ptr(data, "item", &scene_item);
|
|
||||||
|
|
||||||
const char* scene_name =
|
|
||||||
obs_source_get_name(obs_scene_get_source(scene));
|
|
||||||
const char* sceneitem_name =
|
|
||||||
obs_source_get_name(obs_sceneitem_get_source(scene_item));
|
|
||||||
|
|
||||||
obs_data_t* fields = obs_data_create();
|
|
||||||
obs_data_set_string(fields, "scene-name", scene_name);
|
|
||||||
obs_data_set_string(fields, "item-name", sceneitem_name);
|
|
||||||
|
|
||||||
instance->broadcastUpdate("SceneItemAdded", fields);
|
|
||||||
obs_data_release(fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An item has been removed from the current scene.
|
|
||||||
*
|
|
||||||
* @return {String} `scene-name` Name of the scene.
|
|
||||||
* @return {String} `item-name` Name of the item removed from the scene.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name SceneItemRemoved
|
|
||||||
* @category sources
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnSceneItemDelete(void* param, calldata_t* data) {
|
|
||||||
WSEvents* instance = static_cast<WSEvents*>(param);
|
|
||||||
|
|
||||||
obs_scene_t* scene = nullptr;
|
|
||||||
calldata_get_ptr(data, "scene", &scene);
|
|
||||||
|
|
||||||
obs_sceneitem_t* scene_item = nullptr;
|
|
||||||
calldata_get_ptr(data, "item", &scene_item);
|
|
||||||
|
|
||||||
const char* scene_name =
|
|
||||||
obs_source_get_name(obs_scene_get_source(scene));
|
|
||||||
const char* sceneitem_name =
|
|
||||||
obs_source_get_name(obs_sceneitem_get_source(scene_item));
|
|
||||||
|
|
||||||
obs_data_t* fields = obs_data_create();
|
|
||||||
obs_data_set_string(fields, "scene-name", scene_name);
|
|
||||||
obs_data_set_string(fields, "item-name", sceneitem_name);
|
|
||||||
|
|
||||||
instance->broadcastUpdate("SceneItemRemoved", fields);
|
|
||||||
obs_data_release(fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An item's visibility has been toggled.
|
|
||||||
*
|
|
||||||
* @return {String} `scene-name` Name of the scene.
|
|
||||||
* @return {String} `item-name` Name of the item in the scene.
|
|
||||||
* @return {boolean} `item-visible` New visibility state of the item.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name SceneItemVisibilityChanged
|
|
||||||
* @category sources
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
void WSEvents::OnSceneItemVisibilityChanged(void* param, calldata_t* data) {
|
|
||||||
WSEvents* instance = static_cast<WSEvents*>(param);
|
|
||||||
|
|
||||||
obs_scene_t* scene = nullptr;
|
|
||||||
calldata_get_ptr(data, "scene", &scene);
|
|
||||||
|
|
||||||
obs_sceneitem_t* scene_item = nullptr;
|
|
||||||
calldata_get_ptr(data, "item", &scene_item);
|
|
||||||
|
|
||||||
bool visible = false;
|
|
||||||
calldata_get_bool(data, "visible", &visible);
|
|
||||||
|
|
||||||
const char* scene_name =
|
|
||||||
obs_source_get_name(obs_scene_get_source(scene));
|
|
||||||
const char* sceneitem_name =
|
|
||||||
obs_source_get_name(obs_sceneitem_get_source(scene_item));
|
|
||||||
|
|
||||||
obs_data_t* fields = obs_data_create();
|
|
||||||
obs_data_set_string(fields, "scene-name", scene_name);
|
|
||||||
obs_data_set_string(fields, "item-name", sceneitem_name);
|
|
||||||
obs_data_set_bool(fields, "item-visible", visible);
|
|
||||||
|
|
||||||
instance->broadcastUpdate("SceneItemVisibilityChanged", fields);
|
|
||||||
obs_data_release(fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The selected preview scene has changed (only available in Studio Mode).
|
|
||||||
*
|
|
||||||
* @return {String} `scene-name` Name of the scene being previewed.
|
|
||||||
* @return {Source|Array} `sources` List of sources composing the scene. Same specification as [`GetCurrentScene`](#getcurrentscene).
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name PreviewSceneChanged
|
|
||||||
* @category studio mode
|
|
||||||
* @since 4.1.0
|
|
||||||
*/
|
|
||||||
void WSEvents::SelectedSceneChanged(QListWidgetItem* current, QListWidgetItem* prev) {
|
|
||||||
if (Utils::IsPreviewModeActive()) {
|
|
||||||
obs_scene_t* scene = Utils::SceneListItemToScene(current);
|
|
||||||
if (!scene) return;
|
|
||||||
|
|
||||||
obs_source_t* scene_source = obs_scene_get_source(scene);
|
|
||||||
obs_data_array_t* scene_items = Utils::GetSceneItems(scene_source);
|
|
||||||
|
|
||||||
obs_data_t* data = obs_data_create();
|
|
||||||
obs_data_set_string(data, "scene-name", obs_source_get_name(scene_source));
|
|
||||||
obs_data_set_array(data, "sources", scene_items);
|
|
||||||
|
|
||||||
broadcastUpdate("PreviewSceneChanged", data);
|
|
||||||
|
|
||||||
obs_data_array_release(scene_items);
|
|
||||||
obs_data_release(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Studio Mode has been enabled or disabled.
|
|
||||||
*
|
|
||||||
* @return {boolean} `new-state` The new enabled state of Studio Mode.
|
|
||||||
*
|
|
||||||
* @api events
|
|
||||||
* @name StudioModeSwitched
|
|
||||||
* @category studio mode
|
|
||||||
* @since 4.1.0
|
|
||||||
*/
|
|
||||||
void WSEvents::ModeSwitchClicked(bool checked) {
|
|
||||||
obs_data_t* data = obs_data_create();
|
|
||||||
obs_data_set_bool(data, "new-state", checked);
|
|
||||||
|
|
||||||
broadcastUpdate("StudioModeSwitched", data);
|
|
||||||
obs_data_release(data);
|
|
||||||
}
|
|
105
WSEvents.h
105
WSEvents.h
@ -1,105 +0,0 @@
|
|||||||
/*
|
|
||||||
obs-websocket
|
|
||||||
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
|
||||||
Copyright (C) 2017 Brendan Hagan <https://github.com/haganbmj>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef WSEVENTS_H
|
|
||||||
#define WSEVENTS_H
|
|
||||||
|
|
||||||
#include <obs-frontend-api.h>
|
|
||||||
#include <QListWidgetItem>
|
|
||||||
|
|
||||||
#include "WSServer.h"
|
|
||||||
|
|
||||||
class WSEvents : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit WSEvents(WSServer* srv);
|
|
||||||
~WSEvents();
|
|
||||||
static void FrontendEventHandler(
|
|
||||||
enum obs_frontend_event event, void* private_data);
|
|
||||||
void connectTransitionSignals(obs_source_t* transition);
|
|
||||||
void connectSceneSignals(obs_source_t* scene);
|
|
||||||
static WSEvents* Instance;
|
|
||||||
|
|
||||||
uint64_t GetStreamingTime();
|
|
||||||
const char* GetStreamingTimecode();
|
|
||||||
uint64_t GetRecordingTime();
|
|
||||||
const char* GetRecordingTimecode();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void deferredInitOperations();
|
|
||||||
void StreamStatus();
|
|
||||||
void TransitionDurationChanged(int ms);
|
|
||||||
void SelectedSceneChanged(
|
|
||||||
QListWidgetItem* current, QListWidgetItem* prev);
|
|
||||||
void ModeSwitchClicked(bool checked);
|
|
||||||
|
|
||||||
private:
|
|
||||||
WSServer* _srv;
|
|
||||||
signal_handler_t* transition_handler;
|
|
||||||
signal_handler_t* scene_handler;
|
|
||||||
|
|
||||||
bool _streaming_active;
|
|
||||||
bool _recording_active;
|
|
||||||
|
|
||||||
uint64_t _stream_starttime;
|
|
||||||
uint64_t _rec_starttime;
|
|
||||||
|
|
||||||
uint64_t _lastBytesSent;
|
|
||||||
uint64_t _lastBytesSentTime;
|
|
||||||
|
|
||||||
void broadcastUpdate(const char* updateType,
|
|
||||||
obs_data_t* additionalFields);
|
|
||||||
|
|
||||||
void OnSceneChange();
|
|
||||||
void OnSceneListChange();
|
|
||||||
void OnSceneCollectionChange();
|
|
||||||
void OnSceneCollectionListChange();
|
|
||||||
|
|
||||||
void OnTransitionChange();
|
|
||||||
void OnTransitionListChange();
|
|
||||||
|
|
||||||
void OnProfileChange();
|
|
||||||
void OnProfileListChange();
|
|
||||||
|
|
||||||
void OnStreamStarting();
|
|
||||||
void OnStreamStarted();
|
|
||||||
void OnStreamStopping();
|
|
||||||
void OnStreamStopped();
|
|
||||||
|
|
||||||
void OnRecordingStarting();
|
|
||||||
void OnRecordingStarted();
|
|
||||||
void OnRecordingStopping();
|
|
||||||
void OnRecordingStopped();
|
|
||||||
|
|
||||||
void OnReplayStarting();
|
|
||||||
void OnReplayStarted();
|
|
||||||
void OnReplayStopping();
|
|
||||||
void OnReplayStopped();
|
|
||||||
|
|
||||||
void OnExit();
|
|
||||||
|
|
||||||
static void OnTransitionBegin(void* param, calldata_t* data);
|
|
||||||
|
|
||||||
static void OnSceneReordered(void* param, calldata_t* data);
|
|
||||||
static void OnSceneItemAdd(void* param, calldata_t* data);
|
|
||||||
static void OnSceneItemDelete(void* param, calldata_t* data);
|
|
||||||
static void OnSceneItemVisibilityChanged(void* param, calldata_t* data);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // WSEVENTS_H
|
|
2326
WSRequestHandler.cpp
2326
WSRequestHandler.cpp
File diff suppressed because it is too large
Load Diff
@ -1,124 +0,0 @@
|
|||||||
/*
|
|
||||||
obs-websocket
|
|
||||||
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
|
||||||
Copyright (C) 2017 Mikhail Swift <https://github.com/mikhailswift>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef WSREQUESTHANDLER_H
|
|
||||||
#define WSREQUESTHANDLER_H
|
|
||||||
|
|
||||||
#include <QMap>
|
|
||||||
#include <QWebSocket>
|
|
||||||
#include <QWebSocketServer>
|
|
||||||
|
|
||||||
#include <obs-frontend-api.h>
|
|
||||||
|
|
||||||
class WSRequestHandler : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit WSRequestHandler(QWebSocket* client);
|
|
||||||
~WSRequestHandler();
|
|
||||||
void processIncomingMessage(QString textMessage);
|
|
||||||
bool hasField(const char* name);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static obs_service_t* _service;
|
|
||||||
QWebSocket* _client;
|
|
||||||
const char* _messageId;
|
|
||||||
const char* _requestType;
|
|
||||||
obs_data_t* data;
|
|
||||||
|
|
||||||
QMap<QString, void(*)(WSRequestHandler*)> messageMap;
|
|
||||||
QSet<QString> authNotRequired;
|
|
||||||
|
|
||||||
void SendOKResponse(obs_data_t* additionalFields = NULL);
|
|
||||||
void SendErrorResponse(const char* errorMessage);
|
|
||||||
void SendResponse(obs_data_t* response);
|
|
||||||
|
|
||||||
static void HandleGetVersion(WSRequestHandler* req);
|
|
||||||
static void HandleGetAuthRequired(WSRequestHandler* req);
|
|
||||||
static void HandleAuthenticate(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleSetCurrentScene(WSRequestHandler* req);
|
|
||||||
static void HandleGetCurrentScene(WSRequestHandler* req);
|
|
||||||
static void HandleGetSceneList(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleSetSceneItemRender(WSRequestHandler* req);
|
|
||||||
static void HandleSetSceneItemPosition(WSRequestHandler* req);
|
|
||||||
static void HandleSetSceneItemTransform(WSRequestHandler* req);
|
|
||||||
static void HandleSetSceneItemCrop(WSRequestHandler* req);
|
|
||||||
static void HandleResetSceneItem(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleGetStreamingStatus(WSRequestHandler* req);
|
|
||||||
static void HandleStartStopStreaming(WSRequestHandler* req);
|
|
||||||
static void HandleStartStopRecording(WSRequestHandler* req);
|
|
||||||
static void HandleStartStreaming(WSRequestHandler* req);
|
|
||||||
static void HandleStopStreaming(WSRequestHandler* req);
|
|
||||||
static void HandleStartRecording(WSRequestHandler* req);
|
|
||||||
static void HandleStopRecording(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleStartStopReplayBuffer(WSRequestHandler* req);
|
|
||||||
static void HandleStartReplayBuffer(WSRequestHandler* req);
|
|
||||||
static void HandleStopReplayBuffer(WSRequestHandler* req);
|
|
||||||
static void HandleSaveReplayBuffer(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleSetRecordingFolder(WSRequestHandler* req);
|
|
||||||
static void HandleGetRecordingFolder(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleGetTransitionList(WSRequestHandler* req);
|
|
||||||
static void HandleGetCurrentTransition(WSRequestHandler* req);
|
|
||||||
static void HandleSetCurrentTransition(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleSetVolume(WSRequestHandler* req);
|
|
||||||
static void HandleGetVolume(WSRequestHandler* req);
|
|
||||||
static void HandleToggleMute(WSRequestHandler* req);
|
|
||||||
static void HandleSetMute(WSRequestHandler* req);
|
|
||||||
static void HandleGetMute(WSRequestHandler* req);
|
|
||||||
static void HandleSetSyncOffset(WSRequestHandler* req);
|
|
||||||
static void HandleGetSyncOffset(WSRequestHandler* req);
|
|
||||||
static void HandleGetSpecialSources(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleSetCurrentSceneCollection(WSRequestHandler* req);
|
|
||||||
static void HandleGetCurrentSceneCollection(WSRequestHandler* req);
|
|
||||||
static void HandleListSceneCollections(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleSetCurrentProfile(WSRequestHandler* req);
|
|
||||||
static void HandleGetCurrentProfile(WSRequestHandler* req);
|
|
||||||
static void HandleListProfiles(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleSetStreamSettings(WSRequestHandler* req);
|
|
||||||
static void HandleGetStreamSettings(WSRequestHandler* req);
|
|
||||||
static void HandleSaveStreamSettings(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleSetTransitionDuration(WSRequestHandler* req);
|
|
||||||
static void HandleGetTransitionDuration(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleGetStudioModeStatus(WSRequestHandler* req);
|
|
||||||
static void HandleGetPreviewScene(WSRequestHandler* req);
|
|
||||||
static void HandleSetPreviewScene(WSRequestHandler* req);
|
|
||||||
static void HandleTransitionToProgram(WSRequestHandler* req);
|
|
||||||
static void HandleEnableStudioMode(WSRequestHandler* req);
|
|
||||||
static void HandleDisableStudioMode(WSRequestHandler* req);
|
|
||||||
static void HandleToggleStudioMode(WSRequestHandler* req);
|
|
||||||
|
|
||||||
static void HandleSetTextGDIPlusProperties(WSRequestHandler* req);
|
|
||||||
static void HandleGetTextGDIPlusProperties(WSRequestHandler* req);
|
|
||||||
static void HandleSetBrowserSourceProperties(WSRequestHandler* req);
|
|
||||||
static void HandleGetBrowserSourceProperties(WSRequestHandler* req);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // WSPROTOCOL_H
|
|
147
WSServer.cpp
147
WSServer.cpp
@ -1,147 +0,0 @@
|
|||||||
/*
|
|
||||||
obs-websocket
|
|
||||||
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <QtWebSockets/QWebSocket>
|
|
||||||
#include <QtCore/QThread>
|
|
||||||
#include <QtCore/QByteArray>
|
|
||||||
#include <obs-frontend-api.h>
|
|
||||||
|
|
||||||
#include "WSServer.h"
|
|
||||||
#include "obs-websocket.h"
|
|
||||||
#include "Config.h"
|
|
||||||
#include "Utils.h"
|
|
||||||
|
|
||||||
QT_USE_NAMESPACE
|
|
||||||
|
|
||||||
WSServer* WSServer::Instance = nullptr;
|
|
||||||
|
|
||||||
WSServer::WSServer(QObject* parent)
|
|
||||||
: QObject(parent),
|
|
||||||
_wsServer(Q_NULLPTR),
|
|
||||||
_clients(),
|
|
||||||
_clMutex(QMutex::Recursive) {
|
|
||||||
_wsServer = new QWebSocketServer(
|
|
||||||
QStringLiteral("obs-websocket"),
|
|
||||||
QWebSocketServer::NonSecureMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
WSServer::~WSServer() {
|
|
||||||
Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSServer::Start(quint16 port) {
|
|
||||||
if (port == _wsServer->serverPort())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if(_wsServer->isListening())
|
|
||||||
Stop();
|
|
||||||
|
|
||||||
bool serverStarted = _wsServer->listen(QHostAddress::Any, port);
|
|
||||||
if (serverStarted) {
|
|
||||||
connect(_wsServer, SIGNAL(newConnection()),
|
|
||||||
this, SLOT(onNewConnection()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSServer::Stop() {
|
|
||||||
_clMutex.lock();
|
|
||||||
for(QWebSocket* pClient : _clients) {
|
|
||||||
pClient->close();
|
|
||||||
}
|
|
||||||
_clMutex.unlock();
|
|
||||||
|
|
||||||
_wsServer->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSServer::broadcast(QString message) {
|
|
||||||
_clMutex.lock();
|
|
||||||
for(QWebSocket* pClient : _clients) {
|
|
||||||
if (Config::Current()->AuthRequired
|
|
||||||
&& (pClient->property(PROP_AUTHENTICATED).toBool() == false)) {
|
|
||||||
// Skip this client if unauthenticated
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
pClient->sendTextMessage(message);
|
|
||||||
}
|
|
||||||
_clMutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSServer::onNewConnection() {
|
|
||||||
QWebSocket* pSocket = _wsServer->nextPendingConnection();
|
|
||||||
if (pSocket) {
|
|
||||||
connect(pSocket, SIGNAL(textMessageReceived(const QString&)),
|
|
||||||
this, SLOT(onTextMessageReceived(QString)));
|
|
||||||
connect(pSocket, SIGNAL(disconnected()),
|
|
||||||
this, SLOT(onSocketDisconnected()));
|
|
||||||
|
|
||||||
pSocket->setProperty(PROP_AUTHENTICATED, false);
|
|
||||||
|
|
||||||
_clMutex.lock();
|
|
||||||
_clients << pSocket;
|
|
||||||
_clMutex.unlock();
|
|
||||||
|
|
||||||
QHostAddress clientAddr = pSocket->peerAddress();
|
|
||||||
QString clientIp = Utils::FormatIPAddress(clientAddr);
|
|
||||||
|
|
||||||
blog(LOG_INFO, "new client connection from %s:%d",
|
|
||||||
clientIp.toUtf8().constData(), pSocket->peerPort());
|
|
||||||
|
|
||||||
QString msg = QString(obs_module_text("OBSWebsocket.ConnectNotify.ClientIP"))
|
|
||||||
+ QString(" ")
|
|
||||||
+ Utils::FormatIPAddress(clientAddr);
|
|
||||||
|
|
||||||
Utils::SysTrayNotify(msg,
|
|
||||||
QSystemTrayIcon::Information,
|
|
||||||
QString(obs_module_text("OBSWebsocket.ConnectNotify.Connected")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSServer::onTextMessageReceived(QString message) {
|
|
||||||
QWebSocket* pSocket = qobject_cast<QWebSocket*>(sender());
|
|
||||||
if (pSocket) {
|
|
||||||
WSRequestHandler handler(pSocket);
|
|
||||||
handler.processIncomingMessage(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSServer::onSocketDisconnected() {
|
|
||||||
QWebSocket* pSocket = qobject_cast<QWebSocket*>(sender());
|
|
||||||
if (pSocket) {
|
|
||||||
pSocket->setProperty(PROP_AUTHENTICATED, false);
|
|
||||||
|
|
||||||
_clMutex.lock();
|
|
||||||
_clients.removeAll(pSocket);
|
|
||||||
_clMutex.unlock();
|
|
||||||
|
|
||||||
pSocket->deleteLater();
|
|
||||||
|
|
||||||
QHostAddress clientAddr = pSocket->peerAddress();
|
|
||||||
QString clientIp = Utils::FormatIPAddress(clientAddr);
|
|
||||||
|
|
||||||
blog(LOG_INFO, "client %s:%d disconnected",
|
|
||||||
clientIp.toUtf8().constData(), pSocket->peerPort());
|
|
||||||
|
|
||||||
QString msg = QString(obs_module_text("OBSWebsocket.ConnectNotify.ClientIP"))
|
|
||||||
+ QString(" ")
|
|
||||||
+ Utils::FormatIPAddress(clientAddr);
|
|
||||||
|
|
||||||
Utils::SysTrayNotify(msg,
|
|
||||||
QSystemTrayIcon::Information,
|
|
||||||
QString(obs_module_text("OBSWebsocket.ConnectNotify.Disconnected")));
|
|
||||||
}
|
|
||||||
}
|
|
42
appveyor.yml
42
appveyor.yml
@ -4,34 +4,20 @@ environment:
|
|||||||
install:
|
install:
|
||||||
- git submodule update --init --recursive
|
- git submodule update --init --recursive
|
||||||
- cd C:\projects\
|
- cd C:\projects\
|
||||||
- if not exist dependencies2013.zip curl -kLO https://obsproject.com/downloads/dependencies2013.zip -f --retry 5 -C -
|
- if not exist dependencies2015.zip curl -kLO https://obsproject.com/downloads/dependencies2015.zip -f --retry 5 -C -
|
||||||
- 7z x dependencies2013.zip -odependencies2013
|
- 7z x dependencies2015.zip -odependencies2015
|
||||||
- if not exist qt570.zip curl -kLO https://www.slepin.fr/obs-websocket/ci/qt570.zip -f --retry 5 -C -
|
- set DepsPath32=%CD%\dependencies2015\win32
|
||||||
- 7z x qt570.zip -o"Qt5.7.0"
|
- set DepsPath64=%CD%\dependencies2015\win64
|
||||||
- set DepsPath32=%CD%\dependencies2013\win32
|
- call C:\projects\obs-websocket\CI\install-setup-qt.cmd
|
||||||
- set DepsPath64=%CD%\dependencies2013\win64
|
- set build_config=RelWithDebInfo
|
||||||
- set QTDIR32=%CD%\Qt5.7.0\msvc2013
|
- call C:\projects\obs-websocket\CI\install-build-obs.cmd
|
||||||
- set QTDIR64=%CD%\Qt5.7.0\msvc2013_64
|
|
||||||
- set build_config=Release
|
|
||||||
- git clone --recursive https://github.com/jp9000/obs-studio
|
|
||||||
- cd C:\projects\obs-studio\
|
|
||||||
- git checkout 19.0.3
|
|
||||||
- mkdir build
|
|
||||||
- mkdir build32
|
|
||||||
- mkdir build64
|
|
||||||
- cd ./build32
|
|
||||||
- cmake -G "Visual Studio 12 2013" -DCOPIED_DEPENDENCIES=false -DCOPY_DEPENDENCIES=true ..
|
|
||||||
- cd ../build64
|
|
||||||
- cmake -G "Visual Studio 12 2013 Win64" -DCOPIED_DEPENDENCIES=false -DCOPY_DEPENDENCIES=true ..
|
|
||||||
- call msbuild /m /p:Configuration=%build_config% C:\projects\obs-studio\build32\obs-studio.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
|
||||||
- call msbuild /m /p:Configuration=%build_config% C:\projects\obs-studio\build64\obs-studio.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
|
||||||
- cd C:\projects\obs-websocket\
|
- cd C:\projects\obs-websocket\
|
||||||
- mkdir build32
|
- mkdir build32
|
||||||
- mkdir build64
|
- mkdir build64
|
||||||
- cd ./build32
|
- cd ./build32
|
||||||
- cmake -G "Visual Studio 12 2013" -DQTDIR="%QTDIR32%" -DLibObs_DIR="C:\projects\obs-studio\build32\libobs" -DLIBOBS_INCLUDE_DIR="C:\projects\obs-studio\libobs" -DLIBOBS_LIB="C:\projects\obs-studio\build32\libobs\%build_config%\obs.lib" -DOBS_FRONTEND_LIB="C:\projects\obs-studio\build32\UI\obs-frontend-api\%build_config%\obs-frontend-api.lib" ..
|
- cmake -G "Visual Studio 14 2015" -DQTDIR="%QTDIR32%" -DLibObs_DIR="C:\projects\obs-studio\build32\libobs" -DLIBOBS_INCLUDE_DIR="C:\projects\obs-studio\libobs" -DLIBOBS_LIB="C:\projects\obs-studio\build32\libobs\%build_config%\obs.lib" -DOBS_FRONTEND_LIB="C:\projects\obs-studio\build32\UI\obs-frontend-api\%build_config%\obs-frontend-api.lib" ..
|
||||||
- cd ../build64
|
- cd ../build64
|
||||||
- cmake -G "Visual Studio 12 2013 Win64" -DQTDIR="%QTDIR64%" -DLibObs_DIR="C:\projects\obs-studio\build64\libobs" -DLIBOBS_INCLUDE_DIR="C:\projects\obs-studio\libobs" -DLIBOBS_LIB="C:\projects\obs-studio\build64\libobs\%build_config%\obs.lib" -DOBS_FRONTEND_LIB="C:\projects\obs-studio\build64\UI\obs-frontend-api\%build_config%\obs-frontend-api.lib" ..
|
- cmake -G "Visual Studio 14 2015 Win64" -DQTDIR="%QTDIR64%" -DLibObs_DIR="C:\projects\obs-studio\build64\libobs" -DLIBOBS_INCLUDE_DIR="C:\projects\obs-studio\libobs" -DLIBOBS_LIB="C:\projects\obs-studio\build64\libobs\%build_config%\obs.lib" -DOBS_FRONTEND_LIB="C:\projects\obs-studio\build64\UI\obs-frontend-api\%build_config%\obs-frontend-api.lib" ..
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
- call msbuild /m /p:Configuration=%build_config% C:\projects\obs-websocket\build32\obs-websocket.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
- call msbuild /m /p:Configuration=%build_config% C:\projects\obs-websocket\build32\obs-websocket.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
||||||
@ -39,12 +25,16 @@ build_script:
|
|||||||
|
|
||||||
before_deploy:
|
before_deploy:
|
||||||
- 7z a "C:\projects\obs-websocket\build.zip" C:\projects\obs-websocket\release\*
|
- 7z a "C:\projects\obs-websocket\build.zip" C:\projects\obs-websocket\release\*
|
||||||
|
- set PATH=%PATH%;"C:\\Program Files (x86)\\Inno Setup 5"
|
||||||
|
- iscc "C:\projects\obs-websocket\installer\installer.iss"
|
||||||
|
|
||||||
deploy_script:
|
deploy_script:
|
||||||
- ps: Push-AppveyorArtifact "C:\projects\obs-websocket\build.zip" -FileName "obs-websocket-$(git log --pretty=format:'%h' -n 1).zip"
|
- ps: Push-AppveyorArtifact "C:\projects\obs-websocket\build.zip" -FileName "obs-websocket-$(git log --pretty=format:'%h' -n 1)-Windows.zip"
|
||||||
|
- ps: Push-AppveyorArtifact "C:\projects\obs-websocket\installer\Output\obs-websocket-Windows-Installer.exe" -FileName "obs-websocket-$(git log --pretty=format:'%h' -n 1)-Windows-Installer.exe"
|
||||||
|
|
||||||
test: off
|
test: off
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
- C:\projects\dependencies2013.zip
|
- C:\projects\dependencies2015.zip
|
||||||
- C:\projects\qt570.zip
|
- C:\projects\obs-studio-last-tag-built.txt
|
||||||
|
- C:\projects\obs-studio\
|
||||||
|
20
azure-pipelines.yml
Normal file
20
azure-pipelines.yml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
pool:
|
||||||
|
vmImage: 'macOS-10.13'
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- script: ./CI/install-dependencies-macos.sh
|
||||||
|
displayName: 'Install Dependencies'
|
||||||
|
|
||||||
|
- script: ./CI/install-build-obs-macos.sh
|
||||||
|
displayName: 'Build OBS'
|
||||||
|
|
||||||
|
- script: ./CI/build-macos.sh
|
||||||
|
displayName: 'Build obs-websocket'
|
||||||
|
|
||||||
|
- script: ./CI/package-macos.sh
|
||||||
|
displayName: 'Package'
|
||||||
|
|
||||||
|
- task: PublishBuildArtifacts@1
|
||||||
|
inputs:
|
||||||
|
pathtoPublish: './release'
|
||||||
|
artifactName: 'build'
|
3
crowdin.yml
Normal file
3
crowdin.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
files:
|
||||||
|
- source: /data/locale/en-US.ini
|
||||||
|
translation: /data/locale/%locale%.ini
|
@ -4,3 +4,11 @@ OBSWebsocket.Settings.ServerEnable="Websocket-Server aktivieren"
|
|||||||
OBSWebsocket.Settings.ServerPort="Server Port"
|
OBSWebsocket.Settings.ServerPort="Server Port"
|
||||||
OBSWebsocket.Settings.AuthRequired="Authentifizierung erforderlich"
|
OBSWebsocket.Settings.AuthRequired="Authentifizierung erforderlich"
|
||||||
OBSWebsocket.Settings.Password="Passwort"
|
OBSWebsocket.Settings.Password="Passwort"
|
||||||
|
OBSWebsocket.Settings.DebugEnable="Debug-Protokollierung aktivieren"
|
||||||
|
OBSWebsocket.Settings.AlertsEnable="Infobereich-Benachrichtigungen aktivieren"
|
||||||
|
OBSWebsocket.NotifyConnect.Title="Neue WebSocket Verbindung"
|
||||||
|
OBSWebsocket.NotifyConnect.Message="Client %1 verbunden"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Title="WebSocket-Client getrennt"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Message="Client %1 getrennt"
|
||||||
|
OBSWebsocket.Server.StartFailed.Title="WebSocket-Server Fehler"
|
||||||
|
OBSWebsocket.Server.StartFailed.Message="Der WebSocket-Server konnte nicht gestartet werden, mögliche Gründe:\n - TCP Port %1 wird möglicherweise gerade von einem anderen Programm verwendet. Versuchen Sie einen anderen Port in den WebSocket-Server Einstellungen zu setzten oder alle Programme zu beenden, die den Port möglicherweise verwenden.\n - Ein unbekannter Netzwerkfehler ist aufgetreten. Versuchen Sie es erneut mit anderen Einstellungen, einem OBS neustart oder einem System neustart."
|
||||||
|
@ -5,6 +5,10 @@ OBSWebsocket.Settings.ServerPort="Server Port"
|
|||||||
OBSWebsocket.Settings.AuthRequired="Enable authentication"
|
OBSWebsocket.Settings.AuthRequired="Enable authentication"
|
||||||
OBSWebsocket.Settings.Password="Password"
|
OBSWebsocket.Settings.Password="Password"
|
||||||
OBSWebsocket.Settings.DebugEnable="Enable debug logging"
|
OBSWebsocket.Settings.DebugEnable="Enable debug logging"
|
||||||
OBSWebsocket.ConnectNotify.Connected="New WebSocket connection"
|
OBSWebsocket.Settings.AlertsEnable="Enable System Tray Alerts"
|
||||||
OBSWebsocket.ConnectNotify.Disconnected="WebSocket client disconnected"
|
OBSWebsocket.NotifyConnect.Title="New WebSocket connection"
|
||||||
OBSWebsocket.ConnectNotify.ClientIP="Client Address:"
|
OBSWebsocket.NotifyConnect.Message="Client %1 connected"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Title="WebSocket client disconnected"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Message="Client %1 disconnected"
|
||||||
|
OBSWebsocket.Server.StartFailed.Title="WebSocket Server failure"
|
||||||
|
OBSWebsocket.Server.StartFailed.Message="The obs-websocket server failed to start, maybe because:\n - TCP port %1 may currently be in use elsewhere on this system, possibly by another application. Try setting a different TCP port in the WebSocket server settings, or stop any application that could be using this port.\n - An unknown network error happened on your system. Try again by changing settings, restarting OBS or restarting your system."
|
14
data/locale/es-ES.ini
Normal file
14
data/locale/es-ES.ini
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
OBSWebsocket.Menu.SettingsItem="Configuración del servidor obs-websocket"
|
||||||
|
OBSWebsocket.Settings.DialogTitle="obs-websocket"
|
||||||
|
OBSWebsocket.Settings.ServerEnable="Habilitar el servidor Websocket"
|
||||||
|
OBSWebsocket.Settings.ServerPort="Puerto del Servidor"
|
||||||
|
OBSWebsocket.Settings.AuthRequired="Habilitar autenticación"
|
||||||
|
OBSWebsocket.Settings.Password="Contraseña"
|
||||||
|
OBSWebsocket.Settings.DebugEnable="Habilitar registro de depuración"
|
||||||
|
OBSWebsocket.Settings.AlertsEnable="Habilitar alertas de la bandeja de sistema"
|
||||||
|
OBSWebsocket.NotifyConnect.Title="Nueva conexión WebSocket"
|
||||||
|
OBSWebsocket.NotifyConnect.Message="Cliente %1 conectado"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Title="Cliente WebSocket desconectado"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Message="Cliente %1 desconectado"
|
||||||
|
OBSWebsocket.Server.StartFailed.Title="Fallo del servidor WebSocket"
|
||||||
|
OBSWebsocket.Server.StartFailed.Message="El servidor obs-websocket no se pudo iniciar, tal vez porque: \n - el puerto TCP %1 podría estar actualmente en uso en este sistema, posiblemente por otra aplicación. Intente configurar un puerto TCP diferente en la configuración del servidor WebSocket, o detenga cualquier aplicación que pudiese estar utilizando este puerto \n - Un error de red desconocido ha ocurrido en su sistema. Inténtalo de nuevo cambiando la configuración, reiniciando OBS o reiniciando su sistema."
|
@ -1,9 +1,13 @@
|
|||||||
OBSWebsocket.Menu.SettingsItem="Paramètres du serveur Websocket"
|
OBSWebsocket.Menu.SettingsItem="Paramètres du serveur Websocket"
|
||||||
OBSWebsocket.Settings.DialogTitle="obs-websocket"
|
OBSWebsocket.Settings.ServerEnable="Activer le serveur WebSocket"
|
||||||
OBSWebsocket.Settings.ServerEnable="Activer le serveur Websockets"
|
|
||||||
OBSWebsocket.Settings.ServerPort="Port du serveur"
|
OBSWebsocket.Settings.ServerPort="Port du serveur"
|
||||||
OBSWebsocket.Settings.AuthRequired="Activer l'authentification"
|
OBSWebsocket.Settings.AuthRequired="Activer l'authentification"
|
||||||
OBSWebsocket.Settings.Password="Mot de passe"
|
OBSWebsocket.Settings.Password="Mot de passe"
|
||||||
OBSWebsocket.ConnectNotify.Connected="Nouvelle connexion WebSocket"
|
OBSWebsocket.Settings.DebugEnable="Débogage dans le fichier journal"
|
||||||
OBSWebsocket.ConnectNotify.Disconnected="Déconnexion WebSocket"
|
OBSWebsocket.Settings.AlertsEnable="Notifications de connexion/déconnexion"
|
||||||
OBSWebsocket.ConnectNotify.ClientIP="Adresse du client :"
|
OBSWebsocket.NotifyConnect.Title="Nouvelle connexion WebSocket"
|
||||||
|
OBSWebsocket.NotifyConnect.Message="Le client %1 s'est connecté"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Title="Déconnexion WebSocket"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Message="Le client %1 s'est déconnecté"
|
||||||
|
OBSWebsocket.Server.StartFailed.Title="Impossible de démarrer le serveur WebSocket"
|
||||||
|
OBSWebsocket.Server.StartFailed.Message="Le serveur WebSocket n'a pas pu démarrer, peut-être parce que :\n - Le port TCP %1 est en cours d'utilisation sur ce système, certainement par un autre programme. Essayez un port différent dans les réglages du serveur WebSocket, ou arrêtez tout programme susceptible d'utiliser ce port.\n - Une erreur réseau inconnue est survenue. Essayez à nouveau en modifiant vos réglages, en redémarrant OBS ou en redémarrant votre ordinateur."
|
||||||
|
14
data/locale/it-IT.ini
Normal file
14
data/locale/it-IT.ini
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
OBSWebsocket.Menu.SettingsItem="Impostazioni del server di WebSocket"
|
||||||
|
OBSWebsocket.Settings.DialogTitle="obs-websocket"
|
||||||
|
OBSWebsocket.Settings.ServerEnable="Abilitare il server Websocket"
|
||||||
|
OBSWebsocket.Settings.ServerPort="Porta del server"
|
||||||
|
OBSWebsocket.Settings.AuthRequired="Abilitare l'autenticazione"
|
||||||
|
OBSWebsocket.Settings.Password="Password"
|
||||||
|
OBSWebsocket.Settings.DebugEnable="Attivare la registrazione di debug"
|
||||||
|
OBSWebsocket.Settings.AlertsEnable="Attivare gli avvisi di vassoio di sistema"
|
||||||
|
OBSWebsocket.NotifyConnect.Title="Nuova connessione WebSocket"
|
||||||
|
OBSWebsocket.NotifyConnect.Message="%1 cliente collegato"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Title="WebSocket cliente disconnesso"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Message="%1 cliente disconnesso"
|
||||||
|
OBSWebsocket.Server.StartFailed.Title="Errore del WebSocket Server"
|
||||||
|
OBSWebsocket.Server.StartFailed.Message="Impossibile avviare, forse perché il server di obs-websocket: \n - %1 porta TCP potrebbe essere attualmente in uso altrove su questo sistema, possibilmente da un'altra applicazione. Provare a impostare una porta TCP diversa nelle impostazioni del server di WebSocket, o arrestare tutte le applicazioni che potrebbero utilizzare questa porta. \n - è verificato un errore di rete sconosciuto sul sistema. Riprova modificando le impostazioni, riavviare OBS o riavvio del sistema."
|
8
data/locale/ja-JP.ini
Normal file
8
data/locale/ja-JP.ini
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
OBSWebsocket.Menu.SettingsItem="Websocket サーバー設定"
|
||||||
|
OBSWebsocket.Settings.DialogTitle="obs-websocket"
|
||||||
|
OBSWebsocket.Settings.ServerEnable="Websocket サーバーを有効にする"
|
||||||
|
OBSWebsocket.Settings.ServerPort="サーバーポート"
|
||||||
|
OBSWebsocket.Settings.AuthRequired="認証を有効にする"
|
||||||
|
OBSWebsocket.Settings.Password="パスワード"
|
||||||
|
OBSWebsocket.Settings.DebugEnable="デバッグログを有効にする"
|
||||||
|
OBSWebsocket.NotifyConnect.Title="新しいWebSocket接続"
|
0
data/locale/ko-KR.ini
Normal file
0
data/locale/ko-KR.ini
Normal file
@ -1,6 +1,14 @@
|
|||||||
OBSWebsocket.Menu.SettingsItem="Websocket server instellingen"
|
OBSWebsocket.Menu.SettingsItem="Websocket server instellingen"
|
||||||
OBSWebsocket.Settings.DialogTitle="obs-websocket"
|
OBSWebsocket.Settings.DialogTitle="obs-websocket"
|
||||||
OBSWebsocket.Settings.ServerEnable="Activeer Websocket server"
|
OBSWebsocket.Settings.ServerEnable="Activeer Websocket server"
|
||||||
OBSWebsocket.Settings.ServerPort="Server Poort"
|
OBSWebsocket.Settings.ServerPort="Serverpoort"
|
||||||
OBSWebsocket.Settings.AuthRequired="Activeer authenticatie"
|
OBSWebsocket.Settings.AuthRequired="Activeer authenticatie"
|
||||||
OBSWebsocket.Settings.Password="Wachtwoord"
|
OBSWebsocket.Settings.Password="Wachtwoord"
|
||||||
|
OBSWebsocket.Settings.DebugEnable="Activeer debug logs"
|
||||||
|
OBSWebsocket.Settings.AlertsEnable="Systemvak waarschuwingen inschakelen"
|
||||||
|
OBSWebsocket.NotifyConnect.Title="Nieuwe WebSocket verbinding"
|
||||||
|
OBSWebsocket.NotifyConnect.Message="Client %1 verbonden"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Title="WebSocket client connectie verbroken"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Message="Client %1 losgekoppeld"
|
||||||
|
OBSWebsocket.Server.StartFailed.Title="WebSocket Server mislukt"
|
||||||
|
OBSWebsocket.Server.StartFailed.Message="De obs-websocket server kan niet worden gestart, misschien omdat: \n - TCP-poort %1 momenteel wordt gebruikt elders op dit systeem, eventueel door een andere toepassing. Probeer een andere TCP-poort instellen in de WebSocket Server-instellingen of stoppen van elke toepassing die deze poort zouden kunnen gebruiken.\n Een onbekende netwerkfout gebeurde op uw systeem. Probeer het opnieuw door de instellingen wijzigen, OBS herstarten of opnieuw opstarten van uw systeem."
|
||||||
|
@ -4,3 +4,11 @@ OBSWebsocket.Settings.ServerEnable="Włącz serwer zdalnego sterowania (Websocke
|
|||||||
OBSWebsocket.Settings.ServerPort="Port serwera"
|
OBSWebsocket.Settings.ServerPort="Port serwera"
|
||||||
OBSWebsocket.Settings.AuthRequired="Wymagaj hasła"
|
OBSWebsocket.Settings.AuthRequired="Wymagaj hasła"
|
||||||
OBSWebsocket.Settings.Password="Hasło"
|
OBSWebsocket.Settings.Password="Hasło"
|
||||||
|
OBSWebsocket.Settings.DebugEnable="Włącz rejestrowanie debugowania"
|
||||||
|
OBSWebsocket.Settings.AlertsEnable="Włącz powiadomienia o zasobniku systemowym"
|
||||||
|
OBSWebsocket.NotifyConnect.Title="Nowe połączenie WebSocket"
|
||||||
|
OBSWebsocket.NotifyConnect.Message="Klient %1 połączony"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Title="Klient WebSocket odłączony"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Message="Klient %1 połączony"
|
||||||
|
OBSWebsocket.Server.StartFailed.Title="Awaria serwera WebSocket"
|
||||||
|
OBSWebsocket.Server.StartFailed.Message="Nie udało się uruchomić serwera obs-websocket, może a powodu: \n - TCP port %1 może być obecnie używany gdzie indziej w tym systemie, możliwie przez inną aplikację. Spróbuj ustawić inny port TCP w ustawieniach serwera WebSocket, lub zatrzymać dowolną aplikację, która może używać tego portu \n -nieznany błąd sieci wydarzył się w systemie. Spróbuj ponownie, zmieniając ustawienia, ponownie uruchamiając OBS lub ponownie uruchamiając system."
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
OBSWebsocket.Menu.SettingsItem="Configuraçes do Servidor Websocket"
|
OBSWebsocket.Menu.SettingsItem="Configuraçes do Servidor Websocket"
|
||||||
OBSWebsocket.Settings.DialogTitle="obs-websocket"
|
|
||||||
OBSWebsocket.Settings.ServerEnable="Habilitar o Servidor Websocket"
|
OBSWebsocket.Settings.ServerEnable="Habilitar o Servidor Websocket"
|
||||||
OBSWebsocket.Settings.ServerPort="Porta do Servidor"
|
OBSWebsocket.Settings.ServerPort="Porta do Servidor"
|
||||||
OBSWebsocket.Settings.AuthRequired="Autenticação Requerida"
|
OBSWebsocket.Settings.AuthRequired="Autenticação Requerida"
|
||||||
|
14
data/locale/pt-PT.ini
Normal file
14
data/locale/pt-PT.ini
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
OBSWebsocket.Menu.SettingsItem="Configurações do servidor Websocket"
|
||||||
|
OBSWebsocket.Settings.DialogTitle="obs-websocket"
|
||||||
|
OBSWebsocket.Settings.ServerEnable="Habilitar servidor de WebSockets"
|
||||||
|
OBSWebsocket.Settings.ServerPort="Porta do Servidor"
|
||||||
|
OBSWebsocket.Settings.AuthRequired="Activar autenticação"
|
||||||
|
OBSWebsocket.Settings.Password="Palavra passe"
|
||||||
|
OBSWebsocket.Settings.DebugEnable="Habilitar registro de debug"
|
||||||
|
OBSWebsocket.Settings.AlertsEnable="Ativar Alertas da bandeja do sistema"
|
||||||
|
OBSWebsocket.NotifyConnect.Title="Nova conexão WebSocket"
|
||||||
|
OBSWebsocket.NotifyConnect.Message="Cliente %1 conectado"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Title="WebSocket cliente desconectado"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Message="Cliente %1 desconectado"
|
||||||
|
OBSWebsocket.Server.StartFailed.Title="Falha do servidor de WebSocket"
|
||||||
|
OBSWebsocket.Server.StartFailed.Message="O servidor obs-websocket falhou ao iniciar, talvez porque: \n - TCP port %1 pode estar atualmente em uso em outro lugar sobre este sistema, possivelmente por outro aplicativo. Tente definir uma porta TCP diferente nas configurações do servidor de WebSocket, ou parar qualquer aplicativo que poderia estar usando este porto \n - um erro de rede desconhecido aconteceu no seu sistema. Tente novamente alterar configurações, reiniciando OBS ou reiniciando o sistema."
|
14
data/locale/ru-RU.ini
Normal file
14
data/locale/ru-RU.ini
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
OBSWebsocket.Menu.SettingsItem="Параметры сервера Websocket"
|
||||||
|
OBSWebsocket.Settings.DialogTitle="obs-websocket"
|
||||||
|
OBSWebsocket.Settings.ServerEnable="Включить сервер Websocket"
|
||||||
|
OBSWebsocket.Settings.ServerPort="Порт сервера"
|
||||||
|
OBSWebsocket.Settings.AuthRequired="Включить аутентификацию"
|
||||||
|
OBSWebsocket.Settings.Password="Пароль"
|
||||||
|
OBSWebsocket.Settings.DebugEnable="Включить ведение журнала отладки"
|
||||||
|
OBSWebsocket.Settings.AlertsEnable="Включить оповещения в системном трее"
|
||||||
|
OBSWebsocket.NotifyConnect.Title="Новое соединение WebSocket"
|
||||||
|
OBSWebsocket.NotifyConnect.Message="Клиент %1 подключен"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Title="Клиент WebSocket отключён"
|
||||||
|
OBSWebsocket.NotifyDisconnect.Message="Клиент %1 отключен"
|
||||||
|
OBSWebsocket.Server.StartFailed.Title="Сбой сервера WebSocket"
|
||||||
|
OBSWebsocket.Server.StartFailed.Message="Сбой запуска сервера obs-websocket. Вероятные причины:\n - Возможно, TCP-порт %1 занят другим приложением в системе. Попробуйте задать другой TCP-порт в настройках сервера WebSocket или закройте приложение, которое может использовать данный порт.\n - Произошла неизвестная сетевая ошибка в системе. Попробуйте снова после изменения настроек, перезапуска OBS или перезапуска системы."
|
@ -3,4 +3,4 @@ OBSWebsocket.Settings.DialogTitle="obs-websocket 设置"
|
|||||||
OBSWebsocket.Settings.ServerEnable="启用 Websocket 服务器"
|
OBSWebsocket.Settings.ServerEnable="启用 Websocket 服务器"
|
||||||
OBSWebsocket.Settings.ServerPort="服务器端口"
|
OBSWebsocket.Settings.ServerPort="服务器端口"
|
||||||
OBSWebsocket.Settings.AuthRequired="启用密码认证"
|
OBSWebsocket.Settings.AuthRequired="启用密码认证"
|
||||||
OBSWebsocket.Settings.Password="密码"
|
OBSWebsocket.Settings.Password="密码"
|
||||||
|
@ -3,4 +3,4 @@ OBSWebsocket.Settings.DialogTitle="obs-websocket 設定"
|
|||||||
OBSWebsocket.Settings.ServerEnable="啟用 Websocket 伺服器"
|
OBSWebsocket.Settings.ServerEnable="啟用 Websocket 伺服器"
|
||||||
OBSWebsocket.Settings.ServerPort="伺服器端口"
|
OBSWebsocket.Settings.ServerPort="伺服器端口"
|
||||||
OBSWebsocket.Settings.AuthRequired="啟用密碼認證"
|
OBSWebsocket.Settings.AuthRequired="啟用密碼認證"
|
||||||
OBSWebsocket.Settings.Password="密碼"
|
OBSWebsocket.Settings.Password="密碼"
|
||||||
|
1
deps/mbedtls
vendored
1
deps/mbedtls
vendored
Submodule deps/mbedtls deleted from 1a6a15c795
@ -1,6 +1,8 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
const parseComments = require('parse-comments');
|
const parseComments = require('parse-comments');
|
||||||
|
const config = require('./config.json');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read each file and call `parse-comments` on it.
|
* Read each file and call `parse-comments` on it.
|
||||||
@ -25,9 +27,23 @@ const parseFiles = files => {
|
|||||||
*/
|
*/
|
||||||
const processComments = comments => {
|
const processComments = comments => {
|
||||||
let sorted = {};
|
let sorted = {};
|
||||||
|
let errors = [];
|
||||||
|
|
||||||
comments.forEach(comment => {
|
comments.forEach(comment => {
|
||||||
|
if (comment.typedef) {
|
||||||
|
comment.comment = undefined;
|
||||||
|
comment.context = undefined;
|
||||||
|
sorted['typedefs'] = sorted['typedefs'] || [];
|
||||||
|
sorted['typedefs'].push(comment);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof comment.api === 'undefined') return;
|
if (typeof comment.api === 'undefined') return;
|
||||||
|
let validationFailures = validateComment(comment);
|
||||||
|
|
||||||
|
if (validationFailures) {
|
||||||
|
errors.push(validationFailures);
|
||||||
|
}
|
||||||
|
|
||||||
// Store the object based on its api (ie. requests, events) and category (ie. general, scenes, etc).
|
// Store the object based on its api (ie. requests, events) and category (ie. general, scenes, etc).
|
||||||
comment.category = comment.category || 'miscellaneous';
|
comment.category = comment.category || 'miscellaneous';
|
||||||
@ -44,9 +60,45 @@ const processComments = comments => {
|
|||||||
sorted[comment.api][comment.category].push(comment);
|
sorted[comment.api][comment.category].push(comment);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (errors.length) {
|
||||||
|
throw JSON.stringify(errors, null, 2);
|
||||||
|
}
|
||||||
|
|
||||||
return sorted;
|
return sorted;
|
||||||
};
|
};
|
||||||
|
|
||||||
const files = glob.sync("./../*.@(cpp|h)");
|
// Rudimentary validation of documentation content, returns an error object or undefined.
|
||||||
|
const validateComment = comment => {
|
||||||
|
let errors = [];
|
||||||
|
[].concat(comment.params).concat(comment.returns).filter(Boolean).forEach(param => {
|
||||||
|
if (typeof param.name !== 'string' || param.name === '') {
|
||||||
|
errors.push({
|
||||||
|
description: `Invalid param or return value name`,
|
||||||
|
param: param
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof param.type !== 'string' || param.type === '') {
|
||||||
|
errors.push({
|
||||||
|
description: `Invalid param or return value type`,
|
||||||
|
param: param
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (errors.length) {
|
||||||
|
return {
|
||||||
|
errors: errors,
|
||||||
|
fullContext: Object.assign({}, comment)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const files = glob.sync(config.srcGlob);
|
||||||
const comments = processComments(parseFiles(files));
|
const comments = processComments(parseFiles(files));
|
||||||
fs.writeFileSync('./generated/comments.json', JSON.stringify(comments, null, 2));
|
|
||||||
|
if (!fs.existsSync(config.outDirectory)){
|
||||||
|
fs.mkdirSync(config.outDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(path.join(config.outDirectory, 'comments.json'), JSON.stringify(comments, null, 2));
|
||||||
|
5
docs/config.json
Normal file
5
docs/config.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"srcGlob": "./../src/**/*.@(cpp|h)",
|
||||||
|
"srcTemplate": "./protocol.hbs",
|
||||||
|
"outDirectory": "./generated"
|
||||||
|
}
|
16
docs/docs.js
16
docs/docs.js
@ -1,14 +1,16 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
const toc = require('markdown-toc');
|
const toc = require('markdown-toc');
|
||||||
const handlebars = require('handlebars');
|
const handlebars = require('handlebars');
|
||||||
|
const config = require('./config.json');
|
||||||
|
|
||||||
const helpers = require('handlebars-helpers')({
|
const helpers = require('handlebars-helpers')({
|
||||||
handlebars: handlebars
|
handlebars: handlebars
|
||||||
});
|
});
|
||||||
|
|
||||||
// Allows pipe characters to be used within markdown tables.
|
// Allows pipe characters to be used within markdown tables.
|
||||||
handlebars.registerHelper('depipe', (text) => {
|
handlebars.registerHelper('depipe', (text) => {
|
||||||
return text.replace('|', `\\|`);
|
return typeof text === 'string' ? text.replace('|', '\\|') : text;
|
||||||
});
|
});
|
||||||
|
|
||||||
const insertHeader = (text) => {
|
const insertHeader = (text) => {
|
||||||
@ -26,6 +28,10 @@ const generateProtocol = (templatePath, data) => {
|
|||||||
return insertHeader(toc.insert(generated));
|
return insertHeader(toc.insert(generated));
|
||||||
};
|
};
|
||||||
|
|
||||||
const comments = fs.readFileSync('./generated/comments.json', 'utf8');
|
if (!fs.existsSync(config.outDirectory)){
|
||||||
const markdown = generateProtocol('./protocol.hbs', JSON.parse(comments));
|
fs.mkdirSync(config.outDirectory);
|
||||||
fs.writeFileSync('./generated/protocol.md', markdown);
|
}
|
||||||
|
|
||||||
|
const comments = fs.readFileSync(path.join(config.outDirectory, 'comments.json'), 'utf8');
|
||||||
|
const markdown = generateProtocol(config.srcTemplate, JSON.parse(comments));
|
||||||
|
fs.writeFileSync(path.join(config.outDirectory, 'protocol.md'), markdown);
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,16 +1,11 @@
|
|||||||
# obs-websocket 4.2.0 protocol reference
|
# obs-websocket 4.5.0 protocol reference
|
||||||
|
|
||||||
**This is the reference for obs-websocket 4.2.0. See the list below for older versions.**
|
|
||||||
- [4.1.0 protocol reference](https://github.com/Palakis/obs-websocket/blob/4.1.0/PROTOCOL.md)
|
|
||||||
- [4.0.0 protocol reference](https://github.com/Palakis/obs-websocket/blob/4.0.0/PROTOCOL.md)
|
|
||||||
|
|
||||||
# General Introduction
|
# General Introduction
|
||||||
Messages are exchanged between the client and the server as JSON objects.
|
Messages are exchanged between the client and the server as JSON objects.
|
||||||
This protocol is based on the original OBS Remote protocol created by Bill Hamilton, with new commands specific to OBS Studio.
|
This protocol is based on the original OBS Remote protocol created by Bill Hamilton, with new commands specific to OBS Studio.
|
||||||
|
|
||||||
|
|
||||||
# Authentication
|
# Authentication
|
||||||
OBSWebSocket uses SHA256 to transmit credentials.
|
`obs-websocket` uses SHA256 to transmit credentials.
|
||||||
|
|
||||||
A request for [`GetAuthRequired`](#getauthrequired) returns two elements:
|
A request for [`GetAuthRequired`](#getauthrequired) returns two elements:
|
||||||
- A `challenge`: a random string that will be used to generate the auth response.
|
- A `challenge`: a random string that will be used to generate the auth response.
|
||||||
|
2
docs/partials/typedefsHeader.md
Normal file
2
docs/partials/typedefsHeader.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Typedefs
|
||||||
|
These are complex types, such as `Source` and `Scene`, which are used as arguments or return values in multiple requests and/or events.
|
@ -7,6 +7,19 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{{#read "partials/typedefsHeader.md"}}{{/read}}
|
||||||
|
|
||||||
|
{{#each typedefs}}
|
||||||
|
## {{typedefs.0.name}}
|
||||||
|
| Name | Type | Description |
|
||||||
|
| ---- | :---: | ------------|
|
||||||
|
{{#each properties}}
|
||||||
|
| `{{name}}` | _{{depipe type}}_ | {{{depipe description}}} |
|
||||||
|
{{/each}}
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{{#read "partials/eventsHeader.md"}}{{/read}}
|
{{#read "partials/eventsHeader.md"}}{{/read}}
|
||||||
|
|
||||||
{{#each events}}
|
{{#each events}}
|
||||||
@ -15,6 +28,10 @@
|
|||||||
{{#each this}}
|
{{#each this}}
|
||||||
### {{name}}
|
### {{name}}
|
||||||
|
|
||||||
|
{{#if deprecated}}
|
||||||
|
- **⚠️ Deprecated. {{deprecated}} ⚠️**
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{#eq since "unreleased"}}
|
{{#eq since "unreleased"}}
|
||||||
- Unreleased
|
- Unreleased
|
||||||
{{else}}
|
{{else}}
|
||||||
@ -29,7 +46,7 @@
|
|||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | :---: | ------------|
|
| ---- | :---: | ------------|
|
||||||
{{#each returns}}
|
{{#each returns}}
|
||||||
| `{{name}}` | _{{depipe type}}_ | {{{description}}} |
|
| `{{name}}` | _{{depipe type}}_ | {{{depipe description}}} |
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
{{else}}
|
{{else}}
|
||||||
@ -51,6 +68,10 @@ _No additional response items._
|
|||||||
{{#each this}}
|
{{#each this}}
|
||||||
### {{name}}
|
### {{name}}
|
||||||
|
|
||||||
|
{{#if deprecated}}
|
||||||
|
- **⚠️ Deprecated. {{deprecated}} ⚠️**
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{#eq since "unreleased"}}
|
{{#eq since "unreleased"}}
|
||||||
- Unreleased
|
- Unreleased
|
||||||
{{else}}
|
{{else}}
|
||||||
@ -65,7 +86,7 @@ _No additional response items._
|
|||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | :---: | ------------|
|
| ---- | :---: | ------------|
|
||||||
{{#each params}}
|
{{#each params}}
|
||||||
| `{{name}}` | _{{depipe type}}_ | {{{description}}} |
|
| `{{name}}` | _{{depipe type}}_ | {{{depipe description}}} |
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
{{else}}
|
{{else}}
|
||||||
@ -78,7 +99,7 @@ _No specified parameters._
|
|||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ---- | :---: | ------------|
|
| ---- | :---: | ------------|
|
||||||
{{#each returns}}
|
{{#each returns}}
|
||||||
| `{{name}}` | _{{depipe type}}_ | {{{description}}} |
|
| `{{name}}` | _{{depipe type}}_ | {{{depipe description}}} |
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
{{else}}
|
{{else}}
|
||||||
@ -89,4 +110,3 @@ _No additional response items._
|
|||||||
|
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
|
@ -1,113 +0,0 @@
|
|||||||
/*
|
|
||||||
obs-websocket
|
|
||||||
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <obs-frontend-api.h>
|
|
||||||
|
|
||||||
#include "obs-websocket.h"
|
|
||||||
#include "Config.h"
|
|
||||||
#include "WSServer.h"
|
|
||||||
#include "settings-dialog.h"
|
|
||||||
#include "ui_settings-dialog.h"
|
|
||||||
|
|
||||||
#define CHANGE_ME "changeme"
|
|
||||||
|
|
||||||
SettingsDialog::SettingsDialog(QWidget* parent) :
|
|
||||||
QDialog(parent, Qt::Dialog),
|
|
||||||
ui(new Ui::SettingsDialog)
|
|
||||||
{
|
|
||||||
ui->setupUi(this);
|
|
||||||
|
|
||||||
connect(ui->authRequired, &QCheckBox::stateChanged,
|
|
||||||
this, &SettingsDialog::AuthCheckboxChanged);
|
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::accepted,
|
|
||||||
this, &SettingsDialog::FormAccepted);
|
|
||||||
|
|
||||||
|
|
||||||
AuthCheckboxChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsDialog::showEvent(QShowEvent* event)
|
|
||||||
{
|
|
||||||
Config* conf = Config::Current();
|
|
||||||
|
|
||||||
ui->serverEnabled->setChecked(conf->ServerEnabled);
|
|
||||||
ui->serverPort->setValue(conf->ServerPort);
|
|
||||||
|
|
||||||
ui->debugEnabled->setChecked(conf->DebugEnabled);
|
|
||||||
|
|
||||||
ui->authRequired->setChecked(conf->AuthRequired);
|
|
||||||
ui->password->setText(CHANGE_ME);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsDialog::ToggleShowHide()
|
|
||||||
{
|
|
||||||
if (!isVisible())
|
|
||||||
setVisible(true);
|
|
||||||
else
|
|
||||||
setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsDialog::AuthCheckboxChanged()
|
|
||||||
{
|
|
||||||
if (ui->authRequired->isChecked())
|
|
||||||
ui->password->setEnabled(true);
|
|
||||||
else
|
|
||||||
ui->password->setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsDialog::FormAccepted()
|
|
||||||
{
|
|
||||||
Config* conf = Config::Current();
|
|
||||||
|
|
||||||
conf->ServerEnabled = ui->serverEnabled->isChecked();
|
|
||||||
conf->ServerPort = ui->serverPort->value();
|
|
||||||
|
|
||||||
conf->DebugEnabled = ui->debugEnabled->isChecked();
|
|
||||||
|
|
||||||
if (ui->authRequired->isChecked())
|
|
||||||
{
|
|
||||||
if (ui->password->text() != CHANGE_ME)
|
|
||||||
{
|
|
||||||
QByteArray pwd = ui->password->text().toUtf8();
|
|
||||||
const char *new_password = pwd;
|
|
||||||
|
|
||||||
conf->SetPassword(new_password);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(Config::Current()->Secret, "") != 0)
|
|
||||||
conf->AuthRequired = true;
|
|
||||||
else
|
|
||||||
conf->AuthRequired = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
conf->AuthRequired = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
conf->Save();
|
|
||||||
|
|
||||||
if (conf->ServerEnabled)
|
|
||||||
WSServer::Instance->Start(conf->ServerPort);
|
|
||||||
else
|
|
||||||
WSServer::Instance->Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
SettingsDialog::~SettingsDialog()
|
|
||||||
{
|
|
||||||
delete ui;
|
|
||||||
}
|
|
@ -1,141 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>SettingsDialog</class>
|
|
||||||
<widget class="QDialog" name="SettingsDialog">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>407</width>
|
|
||||||
<height>175</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>OBSWebsocket.Settings.DialogTitle</string>
|
|
||||||
</property>
|
|
||||||
<property name="sizeGripEnabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
|
||||||
<property name="sizeConstraint">
|
|
||||||
<enum>QLayout::SetDefaultConstraint</enum>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<layout class="QFormLayout" name="formLayout">
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QCheckBox" name="authRequired">
|
|
||||||
<property name="text">
|
|
||||||
<string>OBSWebsocket.Settings.AuthRequired</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0">
|
|
||||||
<widget class="QLabel" name="lbl_password">
|
|
||||||
<property name="text">
|
|
||||||
<string>OBSWebsocket.Settings.Password</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1">
|
|
||||||
<widget class="QLineEdit" name="password">
|
|
||||||
<property name="echoMode">
|
|
||||||
<enum>QLineEdit::Password</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QCheckBox" name="serverEnabled">
|
|
||||||
<property name="text">
|
|
||||||
<string>OBSWebsocket.Settings.ServerEnable</string>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="lbl_serverPort">
|
|
||||||
<property name="text">
|
|
||||||
<string>OBSWebsocket.Settings.ServerPort</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QSpinBox" name="serverPort">
|
|
||||||
<property name="minimum">
|
|
||||||
<number>1024</number>
|
|
||||||
</property>
|
|
||||||
<property name="maximum">
|
|
||||||
<number>65535</number>
|
|
||||||
</property>
|
|
||||||
<property name="value">
|
|
||||||
<number>4444</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="1">
|
|
||||||
<widget class="QCheckBox" name="debugEnabled">
|
|
||||||
<property name="text">
|
|
||||||
<string>OBSWebsocket.Settings.DebugEnable</string>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="standardButtons">
|
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<resources/>
|
|
||||||
<connections>
|
|
||||||
<connection>
|
|
||||||
<sender>buttonBox</sender>
|
|
||||||
<signal>accepted()</signal>
|
|
||||||
<receiver>SettingsDialog</receiver>
|
|
||||||
<slot>accept()</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>248</x>
|
|
||||||
<y>274</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>157</x>
|
|
||||||
<y>294</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
|
||||||
<sender>buttonBox</sender>
|
|
||||||
<signal>rejected()</signal>
|
|
||||||
<receiver>SettingsDialog</receiver>
|
|
||||||
<slot>reject()</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>316</x>
|
|
||||||
<y>280</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>286</x>
|
|
||||||
<y>294</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
</connections>
|
|
||||||
</ui>
|
|
@ -2,8 +2,8 @@
|
|||||||
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
|
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
|
||||||
|
|
||||||
#define MyAppName "obs-websocket"
|
#define MyAppName "obs-websocket"
|
||||||
#define MyAppVersion "4.2.0"
|
#define MyAppVersion "4.5.1"
|
||||||
#define MyAppPublisher "St<EFBFBD>phane Lepin"
|
#define MyAppPublisher "Stephane Lepin"
|
||||||
#define MyAppURL "http://github.com/Palakis/obs-websocket"
|
#define MyAppURL "http://github.com/Palakis/obs-websocket"
|
||||||
|
|
||||||
[Setup]
|
[Setup]
|
||||||
@ -20,7 +20,7 @@ AppSupportURL={#MyAppURL}
|
|||||||
AppUpdatesURL={#MyAppURL}
|
AppUpdatesURL={#MyAppURL}
|
||||||
DefaultDirName={code:GetDirName}
|
DefaultDirName={code:GetDirName}
|
||||||
DefaultGroupName={#MyAppName}
|
DefaultGroupName={#MyAppName}
|
||||||
OutputBaseFilename=obs-websocket-{#MyAppVersion}-Windows-Installer
|
OutputBaseFilename=obs-websocket-Windows-Installer
|
||||||
Compression=lzma
|
Compression=lzma
|
||||||
SolidCompression=yes
|
SolidCompression=yes
|
||||||
LicenseFile=..\LICENSE
|
LicenseFile=..\LICENSE
|
||||||
@ -42,13 +42,13 @@ Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
|
|||||||
// following function come from https://github.com/Xaymar/obs-studio_amf-encoder-plugin/blob/master/%23Resources/Installer.in.iss#L45
|
// following function come from https://github.com/Xaymar/obs-studio_amf-encoder-plugin/blob/master/%23Resources/Installer.in.iss#L45
|
||||||
function GetDirName(Value: string): string;
|
function GetDirName(Value: string): string;
|
||||||
var
|
var
|
||||||
InstallPath: string;
|
InstallPath: string;
|
||||||
begin
|
begin
|
||||||
// initialize default path, which will be returned when the following registry
|
// initialize default path, which will be returned when the following registry
|
||||||
// key queries fail due to missing keys or for some different reason
|
// key queries fail due to missing keys or for some different reason
|
||||||
Result := '{pf}\obs-studio';
|
Result := '{pf}\obs-studio';
|
||||||
// query the first registry value; if this succeeds, return the obtained value
|
// query the first registry value; if this succeeds, return the obtained value
|
||||||
if RegQueryStringValue(HKLM32, 'SOFTWARE\OBS Studio', '', InstallPath) then
|
if RegQueryStringValue(HKLM32, 'SOFTWARE\OBS Studio', '', InstallPath) then
|
||||||
Result := InstallPath
|
Result := InstallPath
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
obs-websocket
|
|
||||||
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <obs-module.h>
|
|
||||||
#include <obs-frontend-api.h>
|
|
||||||
#include <QAction>
|
|
||||||
#include <QMainWindow>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "obs-websocket.h"
|
|
||||||
#include "WSServer.h"
|
|
||||||
#include "WSEvents.h"
|
|
||||||
#include "Config.h"
|
|
||||||
#include "forms/settings-dialog.h"
|
|
||||||
|
|
||||||
OBS_DECLARE_MODULE()
|
|
||||||
OBS_MODULE_USE_DEFAULT_LOCALE("obs-websocket", "en-US")
|
|
||||||
|
|
||||||
SettingsDialog* settings_dialog;
|
|
||||||
|
|
||||||
bool obs_module_load(void) {
|
|
||||||
blog(LOG_INFO, "you can haz websockets (version %s)", OBS_WEBSOCKET_VERSION);
|
|
||||||
blog(LOG_INFO, "qt version (compile-time): %s ; qt version (run-time): %s",
|
|
||||||
QT_VERSION_STR, qVersion());
|
|
||||||
|
|
||||||
// Core setup
|
|
||||||
Config* config = Config::Current();
|
|
||||||
config->Load();
|
|
||||||
|
|
||||||
WSServer::Instance = new WSServer();
|
|
||||||
WSEvents::Instance = new WSEvents(WSServer::Instance);
|
|
||||||
|
|
||||||
if (config->ServerEnabled)
|
|
||||||
WSServer::Instance->Start(config->ServerPort);
|
|
||||||
|
|
||||||
// UI setup
|
|
||||||
QAction* menu_action = (QAction*)obs_frontend_add_tools_menu_qaction(
|
|
||||||
obs_module_text("OBSWebsocket.Menu.SettingsItem"));
|
|
||||||
|
|
||||||
obs_frontend_push_ui_translation(obs_module_get_string);
|
|
||||||
QMainWindow* main_window = (QMainWindow*)obs_frontend_get_main_window();
|
|
||||||
settings_dialog = new SettingsDialog(main_window);
|
|
||||||
obs_frontend_pop_ui_translation();
|
|
||||||
|
|
||||||
auto menu_cb = [] {
|
|
||||||
settings_dialog->ToggleShowHide();
|
|
||||||
};
|
|
||||||
menu_action->connect(menu_action, &QAction::triggered, menu_cb);
|
|
||||||
|
|
||||||
// Loading finished
|
|
||||||
blog(LOG_INFO, "module loaded!");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void obs_module_unload() {
|
|
||||||
blog(LOG_INFO, "goodbye!");
|
|
||||||
}
|
|
||||||
|
|
186
src/Config.cpp
Normal file
186
src/Config.cpp
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
/*
|
||||||
|
obs-websocket
|
||||||
|
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <obs-frontend-api.h>
|
||||||
|
#include <util/config-file.h>
|
||||||
|
|
||||||
|
#include <QCryptographicHash>
|
||||||
|
#include <QTime>
|
||||||
|
|
||||||
|
#define SECTION_NAME "WebsocketAPI"
|
||||||
|
#define PARAM_ENABLE "ServerEnabled"
|
||||||
|
#define PARAM_PORT "ServerPort"
|
||||||
|
#define PARAM_DEBUG "DebugEnabled"
|
||||||
|
#define PARAM_ALERT "AlertsEnabled"
|
||||||
|
#define PARAM_AUTHREQUIRED "AuthRequired"
|
||||||
|
#define PARAM_SECRET "AuthSecret"
|
||||||
|
#define PARAM_SALT "AuthSalt"
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#define QT_TO_UTF8(str) str.toUtf8().constData()
|
||||||
|
|
||||||
|
Config* Config::_instance = new Config();
|
||||||
|
|
||||||
|
Config::Config() :
|
||||||
|
ServerEnabled(true),
|
||||||
|
ServerPort(4444),
|
||||||
|
DebugEnabled(false),
|
||||||
|
AlertsEnabled(true),
|
||||||
|
AuthRequired(false),
|
||||||
|
Secret(""),
|
||||||
|
Salt(""),
|
||||||
|
SettingsLoaded(false)
|
||||||
|
{
|
||||||
|
qsrand(QTime::currentTime().msec());
|
||||||
|
|
||||||
|
// OBS Config defaults
|
||||||
|
config_t* obsConfig = obs_frontend_get_global_config();
|
||||||
|
if (obsConfig) {
|
||||||
|
config_set_default_bool(obsConfig,
|
||||||
|
SECTION_NAME, PARAM_ENABLE, ServerEnabled);
|
||||||
|
config_set_default_uint(obsConfig,
|
||||||
|
SECTION_NAME, PARAM_PORT, ServerPort);
|
||||||
|
|
||||||
|
config_set_default_bool(obsConfig,
|
||||||
|
SECTION_NAME, PARAM_DEBUG, DebugEnabled);
|
||||||
|
config_set_default_bool(obsConfig,
|
||||||
|
SECTION_NAME, PARAM_ALERT, AlertsEnabled);
|
||||||
|
|
||||||
|
config_set_default_bool(obsConfig,
|
||||||
|
SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired);
|
||||||
|
config_set_default_string(obsConfig,
|
||||||
|
SECTION_NAME, PARAM_SECRET, QT_TO_UTF8(Secret));
|
||||||
|
config_set_default_string(obsConfig,
|
||||||
|
SECTION_NAME, PARAM_SALT, QT_TO_UTF8(Salt));
|
||||||
|
}
|
||||||
|
|
||||||
|
SessionChallenge = GenerateSalt();
|
||||||
|
}
|
||||||
|
|
||||||
|
Config::~Config()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::Load()
|
||||||
|
{
|
||||||
|
config_t* obsConfig = obs_frontend_get_global_config();
|
||||||
|
|
||||||
|
ServerEnabled = config_get_bool(obsConfig, SECTION_NAME, PARAM_ENABLE);
|
||||||
|
ServerPort = config_get_uint(obsConfig, SECTION_NAME, PARAM_PORT);
|
||||||
|
|
||||||
|
DebugEnabled = config_get_bool(obsConfig, SECTION_NAME, PARAM_DEBUG);
|
||||||
|
AlertsEnabled = config_get_bool(obsConfig, SECTION_NAME, PARAM_ALERT);
|
||||||
|
|
||||||
|
AuthRequired = config_get_bool(obsConfig, SECTION_NAME, PARAM_AUTHREQUIRED);
|
||||||
|
Secret = config_get_string(obsConfig, SECTION_NAME, PARAM_SECRET);
|
||||||
|
Salt = config_get_string(obsConfig, SECTION_NAME, PARAM_SALT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::Save()
|
||||||
|
{
|
||||||
|
config_t* obsConfig = obs_frontend_get_global_config();
|
||||||
|
|
||||||
|
config_set_bool(obsConfig, SECTION_NAME, PARAM_ENABLE, ServerEnabled);
|
||||||
|
config_set_uint(obsConfig, SECTION_NAME, PARAM_PORT, ServerPort);
|
||||||
|
|
||||||
|
config_set_bool(obsConfig, SECTION_NAME, PARAM_DEBUG, DebugEnabled);
|
||||||
|
config_set_bool(obsConfig, SECTION_NAME, PARAM_ALERT, AlertsEnabled);
|
||||||
|
|
||||||
|
config_set_bool(obsConfig, SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired);
|
||||||
|
config_set_string(obsConfig, SECTION_NAME, PARAM_SECRET,
|
||||||
|
QT_TO_UTF8(Secret));
|
||||||
|
config_set_string(obsConfig, SECTION_NAME, PARAM_SALT,
|
||||||
|
QT_TO_UTF8(Salt));
|
||||||
|
|
||||||
|
config_save(obsConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Config::GenerateSalt()
|
||||||
|
{
|
||||||
|
// Generate 32 random chars
|
||||||
|
const size_t randomCount = 32;
|
||||||
|
QByteArray randomChars;
|
||||||
|
for (size_t i = 0; i < randomCount; i++) {
|
||||||
|
randomChars.append((char)qrand());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the 32 random chars to a base64 string
|
||||||
|
QString salt = randomChars.toBase64();
|
||||||
|
|
||||||
|
return salt;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Config::GenerateSecret(QString password, QString salt)
|
||||||
|
{
|
||||||
|
// Concatenate the password and the salt
|
||||||
|
QString passAndSalt = "";
|
||||||
|
passAndSalt += password;
|
||||||
|
passAndSalt += salt;
|
||||||
|
|
||||||
|
// Generate a SHA256 hash of the password and salt
|
||||||
|
auto challengeHash = QCryptographicHash::hash(
|
||||||
|
passAndSalt.toUtf8(),
|
||||||
|
QCryptographicHash::Algorithm::Sha256
|
||||||
|
);
|
||||||
|
|
||||||
|
// Encode SHA256 hash to Base64
|
||||||
|
QString challenge = challengeHash.toBase64();
|
||||||
|
|
||||||
|
return challenge;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::SetPassword(QString password)
|
||||||
|
{
|
||||||
|
QString newSalt = GenerateSalt();
|
||||||
|
QString newChallenge = GenerateSecret(password, newSalt);
|
||||||
|
|
||||||
|
this->Salt = newSalt;
|
||||||
|
this->Secret = newChallenge;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::CheckAuth(QString response)
|
||||||
|
{
|
||||||
|
// Concatenate auth secret with the challenge sent to the user
|
||||||
|
QString challengeAndResponse = "";
|
||||||
|
challengeAndResponse += Secret;
|
||||||
|
challengeAndResponse += SessionChallenge;
|
||||||
|
|
||||||
|
// Generate a SHA256 hash of challengeAndResponse
|
||||||
|
auto hash = QCryptographicHash::hash(
|
||||||
|
challengeAndResponse.toUtf8(),
|
||||||
|
QCryptographicHash::Algorithm::Sha256
|
||||||
|
);
|
||||||
|
|
||||||
|
// Encode the SHA256 hash to Base64
|
||||||
|
QString expectedResponse = hash.toBase64();
|
||||||
|
|
||||||
|
bool authSuccess = false;
|
||||||
|
if (response == expectedResponse) {
|
||||||
|
SessionChallenge = GenerateSalt();
|
||||||
|
authSuccess = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return authSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
Config* Config::Current()
|
||||||
|
{
|
||||||
|
return _instance;
|
||||||
|
}
|
@ -16,12 +16,40 @@ You should have received a copy of the GNU General Public License along
|
|||||||
with this program. If not, see <https://www.gnu.org/licenses/>
|
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OBSWEBSOCKET_H
|
#ifndef CONFIG_H
|
||||||
#define OBSWEBSOCKET_H
|
#define CONFIG_H
|
||||||
|
|
||||||
#define PROP_AUTHENTICATED "wsclient_authenticated"
|
#include <QString>
|
||||||
#define OBS_WEBSOCKET_VERSION "4.2.0"
|
|
||||||
|
|
||||||
#define blog(level, msg, ...) blog(level, "[obs-websocket] " msg, ##__VA_ARGS__)
|
class Config {
|
||||||
|
public:
|
||||||
|
Config();
|
||||||
|
~Config();
|
||||||
|
void Load();
|
||||||
|
void Save();
|
||||||
|
|
||||||
#endif // OBSWEBSOCKET_H
|
void SetPassword(QString password);
|
||||||
|
bool CheckAuth(QString userChallenge);
|
||||||
|
QString GenerateSalt();
|
||||||
|
static QString GenerateSecret(
|
||||||
|
QString password, QString salt);
|
||||||
|
|
||||||
|
bool ServerEnabled;
|
||||||
|
uint64_t ServerPort;
|
||||||
|
|
||||||
|
bool DebugEnabled;
|
||||||
|
bool AlertsEnabled;
|
||||||
|
|
||||||
|
bool AuthRequired;
|
||||||
|
QString Secret;
|
||||||
|
QString Salt;
|
||||||
|
QString SessionChallenge;
|
||||||
|
bool SettingsLoaded;
|
||||||
|
|
||||||
|
static Config* Current();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static Config* _instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONFIG_H
|
564
src/Utils.cpp
Normal file
564
src/Utils.cpp
Normal file
@ -0,0 +1,564 @@
|
|||||||
|
/*
|
||||||
|
obs-websocket
|
||||||
|
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <obs-frontend-api.h>
|
||||||
|
#include <obs.hpp>
|
||||||
|
#include "obs-websocket.h"
|
||||||
|
|
||||||
|
#include "Utils.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(OBSScene);
|
||||||
|
|
||||||
|
obs_data_array_t* Utils::StringListToArray(char** strings, char* key) {
|
||||||
|
if (!strings)
|
||||||
|
return obs_data_array_create();
|
||||||
|
|
||||||
|
obs_data_array_t* list = obs_data_array_create();
|
||||||
|
|
||||||
|
char* value = "";
|
||||||
|
for (int i = 0; value != nullptr; i++) {
|
||||||
|
value = strings[i];
|
||||||
|
|
||||||
|
OBSDataAutoRelease item = obs_data_create();
|
||||||
|
obs_data_set_string(item, key, value);
|
||||||
|
|
||||||
|
if (value)
|
||||||
|
obs_data_array_push_back(list, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_array_t* Utils::GetSceneItems(obs_source_t* source) {
|
||||||
|
obs_data_array_t* items = obs_data_array_create();
|
||||||
|
OBSScene scene = obs_scene_from_source(source);
|
||||||
|
|
||||||
|
if (!scene)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
obs_scene_enum_items(scene, [](
|
||||||
|
obs_scene_t* scene,
|
||||||
|
obs_sceneitem_t* currentItem,
|
||||||
|
void* param)
|
||||||
|
{
|
||||||
|
obs_data_array_t* data = static_cast<obs_data_array_t*>(param);
|
||||||
|
|
||||||
|
OBSDataAutoRelease itemData = GetSceneItemData(currentItem);
|
||||||
|
obs_data_array_insert(data, 0, itemData);
|
||||||
|
return true;
|
||||||
|
}, items);
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_t* Utils::GetSceneItemData(obs_sceneitem_t* item) {
|
||||||
|
if (!item)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
vec2 pos;
|
||||||
|
obs_sceneitem_get_pos(item, &pos);
|
||||||
|
|
||||||
|
vec2 scale;
|
||||||
|
obs_sceneitem_get_scale(item, &scale);
|
||||||
|
|
||||||
|
// obs_sceneitem_get_source doesn't increase the refcount
|
||||||
|
OBSSource itemSource = obs_sceneitem_get_source(item);
|
||||||
|
float item_width = float(obs_source_get_width(itemSource));
|
||||||
|
float item_height = float(obs_source_get_height(itemSource));
|
||||||
|
|
||||||
|
obs_data_t* data = obs_data_create();
|
||||||
|
obs_data_set_string(data, "name",
|
||||||
|
obs_source_get_name(obs_sceneitem_get_source(item)));
|
||||||
|
obs_data_set_string(data, "type",
|
||||||
|
obs_source_get_id(obs_sceneitem_get_source(item)));
|
||||||
|
obs_data_set_double(data, "volume",
|
||||||
|
obs_source_get_volume(obs_sceneitem_get_source(item)));
|
||||||
|
obs_data_set_double(data, "x", pos.x);
|
||||||
|
obs_data_set_double(data, "y", pos.y);
|
||||||
|
obs_data_set_int(data, "source_cx", (int)item_width);
|
||||||
|
obs_data_set_int(data, "source_cy", (int)item_height);
|
||||||
|
obs_data_set_double(data, "cx", item_width* scale.x);
|
||||||
|
obs_data_set_double(data, "cy", item_height* scale.y);
|
||||||
|
obs_data_set_bool(data, "render", obs_sceneitem_visible(item));
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_sceneitem_t* Utils::GetSceneItemFromItem(obs_source_t* source, obs_data_t* item) {
|
||||||
|
OBSSceneItem sceneItem;
|
||||||
|
if (obs_data_has_user_value(item, "id")) {
|
||||||
|
sceneItem = GetSceneItemFromId(source, obs_data_get_int(item, "id"));
|
||||||
|
if (obs_data_has_user_value(item, "name") &&
|
||||||
|
(QString)obs_source_get_name(obs_sceneitem_get_source(sceneItem)) !=
|
||||||
|
(QString)obs_data_get_string(item, "name")) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (obs_data_has_user_value(item, "name")) {
|
||||||
|
sceneItem = GetSceneItemFromName(source, obs_data_get_string(item, "name"));
|
||||||
|
}
|
||||||
|
return sceneItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_sceneitem_t* Utils::GetSceneItemFromName(obs_source_t* source, QString name) {
|
||||||
|
struct current_search {
|
||||||
|
QString query;
|
||||||
|
obs_sceneitem_t* result;
|
||||||
|
};
|
||||||
|
|
||||||
|
current_search search;
|
||||||
|
search.query = name;
|
||||||
|
search.result = nullptr;
|
||||||
|
|
||||||
|
OBSScene scene = obs_scene_from_source(source);
|
||||||
|
if (!scene)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
obs_scene_enum_items(scene, [](
|
||||||
|
obs_scene_t* scene,
|
||||||
|
obs_sceneitem_t* currentItem,
|
||||||
|
void* param)
|
||||||
|
{
|
||||||
|
current_search* search = static_cast<current_search*>(param);
|
||||||
|
|
||||||
|
QString currentItemName =
|
||||||
|
obs_source_get_name(obs_sceneitem_get_source(currentItem));
|
||||||
|
|
||||||
|
if (currentItemName == search->query) {
|
||||||
|
search->result = currentItem;
|
||||||
|
obs_sceneitem_addref(search->result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}, &search);
|
||||||
|
|
||||||
|
return search.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_sceneitem_t* Utils::GetSceneItemFromId(obs_source_t* source, size_t id) {
|
||||||
|
struct current_search {
|
||||||
|
size_t query;
|
||||||
|
obs_sceneitem_t* result;
|
||||||
|
};
|
||||||
|
|
||||||
|
current_search search;
|
||||||
|
search.query = id;
|
||||||
|
search.result = nullptr;
|
||||||
|
|
||||||
|
OBSScene scene = obs_scene_from_source(source);
|
||||||
|
if (!scene)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
obs_scene_enum_items(scene, [](
|
||||||
|
obs_scene_t* scene,
|
||||||
|
obs_sceneitem_t* currentItem,
|
||||||
|
void* param)
|
||||||
|
{
|
||||||
|
current_search* search = static_cast<current_search*>(param);
|
||||||
|
|
||||||
|
if (obs_sceneitem_get_id(currentItem) == search->query) {
|
||||||
|
search->result = currentItem;
|
||||||
|
obs_sceneitem_addref(search->result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}, &search);
|
||||||
|
|
||||||
|
return search.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Utils::IsValidAlignment(const uint32_t alignment) {
|
||||||
|
switch (alignment) {
|
||||||
|
case OBS_ALIGN_CENTER:
|
||||||
|
case OBS_ALIGN_LEFT:
|
||||||
|
case OBS_ALIGN_RIGHT:
|
||||||
|
case OBS_ALIGN_TOP:
|
||||||
|
case OBS_ALIGN_BOTTOM:
|
||||||
|
case OBS_ALIGN_TOP | OBS_ALIGN_LEFT:
|
||||||
|
case OBS_ALIGN_TOP | OBS_ALIGN_RIGHT:
|
||||||
|
case OBS_ALIGN_BOTTOM | OBS_ALIGN_LEFT:
|
||||||
|
case OBS_ALIGN_BOTTOM | OBS_ALIGN_RIGHT: {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_source_t* Utils::GetTransitionFromName(QString searchName) {
|
||||||
|
obs_source_t* foundTransition = nullptr;
|
||||||
|
|
||||||
|
obs_frontend_source_list transition_list = {};
|
||||||
|
obs_frontend_get_transitions(&transition_list);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < transition_list.sources.num; i++) {
|
||||||
|
obs_source_t* transition = transition_list.sources.array[i];
|
||||||
|
QString transitionName = obs_source_get_name(transition);
|
||||||
|
|
||||||
|
if (transitionName == searchName) {
|
||||||
|
foundTransition = transition;
|
||||||
|
obs_source_addref(foundTransition);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_frontend_source_list_free(&transition_list);
|
||||||
|
return foundTransition;
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_source_t* Utils::GetSceneFromNameOrCurrent(QString sceneName) {
|
||||||
|
// Both obs_frontend_get_current_scene() and obs_get_source_by_name()
|
||||||
|
// do addref on the return source, so no need to use an OBSSource helper
|
||||||
|
obs_source_t* scene = nullptr;
|
||||||
|
|
||||||
|
if (sceneName.isEmpty() || sceneName.isNull())
|
||||||
|
scene = obs_frontend_get_current_scene();
|
||||||
|
else
|
||||||
|
scene = obs_get_source_by_name(sceneName.toUtf8());
|
||||||
|
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_array_t* Utils::GetScenes() {
|
||||||
|
obs_frontend_source_list sceneList = {};
|
||||||
|
obs_frontend_get_scenes(&sceneList);
|
||||||
|
|
||||||
|
obs_data_array_t* scenes = obs_data_array_create();
|
||||||
|
for (size_t i = 0; i < sceneList.sources.num; i++) {
|
||||||
|
obs_source_t* scene = sceneList.sources.array[i];
|
||||||
|
OBSDataAutoRelease sceneData = GetSceneData(scene);
|
||||||
|
obs_data_array_push_back(scenes, sceneData);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_frontend_source_list_free(&sceneList);
|
||||||
|
return scenes;
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_t* Utils::GetSceneData(obs_source_t* source) {
|
||||||
|
OBSDataArrayAutoRelease sceneItems = GetSceneItems(source);
|
||||||
|
|
||||||
|
obs_data_t* sceneData = obs_data_create();
|
||||||
|
obs_data_set_string(sceneData, "name", obs_source_get_name(source));
|
||||||
|
obs_data_set_array(sceneData, "sources", sceneItems);
|
||||||
|
|
||||||
|
return sceneData;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSpinBox* Utils::GetTransitionDurationControl() {
|
||||||
|
QMainWindow* window = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
return window->findChild<QSpinBox*>("transitionDuration");
|
||||||
|
}
|
||||||
|
|
||||||
|
int Utils::GetTransitionDuration() {
|
||||||
|
QSpinBox* control = GetTransitionDurationControl();
|
||||||
|
if (control)
|
||||||
|
return control->value();
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Utils::SetTransitionDuration(int ms) {
|
||||||
|
QSpinBox* control = GetTransitionDurationControl();
|
||||||
|
if (control && ms >= 0)
|
||||||
|
control->setValue(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Utils::SetTransitionByName(QString transitionName) {
|
||||||
|
OBSSourceAutoRelease transition = GetTransitionFromName(transitionName);
|
||||||
|
|
||||||
|
if (transition) {
|
||||||
|
obs_frontend_set_current_transition(transition);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton* Utils::GetPreviewModeButtonControl() {
|
||||||
|
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
return main->findChild<QPushButton*>("modeSwitch");
|
||||||
|
}
|
||||||
|
|
||||||
|
QListWidget* Utils::GetSceneListControl() {
|
||||||
|
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
return main->findChild<QListWidget*>("scenes");
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_scene_t* Utils::SceneListItemToScene(QListWidgetItem* item) {
|
||||||
|
if (!item)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
QVariant itemData = item->data(static_cast<int>(Qt::UserRole));
|
||||||
|
return itemData.value<OBSScene>();
|
||||||
|
}
|
||||||
|
|
||||||
|
QLayout* Utils::GetPreviewLayout() {
|
||||||
|
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
return main->findChild<QLayout*>("previewLayout");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Utils::TransitionToProgram() {
|
||||||
|
if (!obs_frontend_preview_program_mode_active())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// WARNING : if the layout created in OBS' CreateProgramOptions() changes
|
||||||
|
// then this won't work as expected
|
||||||
|
|
||||||
|
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
|
||||||
|
// The program options widget is the second item in the left-to-right layout
|
||||||
|
QWidget* programOptions = GetPreviewLayout()->itemAt(1)->widget();
|
||||||
|
|
||||||
|
// The "Transition" button lies in the mainButtonLayout
|
||||||
|
// which is the first itemin the program options' layout
|
||||||
|
QLayout* mainButtonLayout = programOptions->layout()->itemAt(1)->layout();
|
||||||
|
QWidget* transitionBtnWidget = mainButtonLayout->itemAt(0)->widget();
|
||||||
|
|
||||||
|
// Try to cast that widget into a button
|
||||||
|
QPushButton* transitionBtn = qobject_cast<QPushButton*>(transitionBtnWidget);
|
||||||
|
|
||||||
|
// Perform a click on that button
|
||||||
|
transitionBtn->click();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Utils::OBSVersionString() {
|
||||||
|
uint32_t version = obs_get_version();
|
||||||
|
|
||||||
|
uint8_t major, minor, patch;
|
||||||
|
major = (version >> 24) & 0xFF;
|
||||||
|
minor = (version >> 16) & 0xFF;
|
||||||
|
patch = version & 0xFF;
|
||||||
|
|
||||||
|
QString result = QString("%1.%2.%3")
|
||||||
|
.arg(major).arg(minor).arg(patch);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSystemTrayIcon* Utils::GetTrayIcon() {
|
||||||
|
QMainWindow* main = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
if (!main) return nullptr;
|
||||||
|
|
||||||
|
return main->findChildren<QSystemTrayIcon*>().first();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Utils::SysTrayNotify(QString &text,
|
||||||
|
QSystemTrayIcon::MessageIcon icon, QString title) {
|
||||||
|
if (!Config::Current()->AlertsEnabled ||
|
||||||
|
!QSystemTrayIcon::isSystemTrayAvailable() ||
|
||||||
|
!QSystemTrayIcon::supportsMessages())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSystemTrayIcon* trayIcon = GetTrayIcon();
|
||||||
|
if (trayIcon)
|
||||||
|
trayIcon->showMessage(title, text, icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Utils::FormatIPAddress(QHostAddress &addr) {
|
||||||
|
QRegExp v4regex("(::ffff:)(((\\d).){3})", Qt::CaseInsensitive);
|
||||||
|
QString addrString = addr.toString();
|
||||||
|
if (addrString.contains(v4regex)) {
|
||||||
|
addrString = QHostAddress(addr.toIPv4Address()).toString();
|
||||||
|
}
|
||||||
|
return addrString;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* Utils::GetRecordingFolder() {
|
||||||
|
config_t* profile = obs_frontend_get_profile_config();
|
||||||
|
QString outputMode = config_get_string(profile, "Output", "Mode");
|
||||||
|
|
||||||
|
if (outputMode == "Advanced") {
|
||||||
|
// Advanced mode
|
||||||
|
return config_get_string(profile, "AdvOut", "RecFilePath");
|
||||||
|
} else {
|
||||||
|
// Simple mode
|
||||||
|
return config_get_string(profile, "SimpleOutput", "FilePath");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Utils::SetRecordingFolder(const char* path) {
|
||||||
|
QDir dir(path);
|
||||||
|
if (!dir.exists())
|
||||||
|
dir.mkpath(".");
|
||||||
|
|
||||||
|
config_t* profile = obs_frontend_get_profile_config();
|
||||||
|
QString outputMode = config_get_string(profile, "Output", "Mode");
|
||||||
|
|
||||||
|
if (outputMode == "Advanced") {
|
||||||
|
config_set_string(profile, "AdvOut", "RecFilePath", path);
|
||||||
|
} else {
|
||||||
|
config_set_string(profile, "SimpleOutput", "FilePath", path);
|
||||||
|
}
|
||||||
|
|
||||||
|
config_save(profile);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Utils::ParseDataToQueryString(obs_data_t* data) {
|
||||||
|
if (!data)
|
||||||
|
return QString();
|
||||||
|
|
||||||
|
QString query;
|
||||||
|
|
||||||
|
obs_data_item_t* item = obs_data_first(data);
|
||||||
|
if (item) {
|
||||||
|
bool isFirst = true;
|
||||||
|
do {
|
||||||
|
if (!obs_data_item_has_user_value(item))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!isFirst)
|
||||||
|
query += "&";
|
||||||
|
else
|
||||||
|
isFirst = false;
|
||||||
|
|
||||||
|
QString attrName = obs_data_item_get_name(item);
|
||||||
|
query += (attrName + "=");
|
||||||
|
|
||||||
|
switch (obs_data_item_gettype(item)) {
|
||||||
|
case OBS_DATA_BOOLEAN:
|
||||||
|
query += (obs_data_item_get_bool(item) ? "true" : "false");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OBS_DATA_NUMBER:
|
||||||
|
switch (obs_data_item_numtype(item)) {
|
||||||
|
case OBS_DATA_NUM_DOUBLE:
|
||||||
|
query +=
|
||||||
|
QString::number(obs_data_item_get_double(item));
|
||||||
|
break;
|
||||||
|
case OBS_DATA_NUM_INT:
|
||||||
|
query +=
|
||||||
|
QString::number(obs_data_item_get_int(item));
|
||||||
|
break;
|
||||||
|
case OBS_DATA_NUM_INVALID:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OBS_DATA_STRING:
|
||||||
|
query +=
|
||||||
|
QUrl::toPercentEncoding(
|
||||||
|
QString(obs_data_item_get_string(item)));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
//other types are not supported
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (obs_data_item_next(&item));
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_hotkey_t* Utils::FindHotkeyByName(QString name) {
|
||||||
|
struct current_search {
|
||||||
|
QString query;
|
||||||
|
obs_hotkey_t* result;
|
||||||
|
};
|
||||||
|
|
||||||
|
current_search search;
|
||||||
|
search.query = name;
|
||||||
|
search.result = nullptr;
|
||||||
|
|
||||||
|
obs_enum_hotkeys([](void* data, obs_hotkey_id id, obs_hotkey_t* hotkey) {
|
||||||
|
current_search* search = static_cast<current_search*>(data);
|
||||||
|
|
||||||
|
const char* hk_name = obs_hotkey_get_name(hotkey);
|
||||||
|
if (hk_name == search->query) {
|
||||||
|
search->result = hotkey;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}, &search);
|
||||||
|
|
||||||
|
return search.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Utils::ReplayBufferEnabled() {
|
||||||
|
config_t* profile = obs_frontend_get_profile_config();
|
||||||
|
QString outputMode = config_get_string(profile, "Output", "Mode");
|
||||||
|
|
||||||
|
if (outputMode == "Simple") {
|
||||||
|
return config_get_bool(profile, "SimpleOutput", "RecRB");
|
||||||
|
}
|
||||||
|
else if (outputMode == "Advanced") {
|
||||||
|
return config_get_bool(profile, "AdvOut", "RecRB");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Utils::StartReplayBuffer() {
|
||||||
|
if (obs_frontend_replay_buffer_active())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!IsRPHotkeySet()) {
|
||||||
|
obs_output_t* rpOutput = obs_frontend_get_replay_buffer_output();
|
||||||
|
OBSData outputHotkeys = obs_hotkeys_save_output(rpOutput);
|
||||||
|
|
||||||
|
OBSData dummyBinding = obs_data_create();
|
||||||
|
obs_data_set_bool(dummyBinding, "control", true);
|
||||||
|
obs_data_set_bool(dummyBinding, "alt", true);
|
||||||
|
obs_data_set_bool(dummyBinding, "shift", true);
|
||||||
|
obs_data_set_bool(dummyBinding, "command", true);
|
||||||
|
obs_data_set_string(dummyBinding, "key", "OBS_KEY_0");
|
||||||
|
|
||||||
|
OBSDataArray rpSaveHotkey = obs_data_get_array(
|
||||||
|
outputHotkeys, "ReplayBuffer.Save");
|
||||||
|
obs_data_array_push_back(rpSaveHotkey, dummyBinding);
|
||||||
|
|
||||||
|
obs_hotkeys_load_output(rpOutput, outputHotkeys);
|
||||||
|
obs_frontend_replay_buffer_start();
|
||||||
|
|
||||||
|
obs_output_release(rpOutput);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
obs_frontend_replay_buffer_start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Utils::IsRPHotkeySet() {
|
||||||
|
OBSOutputAutoRelease rpOutput = obs_frontend_get_replay_buffer_output();
|
||||||
|
OBSDataAutoRelease hotkeys = obs_hotkeys_save_output(rpOutput);
|
||||||
|
OBSDataArrayAutoRelease bindings = obs_data_get_array(hotkeys,
|
||||||
|
"ReplayBuffer.Save");
|
||||||
|
|
||||||
|
size_t count = obs_data_array_count(bindings);
|
||||||
|
return (count > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* Utils::GetFilenameFormatting() {
|
||||||
|
config_t* profile = obs_frontend_get_profile_config();
|
||||||
|
return config_get_string(profile, "Output", "FilenameFormatting");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Utils::SetFilenameFormatting(const char* filenameFormatting) {
|
||||||
|
config_t* profile = obs_frontend_get_profile_config();
|
||||||
|
config_set_string(profile, "Output", "FilenameFormatting", filenameFormatting);
|
||||||
|
config_save(profile);
|
||||||
|
return true;
|
||||||
|
}
|
87
src/Utils.h
Normal file
87
src/Utils.h
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
obs-websocket
|
||||||
|
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UTILS_H
|
||||||
|
#define UTILS_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QLayout>
|
||||||
|
#include <QListWidget>
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
|
#include <QHostAddress>
|
||||||
|
|
||||||
|
#include <obs.hpp>
|
||||||
|
#include <obs-module.h>
|
||||||
|
#include <util/config-file.h>
|
||||||
|
|
||||||
|
class Utils {
|
||||||
|
public:
|
||||||
|
static obs_data_array_t* StringListToArray(char** strings, char* key);
|
||||||
|
static obs_data_array_t* GetSceneItems(obs_source_t* source);
|
||||||
|
static obs_data_t* GetSceneItemData(obs_sceneitem_t* item);
|
||||||
|
static obs_sceneitem_t* GetSceneItemFromName(
|
||||||
|
obs_source_t* source, QString name);
|
||||||
|
static obs_sceneitem_t* GetSceneItemFromId(obs_source_t* source, size_t id);
|
||||||
|
static obs_sceneitem_t* GetSceneItemFromItem(obs_source_t* source, obs_data_t* item);
|
||||||
|
static obs_source_t* GetTransitionFromName(QString transitionName);
|
||||||
|
static obs_source_t* GetSceneFromNameOrCurrent(QString sceneName);
|
||||||
|
|
||||||
|
static bool IsValidAlignment(const uint32_t alignment);
|
||||||
|
|
||||||
|
static obs_data_array_t* GetScenes();
|
||||||
|
static obs_data_t* GetSceneData(obs_source_t* source);
|
||||||
|
|
||||||
|
static QSpinBox* GetTransitionDurationControl();
|
||||||
|
static int GetTransitionDuration();
|
||||||
|
static void SetTransitionDuration(int ms);
|
||||||
|
|
||||||
|
static bool SetTransitionByName(QString transitionName);
|
||||||
|
|
||||||
|
static QPushButton* GetPreviewModeButtonControl();
|
||||||
|
static QLayout* GetPreviewLayout();
|
||||||
|
static QListWidget* GetSceneListControl();
|
||||||
|
static obs_scene_t* SceneListItemToScene(QListWidgetItem* item);
|
||||||
|
|
||||||
|
static void TransitionToProgram();
|
||||||
|
|
||||||
|
static QString OBSVersionString();
|
||||||
|
|
||||||
|
static QSystemTrayIcon* GetTrayIcon();
|
||||||
|
static void SysTrayNotify(
|
||||||
|
QString &text,
|
||||||
|
QSystemTrayIcon::MessageIcon n,
|
||||||
|
QString title = QString("obs-websocket"));
|
||||||
|
|
||||||
|
static QString FormatIPAddress(QHostAddress &addr);
|
||||||
|
|
||||||
|
static const char* GetRecordingFolder();
|
||||||
|
static bool SetRecordingFolder(const char* path);
|
||||||
|
|
||||||
|
static QString ParseDataToQueryString(obs_data_t* data);
|
||||||
|
static obs_hotkey_t* FindHotkeyByName(QString name);
|
||||||
|
static bool ReplayBufferEnabled();
|
||||||
|
static void StartReplayBuffer();
|
||||||
|
static bool IsRPHotkeySet();
|
||||||
|
static const char* GetFilenameFormatting();
|
||||||
|
static bool SetFilenameFormatting(const char* filenameFormatting);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UTILS_H
|
948
src/WSEvents.cpp
Normal file
948
src/WSEvents.cpp
Normal file
@ -0,0 +1,948 @@
|
|||||||
|
/**
|
||||||
|
* obs-websocket
|
||||||
|
* Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
|
* Copyright (C) 2017 Brendan Hagan <https://github.com/haganbmj>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <util/platform.h>
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
#include "WSEvents.h"
|
||||||
|
|
||||||
|
#include "obs-websocket.h"
|
||||||
|
|
||||||
|
bool transitionIsCut(obs_source_t* transition) {
|
||||||
|
if (!transition)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (obs_source_get_type(transition) == OBS_SOURCE_TYPE_TRANSITION
|
||||||
|
&& QString(obs_source_get_id(transition)) == "cut_transition") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* nsToTimestamp(uint64_t ns) {
|
||||||
|
uint64_t ms = ns / (1000 * 1000);
|
||||||
|
uint64_t secs = ms / 1000;
|
||||||
|
uint64_t minutes = secs / 60;
|
||||||
|
|
||||||
|
uint64_t hoursPart = minutes / 60;
|
||||||
|
uint64_t minutesPart = minutes % 60;
|
||||||
|
uint64_t secsPart = secs % 60;
|
||||||
|
uint64_t msPart = ms % 1000;
|
||||||
|
|
||||||
|
char* ts = (char*)bmalloc(64);
|
||||||
|
sprintf(ts, "%02d:%02d:%02d.%03d",
|
||||||
|
hoursPart, minutesPart, secsPart, msPart);
|
||||||
|
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* calldata_get_ptr(const calldata_t* data, const char* name) {
|
||||||
|
void* ptr = nullptr;
|
||||||
|
calldata_get_ptr(data, name, &ptr);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
WSEvents* WSEvents::Instance = nullptr;
|
||||||
|
|
||||||
|
WSEvents::WSEvents(WSServer* srv) {
|
||||||
|
_srv = srv;
|
||||||
|
obs_frontend_add_event_callback(WSEvents::FrontendEventHandler, this);
|
||||||
|
|
||||||
|
QSpinBox* durationControl = Utils::GetTransitionDurationControl();
|
||||||
|
connect(durationControl, SIGNAL(valueChanged(int)),
|
||||||
|
this, SLOT(TransitionDurationChanged(int)));
|
||||||
|
|
||||||
|
QTimer* statusTimer = new QTimer();
|
||||||
|
connect(statusTimer, SIGNAL(timeout()),
|
||||||
|
this, SLOT(StreamStatus()));
|
||||||
|
pulse = false;
|
||||||
|
connect(statusTimer, SIGNAL(timeout()),
|
||||||
|
this, SLOT(Heartbeat()));
|
||||||
|
statusTimer->start(2000); // equal to frontend's constant BITRATE_UPDATE_SECONDS
|
||||||
|
|
||||||
|
currentScene = nullptr;
|
||||||
|
|
||||||
|
QTimer::singleShot(1000, this, SLOT(deferredInitOperations()));
|
||||||
|
|
||||||
|
HeartbeatIsActive = false;
|
||||||
|
|
||||||
|
_streamingActive = false;
|
||||||
|
_recordingActive = false;
|
||||||
|
|
||||||
|
_streamStarttime = 0;
|
||||||
|
_recStarttime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
WSEvents::~WSEvents() {
|
||||||
|
obs_frontend_remove_event_callback(WSEvents::FrontendEventHandler, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSEvents::deferredInitOperations() {
|
||||||
|
hookTransitionBeginEvent();
|
||||||
|
|
||||||
|
OBSSourceAutoRelease scene = obs_frontend_get_current_scene();
|
||||||
|
connectSceneSignals(scene);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private_data) {
|
||||||
|
WSEvents* owner = static_cast<WSEvents*>(private_data);
|
||||||
|
|
||||||
|
if (!owner->_srv)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (event == OBS_FRONTEND_EVENT_SCENE_CHANGED) {
|
||||||
|
owner->OnSceneChange();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED) {
|
||||||
|
owner->OnSceneListChange();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED) {
|
||||||
|
owner->hookTransitionBeginEvent();
|
||||||
|
owner->OnSceneCollectionChange();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_LIST_CHANGED) {
|
||||||
|
owner->OnSceneCollectionListChange();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_TRANSITION_CHANGED) {
|
||||||
|
owner->OnTransitionChange();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_TRANSITION_LIST_CHANGED) {
|
||||||
|
owner->hookTransitionBeginEvent();
|
||||||
|
owner->OnTransitionListChange();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_PROFILE_CHANGED) {
|
||||||
|
owner->OnProfileChange();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED) {
|
||||||
|
owner->OnProfileListChange();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_STREAMING_STARTING) {
|
||||||
|
owner->OnStreamStarting();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_STREAMING_STARTED) {
|
||||||
|
owner->_streamingActive = true;
|
||||||
|
owner->OnStreamStarted();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_STREAMING_STOPPING) {
|
||||||
|
owner->OnStreamStopping();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_STREAMING_STOPPED) {
|
||||||
|
owner->_streamingActive = false;
|
||||||
|
owner->OnStreamStopped();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_RECORDING_STARTING) {
|
||||||
|
owner->OnRecordingStarting();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_RECORDING_STARTED) {
|
||||||
|
owner->_recordingActive = true;
|
||||||
|
owner->OnRecordingStarted();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_RECORDING_STOPPING) {
|
||||||
|
owner->OnRecordingStopping();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_RECORDING_STOPPED) {
|
||||||
|
owner->_recordingActive = false;
|
||||||
|
owner->OnRecordingStopped();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING) {
|
||||||
|
owner->OnReplayStarting();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED) {
|
||||||
|
owner->OnReplayStarted();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING) {
|
||||||
|
owner->OnReplayStopping();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED) {
|
||||||
|
owner->OnReplayStopped();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_STUDIO_MODE_ENABLED) {
|
||||||
|
owner->OnStudioModeSwitched(true);
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_STUDIO_MODE_DISABLED) {
|
||||||
|
owner->OnStudioModeSwitched(false);
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED) {
|
||||||
|
owner->OnPreviewSceneChanged();
|
||||||
|
}
|
||||||
|
else if (event == OBS_FRONTEND_EVENT_EXIT) {
|
||||||
|
owner->connectSceneSignals(nullptr);
|
||||||
|
owner->OnExit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSEvents::broadcastUpdate(const char* updateType,
|
||||||
|
obs_data_t* additionalFields = nullptr)
|
||||||
|
{
|
||||||
|
OBSDataAutoRelease update = obs_data_create();
|
||||||
|
obs_data_set_string(update, "update-type", updateType);
|
||||||
|
|
||||||
|
const char* ts = nullptr;
|
||||||
|
if (_streamingActive) {
|
||||||
|
ts = nsToTimestamp(os_gettime_ns() - _streamStarttime);
|
||||||
|
obs_data_set_string(update, "stream-timecode", ts);
|
||||||
|
bfree((void*)ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_recordingActive) {
|
||||||
|
ts = nsToTimestamp(os_gettime_ns() - _recStarttime);
|
||||||
|
obs_data_set_string(update, "rec-timecode", ts);
|
||||||
|
bfree((void*)ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalFields)
|
||||||
|
obs_data_apply(update, additionalFields);
|
||||||
|
|
||||||
|
QString json = obs_data_get_json(update);
|
||||||
|
_srv->broadcast(json);
|
||||||
|
|
||||||
|
if (Config::Current()->DebugEnabled)
|
||||||
|
blog(LOG_DEBUG, "Update << '%s'", json.toUtf8().constData());
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSEvents::hookTransitionBeginEvent() {
|
||||||
|
obs_frontend_source_list transitions = {};
|
||||||
|
obs_frontend_get_transitions(&transitions);
|
||||||
|
|
||||||
|
for (int i = 0; i < transitions.sources.num; i++) {
|
||||||
|
obs_source_t* transition = transitions.sources.array[i];
|
||||||
|
signal_handler_t* sh = obs_source_get_signal_handler(transition);
|
||||||
|
signal_handler_disconnect(sh, "transition_start", OnTransitionBegin, this);
|
||||||
|
signal_handler_connect(sh, "transition_start", OnTransitionBegin, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_frontend_source_list_free(&transitions);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSEvents::connectSceneSignals(obs_source_t* scene) {
|
||||||
|
signal_handler_t* sh = nullptr;
|
||||||
|
|
||||||
|
if (currentScene) {
|
||||||
|
sh = obs_source_get_signal_handler(currentScene);
|
||||||
|
|
||||||
|
signal_handler_disconnect(sh,
|
||||||
|
"reorder", OnSceneReordered, this);
|
||||||
|
signal_handler_disconnect(sh,
|
||||||
|
"item_add", OnSceneItemAdd, this);
|
||||||
|
signal_handler_disconnect(sh,
|
||||||
|
"item_remove", OnSceneItemDelete, this);
|
||||||
|
signal_handler_disconnect(sh,
|
||||||
|
"item_visible", OnSceneItemVisibilityChanged, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentScene = scene;
|
||||||
|
|
||||||
|
if (currentScene) {
|
||||||
|
// TODO : connect to all scenes, not just the current one.
|
||||||
|
sh = obs_source_get_signal_handler(currentScene);
|
||||||
|
signal_handler_connect(sh,
|
||||||
|
"reorder", OnSceneReordered, this);
|
||||||
|
signal_handler_connect(sh,
|
||||||
|
"item_add", OnSceneItemAdd, this);
|
||||||
|
signal_handler_connect(sh,
|
||||||
|
"item_remove", OnSceneItemDelete, this);
|
||||||
|
signal_handler_connect(sh,
|
||||||
|
"item_visible", OnSceneItemVisibilityChanged, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t WSEvents::GetStreamingTime() {
|
||||||
|
if (_streamingActive)
|
||||||
|
return (os_gettime_ns() - _streamStarttime);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* WSEvents::GetStreamingTimecode() {
|
||||||
|
return nsToTimestamp(GetStreamingTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t WSEvents::GetRecordingTime() {
|
||||||
|
if (_recordingActive)
|
||||||
|
return (os_gettime_ns() - _recStarttime);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* WSEvents::GetRecordingTimecode() {
|
||||||
|
return nsToTimestamp(GetRecordingTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates a scene change.
|
||||||
|
*
|
||||||
|
* @return {String} `scene-name` The new scene.
|
||||||
|
* @return {Array<Source>} `sources` List of sources in the new scene. Same specification as [`GetCurrentScene`](#getcurrentscene).
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name SwitchScenes
|
||||||
|
* @category scenes
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::OnSceneChange() {
|
||||||
|
OBSSourceAutoRelease currentScene = obs_frontend_get_current_scene();
|
||||||
|
OBSDataArrayAutoRelease sceneItems = Utils::GetSceneItems(currentScene);
|
||||||
|
connectSceneSignals(currentScene);
|
||||||
|
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_string(data, "scene-name", obs_source_get_name(currentScene));
|
||||||
|
obs_data_set_array(data, "sources", sceneItems);
|
||||||
|
|
||||||
|
broadcastUpdate("SwitchScenes", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The scene list has been modified.
|
||||||
|
* Scenes have been added, removed, or renamed.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name ScenesChanged
|
||||||
|
* @category scenes
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::OnSceneListChange() {
|
||||||
|
broadcastUpdate("ScenesChanged");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered when switching to another scene collection or when renaming the current scene collection.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name SceneCollectionChanged
|
||||||
|
* @category scenes
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnSceneCollectionChange() {
|
||||||
|
broadcastUpdate("SceneCollectionChanged");
|
||||||
|
|
||||||
|
currentScene = nullptr;
|
||||||
|
|
||||||
|
OnTransitionListChange();
|
||||||
|
OnTransitionChange();
|
||||||
|
|
||||||
|
OnSceneListChange();
|
||||||
|
OnSceneChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered when a scene collection is created, added, renamed, or removed.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name SceneCollectionListChanged
|
||||||
|
* @category scenes
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnSceneCollectionListChange() {
|
||||||
|
broadcastUpdate("SceneCollectionListChanged");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The active transition has been changed.
|
||||||
|
*
|
||||||
|
* @return {String} `transition-name` The name of the new active transition.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name SwitchTransition
|
||||||
|
* @category transitions
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnTransitionChange() {
|
||||||
|
OBSSourceAutoRelease currentTransition = obs_frontend_get_current_transition();
|
||||||
|
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_string(data, "transition-name",
|
||||||
|
obs_source_get_name(currentTransition));
|
||||||
|
|
||||||
|
broadcastUpdate("SwitchTransition", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of available transitions has been modified.
|
||||||
|
* Transitions have been added, removed, or renamed.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name TransitionListChanged
|
||||||
|
* @category transitions
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnTransitionListChange() {
|
||||||
|
broadcastUpdate("TransitionListChanged");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered when switching to another profile or when renaming the current profile.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name ProfileChanged
|
||||||
|
* @category profiles
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnProfileChange() {
|
||||||
|
broadcastUpdate("ProfileChanged");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered when a profile is created, added, renamed, or removed.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name ProfileListChanged
|
||||||
|
* @category profiles
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnProfileListChange() {
|
||||||
|
broadcastUpdate("ProfileListChanged");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A request to start streaming has been issued.
|
||||||
|
*
|
||||||
|
* @return {boolean} `preview-only` Always false (retrocompatibility).
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name StreamStarting
|
||||||
|
* @category streaming
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::OnStreamStarting() {
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_bool(data, "preview-only", false);
|
||||||
|
|
||||||
|
broadcastUpdate("StreamStarting", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Streaming started successfully.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name StreamStarted
|
||||||
|
* @category streaming
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::OnStreamStarted() {
|
||||||
|
_streamStarttime = os_gettime_ns();
|
||||||
|
_lastBytesSent = 0;
|
||||||
|
broadcastUpdate("StreamStarted");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A request to stop streaming has been issued.
|
||||||
|
*
|
||||||
|
* @return {boolean} `preview-only` Always false (retrocompatibility).
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name StreamStopping
|
||||||
|
* @category streaming
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::OnStreamStopping() {
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_bool(data, "preview-only", false);
|
||||||
|
|
||||||
|
broadcastUpdate("StreamStopping", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Streaming stopped successfully.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name StreamStopped
|
||||||
|
* @category streaming
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::OnStreamStopped() {
|
||||||
|
_streamStarttime = 0;
|
||||||
|
broadcastUpdate("StreamStopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A request to start recording has been issued.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name RecordingStarting
|
||||||
|
* @category recording
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::OnRecordingStarting() {
|
||||||
|
broadcastUpdate("RecordingStarting");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recording started successfully.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name RecordingStarted
|
||||||
|
* @category recording
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::OnRecordingStarted() {
|
||||||
|
_recStarttime = os_gettime_ns();
|
||||||
|
broadcastUpdate("RecordingStarted");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A request to stop recording has been issued.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name RecordingStopping
|
||||||
|
* @category recording
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::OnRecordingStopping() {
|
||||||
|
broadcastUpdate("RecordingStopping");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recording stopped successfully.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name RecordingStopped
|
||||||
|
* @category recording
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::OnRecordingStopped() {
|
||||||
|
_recStarttime = 0;
|
||||||
|
broadcastUpdate("RecordingStopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A request to start the replay buffer has been issued.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name ReplayStarting
|
||||||
|
* @category replay buffer
|
||||||
|
* @since 4.2.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnReplayStarting() {
|
||||||
|
broadcastUpdate("ReplayStarting");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replay Buffer started successfully
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name ReplayStarted
|
||||||
|
* @category replay buffer
|
||||||
|
* @since 4.2.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnReplayStarted() {
|
||||||
|
broadcastUpdate("ReplayStarted");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A request to stop the replay buffer has been issued.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name ReplayStopping
|
||||||
|
* @category replay buffer
|
||||||
|
* @since 4.2.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnReplayStopping() {
|
||||||
|
broadcastUpdate("ReplayStopping");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replay Buffer stopped successfully
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name ReplayStopped
|
||||||
|
* @category replay buffer
|
||||||
|
* @since 4.2.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnReplayStopped() {
|
||||||
|
broadcastUpdate("ReplayStopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OBS is exiting.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name Exiting
|
||||||
|
* @category other
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::OnExit() {
|
||||||
|
broadcastUpdate("Exiting");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit every 2 seconds.
|
||||||
|
*
|
||||||
|
* @return {boolean} `streaming` Current streaming state.
|
||||||
|
* @return {boolean} `recording` Current recording state.
|
||||||
|
* @return {boolean} `preview-only` Always false (retrocompatibility).
|
||||||
|
* @return {int} `bytes-per-sec` Amount of data per second (in bytes) transmitted by the stream encoder.
|
||||||
|
* @return {int} `kbits-per-sec` Amount of data per second (in kilobits) transmitted by the stream encoder.
|
||||||
|
* @return {double} `strain` Percentage of dropped frames.
|
||||||
|
* @return {int} `total-stream-time` Total time (in seconds) since the stream started.
|
||||||
|
* @return {int} `num-total-frames` Total number of frames transmitted since the stream started.
|
||||||
|
* @return {int} `num-dropped-frames` Number of frames dropped by the encoder since the stream started.
|
||||||
|
* @return {double} `fps` Current framerate.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name StreamStatus
|
||||||
|
* @category streaming
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSEvents::StreamStatus() {
|
||||||
|
bool streamingActive = obs_frontend_streaming_active();
|
||||||
|
bool recordingActive = obs_frontend_recording_active();
|
||||||
|
|
||||||
|
OBSOutputAutoRelease streamOutput = obs_frontend_get_streaming_output();
|
||||||
|
|
||||||
|
if (!streamOutput || !streamingActive) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t bytesSent = obs_output_get_total_bytes(streamOutput);
|
||||||
|
uint64_t bytesSentTime = os_gettime_ns();
|
||||||
|
|
||||||
|
if (bytesSent < _lastBytesSent)
|
||||||
|
bytesSent = 0;
|
||||||
|
|
||||||
|
if (bytesSent == 0)
|
||||||
|
_lastBytesSent = 0;
|
||||||
|
|
||||||
|
uint64_t bytesBetween = bytesSent - _lastBytesSent;
|
||||||
|
double timePassed =
|
||||||
|
double(bytesSentTime - _lastBytesSentTime) / 1000000000.0;
|
||||||
|
|
||||||
|
uint64_t bytesPerSec = bytesBetween / timePassed;
|
||||||
|
|
||||||
|
_lastBytesSent = bytesSent;
|
||||||
|
_lastBytesSentTime = bytesSentTime;
|
||||||
|
|
||||||
|
uint64_t totalStreamTime =
|
||||||
|
(os_gettime_ns() - _streamStarttime) / 1000000000;
|
||||||
|
|
||||||
|
int totalFrames = obs_output_get_total_frames(streamOutput);
|
||||||
|
int droppedFrames = obs_output_get_frames_dropped(streamOutput);
|
||||||
|
|
||||||
|
float strain = obs_output_get_congestion(streamOutput);
|
||||||
|
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_bool(data, "streaming", streamingActive);
|
||||||
|
obs_data_set_bool(data, "recording", recordingActive);
|
||||||
|
obs_data_set_int(data, "bytes-per-sec", bytesPerSec);
|
||||||
|
obs_data_set_int(data, "kbits-per-sec", (bytesPerSec * 8) / 1024);
|
||||||
|
obs_data_set_int(data, "total-stream-time", totalStreamTime);
|
||||||
|
obs_data_set_int(data, "num-total-frames", totalFrames);
|
||||||
|
obs_data_set_int(data, "num-dropped-frames", droppedFrames);
|
||||||
|
obs_data_set_double(data, "fps", obs_get_active_fps());
|
||||||
|
obs_data_set_double(data, "strain", strain);
|
||||||
|
obs_data_set_bool(data, "preview-only", false); // Retrocompat with OBSRemote
|
||||||
|
|
||||||
|
broadcastUpdate("StreamStatus", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted every 2 seconds after enabling it by calling SetHeartbeat.
|
||||||
|
*
|
||||||
|
* @return {boolean} `pulse` Toggles between every JSON message as an "I am alive" indicator.
|
||||||
|
* @return {string (optional)} `current-profile` Current active profile.
|
||||||
|
* @return {string (optional)} `current-scene` Current active scene.
|
||||||
|
* @return {boolean (optional)} `streaming` Current streaming state.
|
||||||
|
* @return {int (optional)} `total-stream-time` Total time (in seconds) since the stream started.
|
||||||
|
* @return {int (optional)} `total-stream-bytes` Total bytes sent since the stream started.
|
||||||
|
* @return {int (optional)} `total-stream-frames` Total frames streamed since the stream started.
|
||||||
|
* @return {boolean (optional)} `recording` Current recording state.
|
||||||
|
* @return {int (optional)} `total-record-time` Total time (in seconds) since recording started.
|
||||||
|
* @return {int (optional)} `total-record-bytes` Total bytes recorded since the recording started.
|
||||||
|
* @return {int (optional)} `total-record-frames` Total frames recorded since the recording started.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name Heartbeat
|
||||||
|
* @category general
|
||||||
|
*/
|
||||||
|
void WSEvents::Heartbeat() {
|
||||||
|
|
||||||
|
if (!HeartbeatIsActive) return;
|
||||||
|
|
||||||
|
bool streamingActive = obs_frontend_streaming_active();
|
||||||
|
bool recordingActive = obs_frontend_recording_active();
|
||||||
|
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
OBSOutputAutoRelease recordOutput = obs_frontend_get_recording_output();
|
||||||
|
OBSOutputAutoRelease streamOutput = obs_frontend_get_streaming_output();
|
||||||
|
|
||||||
|
pulse = !pulse;
|
||||||
|
obs_data_set_bool(data, "pulse", pulse);
|
||||||
|
|
||||||
|
obs_data_set_string(data, "current-profile", obs_frontend_get_current_profile());
|
||||||
|
|
||||||
|
OBSSourceAutoRelease currentScene = obs_frontend_get_current_scene();
|
||||||
|
obs_data_set_string(data, "current-scene", obs_source_get_name(currentScene));
|
||||||
|
|
||||||
|
obs_data_set_bool(data, "streaming", streamingActive);
|
||||||
|
if (streamingActive) {
|
||||||
|
uint64_t totalStreamTime = (os_gettime_ns() - _streamStarttime) / 1000000000;
|
||||||
|
obs_data_set_int(data, "total-stream-time", totalStreamTime);
|
||||||
|
obs_data_set_int(data, "total-stream-bytes", (uint64_t)obs_output_get_total_bytes(streamOutput));
|
||||||
|
obs_data_set_int(data, "total-stream-frames", obs_output_get_total_frames(streamOutput));
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_set_bool(data, "recording", recordingActive);
|
||||||
|
if (recordingActive) {
|
||||||
|
uint64_t totalRecordTime = (os_gettime_ns() - _recStarttime) / 1000000000;
|
||||||
|
obs_data_set_int(data, "total-record-time", totalRecordTime);
|
||||||
|
obs_data_set_int(data, "total-record-bytes", (uint64_t)obs_output_get_total_bytes(recordOutput));
|
||||||
|
obs_data_set_int(data, "total-record-frames", obs_output_get_total_frames(recordOutput));
|
||||||
|
}
|
||||||
|
|
||||||
|
broadcastUpdate("Heartbeat", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The active transition duration has been changed.
|
||||||
|
*
|
||||||
|
* @return {int} `new-duration` New transition duration.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name TransitionDurationChanged
|
||||||
|
* @category transitions
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::TransitionDurationChanged(int ms) {
|
||||||
|
OBSDataAutoRelease fields = obs_data_create();
|
||||||
|
obs_data_set_int(fields, "new-duration", ms);
|
||||||
|
|
||||||
|
broadcastUpdate("TransitionDurationChanged", fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A transition (other than "cut") has begun.
|
||||||
|
*
|
||||||
|
* @return {String} `name` Transition name.
|
||||||
|
* @return {int} `duration` Transition duration (in milliseconds).
|
||||||
|
* @return {String} `from-scene` Source scene of the transition
|
||||||
|
* @return {String} `to-scene` Destination scene of the transition
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name TransitionBegin
|
||||||
|
* @category transitions
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnTransitionBegin(void* param, calldata_t* data) {
|
||||||
|
WSEvents* instance = static_cast<WSEvents*>(param);
|
||||||
|
|
||||||
|
OBSSource transition = (obs_source_t*)calldata_get_ptr(data, "source");
|
||||||
|
if (!transition) return;
|
||||||
|
|
||||||
|
// Detect if transition is the global transition or a transition override.
|
||||||
|
// Fetching the duration is different depending on the case.
|
||||||
|
OBSSourceAutoRelease sourceScene = obs_transition_get_source(transition, OBS_TRANSITION_SOURCE_A);
|
||||||
|
OBSSourceAutoRelease destinationScene = obs_transition_get_active_source(transition);
|
||||||
|
OBSDataAutoRelease destinationSettings = obs_source_get_private_settings(destinationScene);
|
||||||
|
int duration = -1;
|
||||||
|
if (obs_data_has_default_value(destinationSettings, "transition_duration") ||
|
||||||
|
obs_data_has_user_value(destinationSettings, "transition_duration"))
|
||||||
|
{
|
||||||
|
duration = obs_data_get_int(destinationSettings, "transition_duration");
|
||||||
|
} else {
|
||||||
|
duration = Utils::GetTransitionDuration();
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSDataAutoRelease fields = obs_data_create();
|
||||||
|
obs_data_set_string(fields, "name", obs_source_get_name(transition));
|
||||||
|
if (duration >= 0) {
|
||||||
|
obs_data_set_int(fields, "duration", duration);
|
||||||
|
} else {
|
||||||
|
blog(LOG_WARNING, "OnTransitionBegin: duration is negative !");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceScene) {
|
||||||
|
obs_data_set_string(fields, "from-scene", obs_source_get_name(sourceScene));
|
||||||
|
}
|
||||||
|
if (destinationScene) {
|
||||||
|
obs_data_set_string(fields, "to-scene", obs_source_get_name(destinationScene));
|
||||||
|
}
|
||||||
|
|
||||||
|
instance->broadcastUpdate("TransitionBegin", fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scene items have been reordered.
|
||||||
|
*
|
||||||
|
* @return {String} `scene-name` Name of the scene where items have been reordered.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name SourceOrderChanged
|
||||||
|
* @category sources
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnSceneReordered(void* param, calldata_t* data) {
|
||||||
|
WSEvents* instance = static_cast<WSEvents*>(param);
|
||||||
|
|
||||||
|
obs_scene_t* scene = nullptr;
|
||||||
|
calldata_get_ptr(data, "scene", &scene);
|
||||||
|
|
||||||
|
OBSDataAutoRelease fields = obs_data_create();
|
||||||
|
obs_data_set_string(fields, "scene-name",
|
||||||
|
obs_source_get_name(obs_scene_get_source(scene)));
|
||||||
|
|
||||||
|
instance->broadcastUpdate("SourceOrderChanged", fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An item has been added to the current scene.
|
||||||
|
*
|
||||||
|
* @return {String} `scene-name` Name of the scene.
|
||||||
|
* @return {String} `item-name` Name of the item added to the scene.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name SceneItemAdded
|
||||||
|
* @category sources
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnSceneItemAdd(void* param, calldata_t* data) {
|
||||||
|
WSEvents* instance = static_cast<WSEvents*>(param);
|
||||||
|
|
||||||
|
obs_scene_t* scene = nullptr;
|
||||||
|
calldata_get_ptr(data, "scene", &scene);
|
||||||
|
|
||||||
|
obs_sceneitem_t* sceneItem = nullptr;
|
||||||
|
calldata_get_ptr(data, "item", &sceneItem);
|
||||||
|
|
||||||
|
const char* sceneName =
|
||||||
|
obs_source_get_name(obs_scene_get_source(scene));
|
||||||
|
const char* sceneItemName =
|
||||||
|
obs_source_get_name(obs_sceneitem_get_source(sceneItem));
|
||||||
|
|
||||||
|
OBSDataAutoRelease fields = obs_data_create();
|
||||||
|
obs_data_set_string(fields, "scene-name", sceneName);
|
||||||
|
obs_data_set_string(fields, "item-name", sceneItemName);
|
||||||
|
|
||||||
|
instance->broadcastUpdate("SceneItemAdded", fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An item has been removed from the current scene.
|
||||||
|
*
|
||||||
|
* @return {String} `scene-name` Name of the scene.
|
||||||
|
* @return {String} `item-name` Name of the item removed from the scene.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name SceneItemRemoved
|
||||||
|
* @category sources
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnSceneItemDelete(void* param, calldata_t* data) {
|
||||||
|
WSEvents* instance = static_cast<WSEvents*>(param);
|
||||||
|
|
||||||
|
obs_scene_t* scene = nullptr;
|
||||||
|
calldata_get_ptr(data, "scene", &scene);
|
||||||
|
|
||||||
|
obs_sceneitem_t* sceneItem = nullptr;
|
||||||
|
calldata_get_ptr(data, "item", &sceneItem);
|
||||||
|
|
||||||
|
const char* sceneName =
|
||||||
|
obs_source_get_name(obs_scene_get_source(scene));
|
||||||
|
const char* sceneItemName =
|
||||||
|
obs_source_get_name(obs_sceneitem_get_source(sceneItem));
|
||||||
|
|
||||||
|
OBSDataAutoRelease fields = obs_data_create();
|
||||||
|
obs_data_set_string(fields, "scene-name", sceneName);
|
||||||
|
obs_data_set_string(fields, "item-name", sceneItemName);
|
||||||
|
|
||||||
|
instance->broadcastUpdate("SceneItemRemoved", fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An item's visibility has been toggled.
|
||||||
|
*
|
||||||
|
* @return {String} `scene-name` Name of the scene.
|
||||||
|
* @return {String} `item-name` Name of the item in the scene.
|
||||||
|
* @return {boolean} `item-visible` New visibility state of the item.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name SceneItemVisibilityChanged
|
||||||
|
* @category sources
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnSceneItemVisibilityChanged(void* param, calldata_t* data) {
|
||||||
|
WSEvents* instance = static_cast<WSEvents*>(param);
|
||||||
|
|
||||||
|
obs_scene_t* scene = nullptr;
|
||||||
|
calldata_get_ptr(data, "scene", &scene);
|
||||||
|
|
||||||
|
obs_sceneitem_t* sceneItem = nullptr;
|
||||||
|
calldata_get_ptr(data, "item", &sceneItem);
|
||||||
|
|
||||||
|
bool visible = false;
|
||||||
|
calldata_get_bool(data, "visible", &visible);
|
||||||
|
|
||||||
|
const char* sceneName =
|
||||||
|
obs_source_get_name(obs_scene_get_source(scene));
|
||||||
|
const char* sceneItemName =
|
||||||
|
obs_source_get_name(obs_sceneitem_get_source(sceneItem));
|
||||||
|
|
||||||
|
OBSDataAutoRelease fields = obs_data_create();
|
||||||
|
obs_data_set_string(fields, "scene-name", sceneName);
|
||||||
|
obs_data_set_string(fields, "item-name", sceneItemName);
|
||||||
|
obs_data_set_bool(fields, "item-visible", visible);
|
||||||
|
|
||||||
|
instance->broadcastUpdate("SceneItemVisibilityChanged", fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The selected preview scene has changed (only available in Studio Mode).
|
||||||
|
*
|
||||||
|
* @return {String} `scene-name` Name of the scene being previewed.
|
||||||
|
* @return {Array<Source>} `sources` List of sources composing the scene. Same specification as [`GetCurrentScene`](#getcurrentscene).
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name PreviewSceneChanged
|
||||||
|
* @category studio mode
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnPreviewSceneChanged() {
|
||||||
|
if (obs_frontend_preview_program_mode_active()) {
|
||||||
|
OBSSourceAutoRelease scene = obs_frontend_get_current_preview_scene();
|
||||||
|
if (!scene)
|
||||||
|
return;
|
||||||
|
|
||||||
|
OBSDataArrayAutoRelease sceneItems = Utils::GetSceneItems(scene);
|
||||||
|
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_string(data, "scene-name", obs_source_get_name(scene));
|
||||||
|
obs_data_set_array(data, "sources", sceneItems);
|
||||||
|
|
||||||
|
broadcastUpdate("PreviewSceneChanged", data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Studio Mode has been enabled or disabled.
|
||||||
|
*
|
||||||
|
* @return {boolean} `new-state` The new enabled state of Studio Mode.
|
||||||
|
*
|
||||||
|
* @api events
|
||||||
|
* @name StudioModeSwitched
|
||||||
|
* @category studio mode
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSEvents::OnStudioModeSwitched(bool checked) {
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_bool(data, "new-state", checked);
|
||||||
|
|
||||||
|
broadcastUpdate("StudioModeSwitched", data);
|
||||||
|
}
|
110
src/WSEvents.h
Normal file
110
src/WSEvents.h
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
obs-websocket
|
||||||
|
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
|
Copyright (C) 2017 Brendan Hagan <https://github.com/haganbmj>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WSEVENTS_H
|
||||||
|
#define WSEVENTS_H
|
||||||
|
|
||||||
|
#include <obs.hpp>
|
||||||
|
#include <obs-frontend-api.h>
|
||||||
|
#include <QListWidgetItem>
|
||||||
|
#include "WSServer.h"
|
||||||
|
|
||||||
|
class WSEvents : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit WSEvents(WSServer* srv);
|
||||||
|
~WSEvents();
|
||||||
|
static void FrontendEventHandler(
|
||||||
|
enum obs_frontend_event event, void* privateData);
|
||||||
|
static WSEvents* Instance;
|
||||||
|
void connectSceneSignals(obs_source_t* scene);
|
||||||
|
|
||||||
|
void hookTransitionBeginEvent();
|
||||||
|
|
||||||
|
uint64_t GetStreamingTime();
|
||||||
|
const char* GetStreamingTimecode();
|
||||||
|
uint64_t GetRecordingTime();
|
||||||
|
const char* GetRecordingTimecode();
|
||||||
|
|
||||||
|
bool HeartbeatIsActive;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void deferredInitOperations();
|
||||||
|
void StreamStatus();
|
||||||
|
void Heartbeat();
|
||||||
|
void TransitionDurationChanged(int ms);
|
||||||
|
|
||||||
|
private:
|
||||||
|
WSServer* _srv;
|
||||||
|
OBSSource currentScene;
|
||||||
|
|
||||||
|
bool pulse;
|
||||||
|
|
||||||
|
bool _streamingActive;
|
||||||
|
bool _recordingActive;
|
||||||
|
|
||||||
|
uint64_t _streamStarttime;
|
||||||
|
uint64_t _recStarttime;
|
||||||
|
|
||||||
|
uint64_t _lastBytesSent;
|
||||||
|
uint64_t _lastBytesSentTime;
|
||||||
|
|
||||||
|
void broadcastUpdate(const char* updateType,
|
||||||
|
obs_data_t* additionalFields);
|
||||||
|
|
||||||
|
void OnSceneChange();
|
||||||
|
void OnSceneListChange();
|
||||||
|
void OnSceneCollectionChange();
|
||||||
|
void OnSceneCollectionListChange();
|
||||||
|
|
||||||
|
void OnTransitionChange();
|
||||||
|
void OnTransitionListChange();
|
||||||
|
|
||||||
|
void OnProfileChange();
|
||||||
|
void OnProfileListChange();
|
||||||
|
|
||||||
|
void OnStreamStarting();
|
||||||
|
void OnStreamStarted();
|
||||||
|
void OnStreamStopping();
|
||||||
|
void OnStreamStopped();
|
||||||
|
|
||||||
|
void OnRecordingStarting();
|
||||||
|
void OnRecordingStarted();
|
||||||
|
void OnRecordingStopping();
|
||||||
|
void OnRecordingStopped();
|
||||||
|
|
||||||
|
void OnReplayStarting();
|
||||||
|
void OnReplayStarted();
|
||||||
|
void OnReplayStopping();
|
||||||
|
void OnReplayStopped();
|
||||||
|
|
||||||
|
void OnStudioModeSwitched(bool enabled);
|
||||||
|
void OnPreviewSceneChanged();
|
||||||
|
|
||||||
|
void OnExit();
|
||||||
|
|
||||||
|
static void OnTransitionBegin(void* param, calldata_t* data);
|
||||||
|
|
||||||
|
static void OnSceneReordered(void* param, calldata_t* data);
|
||||||
|
static void OnSceneItemAdd(void* param, calldata_t* data);
|
||||||
|
static void OnSceneItemDelete(void* param, calldata_t* data);
|
||||||
|
static void OnSceneItemVisibilityChanged(void* param, calldata_t* data);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WSEVENTS_H
|
230
src/WSRequestHandler.cpp
Normal file
230
src/WSRequestHandler.cpp
Normal file
@ -0,0 +1,230 @@
|
|||||||
|
/**
|
||||||
|
* obs-websocket
|
||||||
|
* Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
|
* Copyright (C) 2017 Mikhail Swift <https://github.com/mikhailswift>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <obs-data.h>
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
QHash<QString, void(*)(WSRequestHandler*)> WSRequestHandler::messageMap {
|
||||||
|
{ "GetVersion", WSRequestHandler::HandleGetVersion },
|
||||||
|
{ "GetAuthRequired", WSRequestHandler::HandleGetAuthRequired },
|
||||||
|
{ "Authenticate", WSRequestHandler::HandleAuthenticate },
|
||||||
|
|
||||||
|
{ "SetHeartbeat", WSRequestHandler::HandleSetHeartbeat },
|
||||||
|
|
||||||
|
{ "SetFilenameFormatting", WSRequestHandler::HandleSetFilenameFormatting },
|
||||||
|
{ "GetFilenameFormatting", WSRequestHandler::HandleGetFilenameFormatting },
|
||||||
|
|
||||||
|
{ "SetCurrentScene", WSRequestHandler::HandleSetCurrentScene },
|
||||||
|
{ "GetCurrentScene", WSRequestHandler::HandleGetCurrentScene },
|
||||||
|
{ "GetSceneList", WSRequestHandler::HandleGetSceneList },
|
||||||
|
|
||||||
|
{ "SetSourceRender", WSRequestHandler::HandleSetSceneItemRender }, // Retrocompat
|
||||||
|
{ "SetSceneItemRender", WSRequestHandler::HandleSetSceneItemRender },
|
||||||
|
{ "SetSceneItemPosition", WSRequestHandler::HandleSetSceneItemPosition },
|
||||||
|
{ "SetSceneItemTransform", WSRequestHandler::HandleSetSceneItemTransform },
|
||||||
|
{ "SetSceneItemCrop", WSRequestHandler::HandleSetSceneItemCrop },
|
||||||
|
{ "GetSceneItemProperties", WSRequestHandler::HandleGetSceneItemProperties },
|
||||||
|
{ "SetSceneItemProperties", WSRequestHandler::HandleSetSceneItemProperties },
|
||||||
|
{ "ResetSceneItem", WSRequestHandler::HandleResetSceneItem },
|
||||||
|
{ "DeleteSceneItem", WSRequestHandler::HandleDeleteSceneItem },
|
||||||
|
{ "DuplicateSceneItem", WSRequestHandler::HandleDuplicateSceneItem },
|
||||||
|
{ "ReorderSceneItems", WSRequestHandler::HandleReorderSceneItems },
|
||||||
|
|
||||||
|
{ "GetStreamingStatus", WSRequestHandler::HandleGetStreamingStatus },
|
||||||
|
{ "StartStopStreaming", WSRequestHandler::HandleStartStopStreaming },
|
||||||
|
{ "StartStopRecording", WSRequestHandler::HandleStartStopRecording },
|
||||||
|
{ "StartStreaming", WSRequestHandler::HandleStartStreaming },
|
||||||
|
{ "StopStreaming", WSRequestHandler::HandleStopStreaming },
|
||||||
|
{ "StartRecording", WSRequestHandler::HandleStartRecording },
|
||||||
|
{ "StopRecording", WSRequestHandler::HandleStopRecording },
|
||||||
|
|
||||||
|
{ "StartStopReplayBuffer", WSRequestHandler::HandleStartStopReplayBuffer },
|
||||||
|
{ "StartReplayBuffer", WSRequestHandler::HandleStartReplayBuffer },
|
||||||
|
{ "StopReplayBuffer", WSRequestHandler::HandleStopReplayBuffer },
|
||||||
|
{ "SaveReplayBuffer", WSRequestHandler::HandleSaveReplayBuffer },
|
||||||
|
|
||||||
|
{ "SetRecordingFolder", WSRequestHandler::HandleSetRecordingFolder },
|
||||||
|
{ "GetRecordingFolder", WSRequestHandler::HandleGetRecordingFolder },
|
||||||
|
|
||||||
|
{ "GetTransitionList", WSRequestHandler::HandleGetTransitionList },
|
||||||
|
{ "GetCurrentTransition", WSRequestHandler::HandleGetCurrentTransition },
|
||||||
|
{ "SetCurrentTransition", WSRequestHandler::HandleSetCurrentTransition },
|
||||||
|
{ "SetTransitionDuration", WSRequestHandler::HandleSetTransitionDuration },
|
||||||
|
{ "GetTransitionDuration", WSRequestHandler::HandleGetTransitionDuration },
|
||||||
|
|
||||||
|
{ "SetVolume", WSRequestHandler::HandleSetVolume },
|
||||||
|
{ "GetVolume", WSRequestHandler::HandleGetVolume },
|
||||||
|
{ "ToggleMute", WSRequestHandler::HandleToggleMute },
|
||||||
|
{ "SetMute", WSRequestHandler::HandleSetMute },
|
||||||
|
{ "GetMute", WSRequestHandler::HandleGetMute },
|
||||||
|
{ "SetSyncOffset", WSRequestHandler::HandleSetSyncOffset },
|
||||||
|
{ "GetSyncOffset", WSRequestHandler::HandleGetSyncOffset },
|
||||||
|
{ "GetSpecialSources", WSRequestHandler::HandleGetSpecialSources },
|
||||||
|
{ "GetSourcesList", WSRequestHandler::HandleGetSourcesList },
|
||||||
|
{ "GetSourceTypesList", WSRequestHandler::HandleGetSourceTypesList },
|
||||||
|
{ "GetSourceSettings", WSRequestHandler::HandleGetSourceSettings },
|
||||||
|
{ "SetSourceSettings", WSRequestHandler::HandleSetSourceSettings },
|
||||||
|
|
||||||
|
{ "GetSourceFilters", WSRequestHandler::HandleGetSourceFilters },
|
||||||
|
{ "AddFilterToSource", WSRequestHandler::HandleAddFilterToSource },
|
||||||
|
{ "RemoveFilterFromSource", WSRequestHandler::HandleRemoveFilterFromSource },
|
||||||
|
{ "ReorderSourceFilter", WSRequestHandler::HandleReorderSourceFilter },
|
||||||
|
{ "MoveSourceFilter", WSRequestHandler::HandleMoveSourceFilter },
|
||||||
|
{ "SetSourceFilterSettings", WSRequestHandler::HandleSetSourceFilterSettings },
|
||||||
|
|
||||||
|
{ "SetCurrentSceneCollection", WSRequestHandler::HandleSetCurrentSceneCollection },
|
||||||
|
{ "GetCurrentSceneCollection", WSRequestHandler::HandleGetCurrentSceneCollection },
|
||||||
|
{ "ListSceneCollections", WSRequestHandler::HandleListSceneCollections },
|
||||||
|
|
||||||
|
{ "SetCurrentProfile", WSRequestHandler::HandleSetCurrentProfile },
|
||||||
|
{ "GetCurrentProfile", WSRequestHandler::HandleGetCurrentProfile },
|
||||||
|
{ "ListProfiles", WSRequestHandler::HandleListProfiles },
|
||||||
|
|
||||||
|
{ "SetStreamSettings", WSRequestHandler::HandleSetStreamSettings },
|
||||||
|
{ "GetStreamSettings", WSRequestHandler::HandleGetStreamSettings },
|
||||||
|
{ "SaveStreamSettings", WSRequestHandler::HandleSaveStreamSettings },
|
||||||
|
|
||||||
|
{ "GetStudioModeStatus", WSRequestHandler::HandleGetStudioModeStatus },
|
||||||
|
{ "GetPreviewScene", WSRequestHandler::HandleGetPreviewScene },
|
||||||
|
{ "SetPreviewScene", WSRequestHandler::HandleSetPreviewScene },
|
||||||
|
{ "TransitionToProgram", WSRequestHandler::HandleTransitionToProgram },
|
||||||
|
{ "EnableStudioMode", WSRequestHandler::HandleEnableStudioMode },
|
||||||
|
{ "DisableStudioMode", WSRequestHandler::HandleDisableStudioMode },
|
||||||
|
{ "ToggleStudioMode", WSRequestHandler::HandleToggleStudioMode },
|
||||||
|
|
||||||
|
{ "SetTextGDIPlusProperties", WSRequestHandler::HandleSetTextGDIPlusProperties },
|
||||||
|
{ "GetTextGDIPlusProperties", WSRequestHandler::HandleGetTextGDIPlusProperties },
|
||||||
|
|
||||||
|
{ "SetTextFreetype2Properties", WSRequestHandler::HandleSetTextFreetype2Properties },
|
||||||
|
{ "GetTextFreetype2Properties", WSRequestHandler::HandleGetTextFreetype2Properties },
|
||||||
|
|
||||||
|
{ "GetBrowserSourceProperties", WSRequestHandler::HandleGetBrowserSourceProperties },
|
||||||
|
{ "SetBrowserSourceProperties", WSRequestHandler::HandleSetBrowserSourceProperties }
|
||||||
|
};
|
||||||
|
|
||||||
|
QSet<QString> WSRequestHandler::authNotRequired {
|
||||||
|
"GetVersion",
|
||||||
|
"GetAuthRequired",
|
||||||
|
"Authenticate"
|
||||||
|
};
|
||||||
|
|
||||||
|
WSRequestHandler::WSRequestHandler(QWebSocket* client) :
|
||||||
|
_messageId(0),
|
||||||
|
_requestType(""),
|
||||||
|
data(nullptr),
|
||||||
|
_client(client)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSRequestHandler::processIncomingMessage(QString textMessage) {
|
||||||
|
QByteArray msgData = textMessage.toUtf8();
|
||||||
|
const char* msg = msgData.constData();
|
||||||
|
|
||||||
|
data = obs_data_create_from_json(msg);
|
||||||
|
if (!data) {
|
||||||
|
if (!msg)
|
||||||
|
msg = "<null pointer>";
|
||||||
|
|
||||||
|
blog(LOG_ERROR, "invalid JSON payload received for '%s'", msg);
|
||||||
|
SendErrorResponse("invalid JSON payload");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Config::Current()->DebugEnabled) {
|
||||||
|
blog(LOG_DEBUG, "Request >> '%s'", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasField("request-type")
|
||||||
|
|| !hasField("message-id"))
|
||||||
|
{
|
||||||
|
SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_requestType = obs_data_get_string(data, "request-type");
|
||||||
|
_messageId = obs_data_get_string(data, "message-id");
|
||||||
|
|
||||||
|
if (Config::Current()->AuthRequired
|
||||||
|
&& (_client->property(PROP_AUTHENTICATED).toBool() == false)
|
||||||
|
&& (authNotRequired.find(_requestType) == authNotRequired.end()))
|
||||||
|
{
|
||||||
|
SendErrorResponse("Not Authenticated");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void (*handlerFunc)(WSRequestHandler*) = (messageMap[_requestType]);
|
||||||
|
|
||||||
|
if (handlerFunc != nullptr)
|
||||||
|
handlerFunc(this);
|
||||||
|
else
|
||||||
|
SendErrorResponse("invalid request type");
|
||||||
|
}
|
||||||
|
|
||||||
|
WSRequestHandler::~WSRequestHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSRequestHandler::SendOKResponse(obs_data_t* additionalFields) {
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "status", "ok");
|
||||||
|
obs_data_set_string(response, "message-id", _messageId);
|
||||||
|
|
||||||
|
if (additionalFields)
|
||||||
|
obs_data_apply(response, additionalFields);
|
||||||
|
|
||||||
|
SendResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSRequestHandler::SendErrorResponse(const char* errorMessage) {
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "status", "error");
|
||||||
|
obs_data_set_string(response, "error", errorMessage);
|
||||||
|
obs_data_set_string(response, "message-id", _messageId);
|
||||||
|
|
||||||
|
SendResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSRequestHandler::SendErrorResponse(obs_data_t* additionalFields) {
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "status", "error");
|
||||||
|
obs_data_set_string(response, "message-id", _messageId);
|
||||||
|
|
||||||
|
if (additionalFields)
|
||||||
|
obs_data_set_obj(response, "error", additionalFields);
|
||||||
|
|
||||||
|
SendResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSRequestHandler::SendResponse(obs_data_t* response) {
|
||||||
|
QString json = obs_data_get_json(response);
|
||||||
|
_client->sendTextMessage(json);
|
||||||
|
|
||||||
|
if (Config::Current()->DebugEnabled)
|
||||||
|
blog(LOG_DEBUG, "Response << '%s'", json.toUtf8().constData());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WSRequestHandler::hasField(QString name) {
|
||||||
|
if (!data || name.isEmpty() || name.isNull())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return obs_data_has_user_value(data, name.toUtf8());
|
||||||
|
}
|
153
src/WSRequestHandler.h
Normal file
153
src/WSRequestHandler.h
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
/*
|
||||||
|
obs-websocket
|
||||||
|
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
|
Copyright (C) 2017 Mikhail Swift <https://github.com/mikhailswift>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WSREQUESTHANDLER_H
|
||||||
|
#define WSREQUESTHANDLER_H
|
||||||
|
|
||||||
|
#include <QHash>
|
||||||
|
#include <QSet>
|
||||||
|
#include <QWebSocket>
|
||||||
|
#include <QWebSocketServer>
|
||||||
|
|
||||||
|
#include <obs.hpp>
|
||||||
|
#include <obs-frontend-api.h>
|
||||||
|
|
||||||
|
#include "obs-websocket.h"
|
||||||
|
|
||||||
|
class WSRequestHandler : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit WSRequestHandler(QWebSocket* client);
|
||||||
|
~WSRequestHandler();
|
||||||
|
void processIncomingMessage(QString textMessage);
|
||||||
|
bool hasField(QString name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QWebSocket* _client;
|
||||||
|
const char* _messageId;
|
||||||
|
const char* _requestType;
|
||||||
|
OBSDataAutoRelease data;
|
||||||
|
|
||||||
|
void SendOKResponse(obs_data_t* additionalFields = NULL);
|
||||||
|
void SendErrorResponse(const char* errorMessage);
|
||||||
|
void SendErrorResponse(obs_data_t* additionalFields = NULL);
|
||||||
|
void SendResponse(obs_data_t* response);
|
||||||
|
|
||||||
|
static QHash<QString, void(*)(WSRequestHandler*)> messageMap;
|
||||||
|
static QSet<QString> authNotRequired;
|
||||||
|
|
||||||
|
static void HandleGetVersion(WSRequestHandler* req);
|
||||||
|
static void HandleGetAuthRequired(WSRequestHandler* req);
|
||||||
|
static void HandleAuthenticate(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetHeartbeat(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetFilenameFormatting(WSRequestHandler* req);
|
||||||
|
static void HandleGetFilenameFormatting(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetCurrentScene(WSRequestHandler* req);
|
||||||
|
static void HandleGetCurrentScene(WSRequestHandler* req);
|
||||||
|
static void HandleGetSceneList(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetSceneItemRender(WSRequestHandler* req);
|
||||||
|
static void HandleSetSceneItemPosition(WSRequestHandler* req);
|
||||||
|
static void HandleSetSceneItemTransform(WSRequestHandler* req);
|
||||||
|
static void HandleSetSceneItemCrop(WSRequestHandler* req);
|
||||||
|
static void HandleGetSceneItemProperties(WSRequestHandler* req);
|
||||||
|
static void HandleSetSceneItemProperties(WSRequestHandler* req);
|
||||||
|
static void HandleResetSceneItem(WSRequestHandler* req);
|
||||||
|
static void HandleDuplicateSceneItem(WSRequestHandler* req);
|
||||||
|
static void HandleDeleteSceneItem(WSRequestHandler* req);
|
||||||
|
static void HandleReorderSceneItems(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleGetStreamingStatus(WSRequestHandler* req);
|
||||||
|
static void HandleStartStopStreaming(WSRequestHandler* req);
|
||||||
|
static void HandleStartStopRecording(WSRequestHandler* req);
|
||||||
|
static void HandleStartStreaming(WSRequestHandler* req);
|
||||||
|
static void HandleStopStreaming(WSRequestHandler* req);
|
||||||
|
static void HandleStartRecording(WSRequestHandler* req);
|
||||||
|
static void HandleStopRecording(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleStartStopReplayBuffer(WSRequestHandler* req);
|
||||||
|
static void HandleStartReplayBuffer(WSRequestHandler* req);
|
||||||
|
static void HandleStopReplayBuffer(WSRequestHandler* req);
|
||||||
|
static void HandleSaveReplayBuffer(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetRecordingFolder(WSRequestHandler* req);
|
||||||
|
static void HandleGetRecordingFolder(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleGetTransitionList(WSRequestHandler* req);
|
||||||
|
static void HandleGetCurrentTransition(WSRequestHandler* req);
|
||||||
|
static void HandleSetCurrentTransition(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetVolume(WSRequestHandler* req);
|
||||||
|
static void HandleGetVolume(WSRequestHandler* req);
|
||||||
|
static void HandleToggleMute(WSRequestHandler* req);
|
||||||
|
static void HandleSetMute(WSRequestHandler* req);
|
||||||
|
static void HandleGetMute(WSRequestHandler* req);
|
||||||
|
static void HandleSetSyncOffset(WSRequestHandler* req);
|
||||||
|
static void HandleGetSyncOffset(WSRequestHandler* req);
|
||||||
|
static void HandleGetSpecialSources(WSRequestHandler* req);
|
||||||
|
static void HandleGetSourcesList(WSRequestHandler* req);
|
||||||
|
static void HandleGetSourceTypesList(WSRequestHandler* req);
|
||||||
|
static void HandleGetSourceSettings(WSRequestHandler* req);
|
||||||
|
static void HandleSetSourceSettings(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleGetSourceFilters(WSRequestHandler* req);
|
||||||
|
static void HandleAddFilterToSource(WSRequestHandler* req);
|
||||||
|
static void HandleRemoveFilterFromSource(WSRequestHandler* req);
|
||||||
|
static void HandleReorderSourceFilter(WSRequestHandler* req);
|
||||||
|
static void HandleMoveSourceFilter(WSRequestHandler* req);
|
||||||
|
static void HandleSetSourceFilterSettings(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetCurrentSceneCollection(WSRequestHandler* req);
|
||||||
|
static void HandleGetCurrentSceneCollection(WSRequestHandler* req);
|
||||||
|
static void HandleListSceneCollections(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetCurrentProfile(WSRequestHandler* req);
|
||||||
|
static void HandleGetCurrentProfile(WSRequestHandler* req);
|
||||||
|
static void HandleListProfiles(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetStreamSettings(WSRequestHandler* req);
|
||||||
|
static void HandleGetStreamSettings(WSRequestHandler* req);
|
||||||
|
static void HandleSaveStreamSettings(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetTransitionDuration(WSRequestHandler* req);
|
||||||
|
static void HandleGetTransitionDuration(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleGetStudioModeStatus(WSRequestHandler* req);
|
||||||
|
static void HandleGetPreviewScene(WSRequestHandler* req);
|
||||||
|
static void HandleSetPreviewScene(WSRequestHandler* req);
|
||||||
|
static void HandleTransitionToProgram(WSRequestHandler* req);
|
||||||
|
static void HandleEnableStudioMode(WSRequestHandler* req);
|
||||||
|
static void HandleDisableStudioMode(WSRequestHandler* req);
|
||||||
|
static void HandleToggleStudioMode(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetTextGDIPlusProperties(WSRequestHandler* req);
|
||||||
|
static void HandleGetTextGDIPlusProperties(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetTextFreetype2Properties(WSRequestHandler* req);
|
||||||
|
static void HandleGetTextFreetype2Properties(WSRequestHandler* req);
|
||||||
|
|
||||||
|
static void HandleSetBrowserSourceProperties(WSRequestHandler* req);
|
||||||
|
static void HandleGetBrowserSourceProperties(WSRequestHandler* req);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WSPROTOCOL_H
|
168
src/WSRequestHandler_General.cpp
Normal file
168
src/WSRequestHandler_General.cpp
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
#include "WSEvents.h"
|
||||||
|
|
||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the latest version of the plugin and the API.
|
||||||
|
*
|
||||||
|
* @return {double} `version` OBSRemote compatible API version. Fixed to 1.1 for retrocompatibility.
|
||||||
|
* @return {String} `obs-websocket-version` obs-websocket plugin version.
|
||||||
|
* @return {String} `obs-studio-version` OBS Studio program version.
|
||||||
|
* @return {String} `available-requests` List of available request types, formatted as a comma-separated list string (e.g. : "Method1,Method2,Method3").
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetVersion
|
||||||
|
* @category general
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetVersion(WSRequestHandler* req) {
|
||||||
|
QString obsVersion = Utils::OBSVersionString();
|
||||||
|
|
||||||
|
QList<QString> names = req->messageMap.keys();
|
||||||
|
names.sort(Qt::CaseInsensitive);
|
||||||
|
|
||||||
|
// (Palakis) OBS' data arrays only support object arrays, so I improvised.
|
||||||
|
QString requests;
|
||||||
|
requests += names.takeFirst();
|
||||||
|
for (QString reqName : names) {
|
||||||
|
requests += ("," + reqName);
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_string(data, "obs-websocket-version", OBS_WEBSOCKET_VERSION);
|
||||||
|
obs_data_set_string(data, "obs-studio-version", obsVersion.toUtf8());
|
||||||
|
obs_data_set_string(data, "available-requests", requests.toUtf8());
|
||||||
|
|
||||||
|
req->SendOKResponse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells the client if authentication is required. If so, returns authentication parameters `challenge`
|
||||||
|
* and `salt` (see "Authentication" for more information).
|
||||||
|
*
|
||||||
|
* @return {boolean} `authRequired` Indicates whether authentication is required.
|
||||||
|
* @return {String (optional)} `challenge`
|
||||||
|
* @return {String (optional)} `salt`
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetAuthRequired
|
||||||
|
* @category general
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetAuthRequired(WSRequestHandler* req) {
|
||||||
|
bool authRequired = Config::Current()->AuthRequired;
|
||||||
|
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_bool(data, "authRequired", authRequired);
|
||||||
|
|
||||||
|
if (authRequired) {
|
||||||
|
obs_data_set_string(data, "challenge",
|
||||||
|
Config::Current()->SessionChallenge.toUtf8());
|
||||||
|
obs_data_set_string(data, "salt",
|
||||||
|
Config::Current()->Salt.toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
|
req->SendOKResponse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to authenticate the client to the server.
|
||||||
|
*
|
||||||
|
* @param {String} `auth` Response to the auth challenge (see "Authentication" for more information).
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name Authenticate
|
||||||
|
* @category general
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("auth")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString auth = obs_data_get_string(req->data, "auth");
|
||||||
|
if (auth.isEmpty()) {
|
||||||
|
req->SendErrorResponse("auth not specified!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((req->_client->property(PROP_AUTHENTICATED).toBool() == false)
|
||||||
|
&& Config::Current()->CheckAuth(auth))
|
||||||
|
{
|
||||||
|
req->_client->setProperty(PROP_AUTHENTICATED, true);
|
||||||
|
req->SendOKResponse();
|
||||||
|
} else {
|
||||||
|
req->SendErrorResponse("Authentication Failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/disable sending of the Heartbeat event
|
||||||
|
*
|
||||||
|
* @param {boolean} `enable` Starts/Stops emitting heartbeat messages
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetHeartbeat
|
||||||
|
* @category general
|
||||||
|
* @since 4.3.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetHeartbeat(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("enable")) {
|
||||||
|
req->SendErrorResponse("Heartbeat <enable> parameter missing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WSEvents::Instance->HeartbeatIsActive =
|
||||||
|
obs_data_get_bool(req->data, "enable");
|
||||||
|
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_bool(response, "enable",
|
||||||
|
WSEvents::Instance->HeartbeatIsActive);
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the filename formatting string
|
||||||
|
*
|
||||||
|
* @param {String} `filename-formatting` Filename formatting string to set.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetFilenameFormatting
|
||||||
|
* @category general
|
||||||
|
* @since 4.3.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetFilenameFormatting(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("filename-formatting")) {
|
||||||
|
req->SendErrorResponse("<filename-formatting> parameter missing");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString filenameFormatting = obs_data_get_string(req->data, "filename-formatting");
|
||||||
|
if (!filenameFormatting.isEmpty()) {
|
||||||
|
Utils::SetFilenameFormatting(filenameFormatting.toUtf8());
|
||||||
|
req->SendOKResponse();
|
||||||
|
} else {
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the filename formatting string
|
||||||
|
*
|
||||||
|
* @return {String} `filename-formatting` Current filename formatting string.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetFilenameFormatting
|
||||||
|
* @category general
|
||||||
|
* @since 4.3.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetFilenameFormatting(WSRequestHandler* req) {
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "filename-formatting", Utils::GetFilenameFormatting());
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
70
src/WSRequestHandler_Profiles.cpp
Normal file
70
src/WSRequestHandler_Profiles.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include <QString>
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the currently active profile.
|
||||||
|
*
|
||||||
|
* @param {String} `profile-name` Name of the desired profile.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetCurrentProfile
|
||||||
|
* @category profiles
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetCurrentProfile(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("profile-name")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString profileName = obs_data_get_string(req->data, "profile-name");
|
||||||
|
if (!profileName.isEmpty()) {
|
||||||
|
// TODO : check if profile exists
|
||||||
|
obs_frontend_set_current_profile(profileName.toUtf8());
|
||||||
|
req->SendOKResponse();
|
||||||
|
} else {
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the current profile.
|
||||||
|
*
|
||||||
|
* @return {String} `profile-name` Name of the currently active profile.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetCurrentProfile
|
||||||
|
* @category profiles
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetCurrentProfile(WSRequestHandler* req) {
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "profile-name",
|
||||||
|
obs_frontend_get_current_profile());
|
||||||
|
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of available profiles.
|
||||||
|
*
|
||||||
|
* @return {Array<Object>} `profiles` List of available profiles.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name ListProfiles
|
||||||
|
* @category profiles
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleListProfiles(WSRequestHandler* req) {
|
||||||
|
char** profiles = obs_frontend_get_profiles();
|
||||||
|
OBSDataArrayAutoRelease list =
|
||||||
|
Utils::StringListToArray(profiles, "profile-name");
|
||||||
|
bfree(profiles);
|
||||||
|
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_array(response, "profiles", list);
|
||||||
|
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
100
src/WSRequestHandler_Recording.cpp
Normal file
100
src/WSRequestHandler_Recording.cpp
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
#include <QString>
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle recording on or off.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name StartStopRecording
|
||||||
|
* @category recording
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleStartStopRecording(WSRequestHandler* req) {
|
||||||
|
if (obs_frontend_recording_active())
|
||||||
|
obs_frontend_recording_stop();
|
||||||
|
else
|
||||||
|
obs_frontend_recording_start();
|
||||||
|
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start recording.
|
||||||
|
* Will return an `error` if recording is already active.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name StartRecording
|
||||||
|
* @category recording
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleStartRecording(WSRequestHandler* req) {
|
||||||
|
if (obs_frontend_recording_active() == false) {
|
||||||
|
obs_frontend_recording_start();
|
||||||
|
req->SendOKResponse();
|
||||||
|
} else {
|
||||||
|
req->SendErrorResponse("recording already active");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop recording.
|
||||||
|
* Will return an `error` if recording is not active.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name StopRecording
|
||||||
|
* @category recording
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleStopRecording(WSRequestHandler* req) {
|
||||||
|
if (obs_frontend_recording_active() == true) {
|
||||||
|
obs_frontend_recording_stop();
|
||||||
|
req->SendOKResponse();
|
||||||
|
} else {
|
||||||
|
req->SendErrorResponse("recording not active");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the current recording folder.
|
||||||
|
*
|
||||||
|
* @param {String} `rec-folder` Path of the recording folder.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetRecordingFolder
|
||||||
|
* @category recording
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetRecordingFolder(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("rec-folder")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* newRecFolder = obs_data_get_string(req->data, "rec-folder");
|
||||||
|
bool success = Utils::SetRecordingFolder(newRecFolder);
|
||||||
|
if (success)
|
||||||
|
req->SendOKResponse();
|
||||||
|
else
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the path of the current recording folder.
|
||||||
|
*
|
||||||
|
* @return {String} `rec-folder` Path of the recording folder.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetRecordingFolder
|
||||||
|
* @category recording
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetRecordingFolder(WSRequestHandler* req) {
|
||||||
|
const char* recFolder = Utils::GetRecordingFolder();
|
||||||
|
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "rec-folder", recFolder);
|
||||||
|
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
92
src/WSRequestHandler_ReplayBuffer.cpp
Normal file
92
src/WSRequestHandler_ReplayBuffer.cpp
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#include <QString>
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle the Replay Buffer on/off.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name StartStopReplayBuffer
|
||||||
|
* @category replay buffer
|
||||||
|
* @since 4.2.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleStartStopReplayBuffer(WSRequestHandler* req) {
|
||||||
|
if (obs_frontend_replay_buffer_active()) {
|
||||||
|
obs_frontend_replay_buffer_stop();
|
||||||
|
} else {
|
||||||
|
Utils::StartReplayBuffer();
|
||||||
|
}
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start recording into the Replay Buffer.
|
||||||
|
* Will return an `error` if the Replay Buffer is already active or if the
|
||||||
|
* "Save Replay Buffer" hotkey is not set in OBS' settings.
|
||||||
|
* Setting this hotkey is mandatory, even when triggering saves only
|
||||||
|
* through obs-websocket.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name StartReplayBuffer
|
||||||
|
* @category replay buffer
|
||||||
|
* @since 4.2.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleStartReplayBuffer(WSRequestHandler* req) {
|
||||||
|
if (!Utils::ReplayBufferEnabled()) {
|
||||||
|
req->SendErrorResponse("replay buffer disabled in settings");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obs_frontend_replay_buffer_active() == true) {
|
||||||
|
req->SendErrorResponse("replay buffer already active");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils::StartReplayBuffer();
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop recording into the Replay Buffer.
|
||||||
|
* Will return an `error` if the Replay Buffer is not active.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name StopReplayBuffer
|
||||||
|
* @category replay buffer
|
||||||
|
* @since 4.2.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleStopReplayBuffer(WSRequestHandler* req) {
|
||||||
|
if (obs_frontend_replay_buffer_active() == true) {
|
||||||
|
obs_frontend_replay_buffer_stop();
|
||||||
|
req->SendOKResponse();
|
||||||
|
} else {
|
||||||
|
req->SendErrorResponse("replay buffer not active");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush and save the contents of the Replay Buffer to disk. This is
|
||||||
|
* basically the same as triggering the "Save Replay Buffer" hotkey.
|
||||||
|
* Will return an `error` if the Replay Buffer is not active.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SaveReplayBuffer
|
||||||
|
* @category replay buffer
|
||||||
|
* @since 4.2.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSaveReplayBuffer(WSRequestHandler* req) {
|
||||||
|
if (!obs_frontend_replay_buffer_active()) {
|
||||||
|
req->SendErrorResponse("replay buffer not active");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSOutputAutoRelease replayOutput = obs_frontend_get_replay_buffer_output();
|
||||||
|
|
||||||
|
calldata_t cd = { 0 };
|
||||||
|
proc_handler_t* ph = obs_output_get_proc_handler(replayOutput);
|
||||||
|
proc_handler_call(ph, "save", &cd);
|
||||||
|
calldata_free(&cd);
|
||||||
|
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
70
src/WSRequestHandler_SceneCollections.cpp
Normal file
70
src/WSRequestHandler_SceneCollections.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include <QString>
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the active scene collection.
|
||||||
|
*
|
||||||
|
* @param {String} `sc-name` Name of the desired scene collection.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetCurrentSceneCollection
|
||||||
|
* @category scene collections
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetCurrentSceneCollection(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("sc-name")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString sceneCollection = obs_data_get_string(req->data, "sc-name");
|
||||||
|
if (!sceneCollection.isEmpty()) {
|
||||||
|
// TODO : Check if specified profile exists and if changing is allowed
|
||||||
|
obs_frontend_set_current_scene_collection(sceneCollection.toUtf8());
|
||||||
|
req->SendOKResponse();
|
||||||
|
} else {
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the current scene collection.
|
||||||
|
*
|
||||||
|
* @return {String} `sc-name` Name of the currently active scene collection.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetCurrentSceneCollection
|
||||||
|
* @category scene collections
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetCurrentSceneCollection(WSRequestHandler* req) {
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "sc-name",
|
||||||
|
obs_frontend_get_current_scene_collection());
|
||||||
|
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List available scene collections
|
||||||
|
*
|
||||||
|
* @return {Array<String>} `scene-collections` Scene collections list
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name ListSceneCollections
|
||||||
|
* @category scene collections
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleListSceneCollections(WSRequestHandler* req) {
|
||||||
|
char** sceneCollections = obs_frontend_get_scene_collections();
|
||||||
|
OBSDataArrayAutoRelease list =
|
||||||
|
Utils::StringListToArray(sceneCollections, "sc-name");
|
||||||
|
bfree(sceneCollections);
|
||||||
|
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_array(response, "scene-collections", list);
|
||||||
|
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
689
src/WSRequestHandler_SceneItems.cpp
Normal file
689
src/WSRequestHandler_SceneItems.cpp
Normal file
@ -0,0 +1,689 @@
|
|||||||
|
#include <QString>
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the scene specific properties of the specified source item.
|
||||||
|
*
|
||||||
|
* @param {String (optional)} `scene-name` the name of the scene that the source item belongs to. Defaults to the current scene.
|
||||||
|
* @param {String} `item` The name of the source.
|
||||||
|
*
|
||||||
|
* @return {String} `name` The name of the source.
|
||||||
|
* @return {int} `position.x` The x position of the source from the left.
|
||||||
|
* @return {int} `position.y` The y position of the source from the top.
|
||||||
|
* @return {int} `position.alignment` The point on the source that the item is manipulated from.
|
||||||
|
* @return {double} `rotation` The clockwise rotation of the item in degrees around the point of alignment.
|
||||||
|
* @return {double} `scale.x` The x-scale factor of the source.
|
||||||
|
* @return {double} `scale.y` The y-scale factor of the source.
|
||||||
|
* @return {int} `crop.top` The number of pixels cropped off the top of the source before scaling.
|
||||||
|
* @return {int} `crop.right` The number of pixels cropped off the right of the source before scaling.
|
||||||
|
* @return {int} `crop.bottom` The number of pixels cropped off the bottom of the source before scaling.
|
||||||
|
* @return {int} `crop.left` The number of pixels cropped off the left of the source before scaling.
|
||||||
|
* @return {bool} `visible` If the source is visible.
|
||||||
|
* @return {String} `bounds.type` Type of bounding box.
|
||||||
|
* @return {int} `bounds.alignment` Alignment of the bounding box.
|
||||||
|
* @return {double} `bounds.x` Width of the bounding box.
|
||||||
|
* @return {double} `bounds.y` Height of the bounding box.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetSceneItemProperties
|
||||||
|
* @category scene items
|
||||||
|
* @since 4.3.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetSceneItemProperties(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("item")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString itemName = obs_data_get_string(req->data, "item");
|
||||||
|
if (itemName.isEmpty()) {
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString sceneName = obs_data_get_string(req->data, "scene-name");
|
||||||
|
OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName);
|
||||||
|
if (!scene) {
|
||||||
|
req->SendErrorResponse("requested scene doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSSceneItemAutoRelease sceneItem =
|
||||||
|
Utils::GetSceneItemFromName(scene, itemName);
|
||||||
|
if (!sceneItem) {
|
||||||
|
req->SendErrorResponse("specified scene item doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_string(data, "name", itemName.toUtf8());
|
||||||
|
|
||||||
|
OBSDataAutoRelease posData = obs_data_create();
|
||||||
|
vec2 pos;
|
||||||
|
obs_sceneitem_get_pos(sceneItem, &pos);
|
||||||
|
obs_data_set_double(posData, "x", pos.x);
|
||||||
|
obs_data_set_double(posData, "y", pos.y);
|
||||||
|
obs_data_set_int(posData, "alignment", obs_sceneitem_get_alignment(sceneItem));
|
||||||
|
obs_data_set_obj(data, "position", posData);
|
||||||
|
|
||||||
|
obs_data_set_double(data, "rotation", obs_sceneitem_get_rot(sceneItem));
|
||||||
|
|
||||||
|
OBSDataAutoRelease scaleData = obs_data_create();
|
||||||
|
vec2 scale;
|
||||||
|
obs_sceneitem_get_scale(sceneItem, &scale);
|
||||||
|
obs_data_set_double(scaleData, "x", scale.x);
|
||||||
|
obs_data_set_double(scaleData, "y", scale.y);
|
||||||
|
obs_data_set_obj(data, "scale", scaleData);
|
||||||
|
|
||||||
|
OBSDataAutoRelease cropData = obs_data_create();
|
||||||
|
obs_sceneitem_crop crop;
|
||||||
|
obs_sceneitem_get_crop(sceneItem, &crop);
|
||||||
|
obs_data_set_int(cropData, "left", crop.left);
|
||||||
|
obs_data_set_int(cropData, "top", crop.top);
|
||||||
|
obs_data_set_int(cropData, "right", crop.right);
|
||||||
|
obs_data_set_int(cropData, "bottom", crop.bottom);
|
||||||
|
obs_data_set_obj(data, "crop", cropData);
|
||||||
|
|
||||||
|
obs_data_set_bool(data, "visible", obs_sceneitem_visible(sceneItem));
|
||||||
|
|
||||||
|
OBSDataAutoRelease boundsData = obs_data_create();
|
||||||
|
obs_bounds_type boundsType = obs_sceneitem_get_bounds_type(sceneItem);
|
||||||
|
if (boundsType == OBS_BOUNDS_NONE) {
|
||||||
|
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_NONE");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch (boundsType) {
|
||||||
|
case OBS_BOUNDS_STRETCH: {
|
||||||
|
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_STRETCH");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OBS_BOUNDS_SCALE_INNER: {
|
||||||
|
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_INNER");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OBS_BOUNDS_SCALE_OUTER: {
|
||||||
|
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_OUTER");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OBS_BOUNDS_SCALE_TO_WIDTH: {
|
||||||
|
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_TO_WIDTH");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OBS_BOUNDS_SCALE_TO_HEIGHT: {
|
||||||
|
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_SCALE_TO_HEIGHT");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case OBS_BOUNDS_MAX_ONLY: {
|
||||||
|
obs_data_set_string(boundsData, "type", "OBS_BOUNDS_MAX_ONLY");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
obs_data_set_int(boundsData, "alignment", obs_sceneitem_get_bounds_alignment(sceneItem));
|
||||||
|
vec2 bounds;
|
||||||
|
obs_sceneitem_get_bounds(sceneItem, &bounds);
|
||||||
|
obs_data_set_double(boundsData, "x", bounds.x);
|
||||||
|
obs_data_set_double(boundsData, "y", bounds.y);
|
||||||
|
}
|
||||||
|
obs_data_set_obj(data, "bounds", boundsData);
|
||||||
|
|
||||||
|
req->SendOKResponse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the scene specific properties of a source. Unspecified properties will remain unchanged.
|
||||||
|
*
|
||||||
|
* @param {String (optional)} `scene-name` the name of the scene that the source item belongs to. Defaults to the current scene.
|
||||||
|
* @param {String} `item` The name of the source.
|
||||||
|
* @param {int} `position.x` The new x position of the source.
|
||||||
|
* @param {int} `position.y` The new y position of the source.
|
||||||
|
* @param {int} `position.alignment` The new alignment of the source.
|
||||||
|
* @param {double} `rotation` The new clockwise rotation of the item in degrees.
|
||||||
|
* @param {double} `scale.x` The new x scale of the item.
|
||||||
|
* @param {double} `scale.y` The new y scale of the item.
|
||||||
|
* @param {int} `crop.top` The new amount of pixels cropped off the top of the source before scaling.
|
||||||
|
* @param {int} `crop.bottom` The new amount of pixels cropped off the bottom of the source before scaling.
|
||||||
|
* @param {int} `crop.left` The new amount of pixels cropped off the left of the source before scaling.
|
||||||
|
* @param {int} `crop.right` The new amount of pixels cropped off the right of the source before scaling.
|
||||||
|
* @param {bool} `visible` The new visibility of the source. 'true' shows source, 'false' hides source.
|
||||||
|
* @param {String} `bounds.type` The new bounds type of the source.
|
||||||
|
* @param {int} `bounds.alignment` The new alignment of the bounding box. (0-2, 4-6, 8-10)
|
||||||
|
* @param {double} `bounds.x` The new width of the bounding box.
|
||||||
|
* @param {double} `bounds.y` The new height of the bounding box.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetSceneItemProperties
|
||||||
|
* @category scene items
|
||||||
|
* @since 4.3.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetSceneItemProperties(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("item")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString itemName = obs_data_get_string(req->data, "item");
|
||||||
|
if (itemName.isEmpty()) {
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString sceneName = obs_data_get_string(req->data, "scene-name");
|
||||||
|
OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName);
|
||||||
|
if (!scene) {
|
||||||
|
req->SendErrorResponse("requested scene doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSSceneItemAutoRelease sceneItem =
|
||||||
|
Utils::GetSceneItemFromName(scene, itemName);
|
||||||
|
if (!sceneItem) {
|
||||||
|
req->SendErrorResponse("specified scene item doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool badRequest = false;
|
||||||
|
OBSDataAutoRelease errorMessage = obs_data_create();
|
||||||
|
|
||||||
|
if (req->hasField("position")) {
|
||||||
|
vec2 oldPosition;
|
||||||
|
OBSDataAutoRelease positionError = obs_data_create();
|
||||||
|
obs_sceneitem_get_pos(sceneItem, &oldPosition);
|
||||||
|
OBSDataAutoRelease reqPosition = obs_data_get_obj(req->data, "position");
|
||||||
|
vec2 newPosition = oldPosition;
|
||||||
|
if (obs_data_has_user_value(reqPosition, "x")) {
|
||||||
|
newPosition.x = obs_data_get_int(reqPosition, "x");
|
||||||
|
}
|
||||||
|
if (obs_data_has_user_value(reqPosition, "y")) {
|
||||||
|
newPosition.y = obs_data_get_int(reqPosition, "y");
|
||||||
|
}
|
||||||
|
if (obs_data_has_user_value(reqPosition, "alignment")) {
|
||||||
|
const uint32_t alignment = obs_data_get_int(reqPosition, "alignment");
|
||||||
|
if (Utils::IsValidAlignment(alignment)) {
|
||||||
|
obs_sceneitem_set_alignment(sceneItem, alignment);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
badRequest = true;
|
||||||
|
obs_data_set_string(positionError, "alignment", "invalid");
|
||||||
|
obs_data_set_obj(errorMessage, "position", positionError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
obs_sceneitem_set_pos(sceneItem, &newPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req->hasField("rotation")) {
|
||||||
|
obs_sceneitem_set_rot(sceneItem, (float)obs_data_get_double(req->data, "rotation"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req->hasField("scale")) {
|
||||||
|
vec2 oldScale;
|
||||||
|
obs_sceneitem_get_scale(sceneItem, &oldScale);
|
||||||
|
OBSDataAutoRelease reqScale = obs_data_get_obj(req->data, "scale");
|
||||||
|
vec2 newScale = oldScale;
|
||||||
|
if (obs_data_has_user_value(reqScale, "x")) {
|
||||||
|
newScale.x = obs_data_get_double(reqScale, "x");
|
||||||
|
}
|
||||||
|
if (obs_data_has_user_value(reqScale, "y")) {
|
||||||
|
newScale.y = obs_data_get_double(reqScale, "y");
|
||||||
|
}
|
||||||
|
obs_sceneitem_set_scale(sceneItem, &newScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req->hasField("crop")) {
|
||||||
|
obs_sceneitem_crop oldCrop;
|
||||||
|
obs_sceneitem_get_crop(sceneItem, &oldCrop);
|
||||||
|
OBSDataAutoRelease reqCrop = obs_data_get_obj(req->data, "crop");
|
||||||
|
obs_sceneitem_crop newCrop = oldCrop;
|
||||||
|
if (obs_data_has_user_value(reqCrop, "top")) {
|
||||||
|
newCrop.top = obs_data_get_int(reqCrop, "top");
|
||||||
|
}
|
||||||
|
if (obs_data_has_user_value(reqCrop, "right")) {
|
||||||
|
newCrop.right = obs_data_get_int(reqCrop, "right");
|
||||||
|
}
|
||||||
|
if (obs_data_has_user_value(reqCrop, "bottom")) {
|
||||||
|
newCrop.bottom = obs_data_get_int(reqCrop, "bottom");
|
||||||
|
}
|
||||||
|
if (obs_data_has_user_value(reqCrop, "left")) {
|
||||||
|
newCrop.left = obs_data_get_int(reqCrop, "left");
|
||||||
|
}
|
||||||
|
obs_sceneitem_set_crop(sceneItem, &newCrop);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req->hasField("visible")) {
|
||||||
|
obs_sceneitem_set_visible(sceneItem, obs_data_get_bool(req->data, "visible"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req->hasField("bounds")) {
|
||||||
|
bool badBounds = false;
|
||||||
|
OBSDataAutoRelease boundsError = obs_data_create();
|
||||||
|
OBSDataAutoRelease reqBounds = obs_data_get_obj(req->data, "bounds");
|
||||||
|
if (obs_data_has_user_value(reqBounds, "type")) {
|
||||||
|
const char* newBoundsType = obs_data_get_string(reqBounds, "type");
|
||||||
|
if (newBoundsType == "OBS_BOUNDS_NONE") {
|
||||||
|
obs_sceneitem_set_bounds_type(sceneItem, OBS_BOUNDS_NONE);
|
||||||
|
}
|
||||||
|
else if (newBoundsType == "OBS_BOUNDS_STRETCH") {
|
||||||
|
obs_sceneitem_set_bounds_type(sceneItem, OBS_BOUNDS_STRETCH);
|
||||||
|
}
|
||||||
|
else if (newBoundsType == "OBS_BOUNDS_SCALE_INNER") {
|
||||||
|
obs_sceneitem_set_bounds_type(sceneItem, OBS_BOUNDS_SCALE_INNER);
|
||||||
|
}
|
||||||
|
else if (newBoundsType == "OBS_BOUNDS_SCALE_OUTER") {
|
||||||
|
obs_sceneitem_set_bounds_type(sceneItem, OBS_BOUNDS_SCALE_OUTER);
|
||||||
|
}
|
||||||
|
else if (newBoundsType == "OBS_BOUNDS_SCALE_TO_WIDTH") {
|
||||||
|
obs_sceneitem_set_bounds_type(sceneItem, OBS_BOUNDS_SCALE_TO_WIDTH);
|
||||||
|
}
|
||||||
|
else if (newBoundsType == "OBS_BOUNDS_SCALE_TO_HEIGHT") {
|
||||||
|
obs_sceneitem_set_bounds_type(sceneItem, OBS_BOUNDS_SCALE_TO_HEIGHT);
|
||||||
|
}
|
||||||
|
else if (newBoundsType == "OBS_BOUNDS_MAX_ONLY") {
|
||||||
|
obs_sceneitem_set_bounds_type(sceneItem, OBS_BOUNDS_MAX_ONLY);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
badRequest = badBounds = true;
|
||||||
|
obs_data_set_string(boundsError, "type", "invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vec2 oldBounds;
|
||||||
|
obs_sceneitem_get_bounds(sceneItem, &oldBounds);
|
||||||
|
vec2 newBounds = oldBounds;
|
||||||
|
if (obs_data_has_user_value(reqBounds, "x")) {
|
||||||
|
newBounds.x = obs_data_get_double(reqBounds, "x");
|
||||||
|
}
|
||||||
|
if (obs_data_has_user_value(reqBounds, "y")) {
|
||||||
|
newBounds.y = obs_data_get_double(reqBounds, "y");
|
||||||
|
}
|
||||||
|
obs_sceneitem_set_bounds(sceneItem, &newBounds);
|
||||||
|
if (obs_data_has_user_value(reqBounds, "alignment")) {
|
||||||
|
const uint32_t bounds_alignment = obs_data_get_int(reqBounds, "alignment");
|
||||||
|
if (Utils::IsValidAlignment(bounds_alignment)) {
|
||||||
|
obs_sceneitem_set_bounds_alignment(sceneItem, bounds_alignment);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
badRequest = badBounds = true;
|
||||||
|
obs_data_set_string(boundsError, "alignment", "invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (badBounds) {
|
||||||
|
obs_data_set_obj(errorMessage, "bounds", boundsError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (badRequest) {
|
||||||
|
req->SendErrorResponse(errorMessage);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset a scene item.
|
||||||
|
*
|
||||||
|
* @param {String (optional)} `scene-name` Name of the scene the source belongs to. Defaults to the current scene.
|
||||||
|
* @param {String} `item` Name of the source item.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name ResetSceneItem
|
||||||
|
* @category scene items
|
||||||
|
* @since 4.2.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleResetSceneItem(WSRequestHandler* req) {
|
||||||
|
// TODO: remove this request, or refactor it to ResetSource
|
||||||
|
|
||||||
|
if (!req->hasField("item")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* itemName = obs_data_get_string(req->data, "item");
|
||||||
|
if (!itemName) {
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* sceneName = obs_data_get_string(req->data, "scene-name");
|
||||||
|
OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName);
|
||||||
|
if (!scene) {
|
||||||
|
req->SendErrorResponse("requested scene doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromName(scene, itemName);
|
||||||
|
if (sceneItem) {
|
||||||
|
OBSSource sceneItemSource = obs_sceneitem_get_source(sceneItem);
|
||||||
|
|
||||||
|
OBSDataAutoRelease settings = obs_source_get_settings(sceneItemSource);
|
||||||
|
obs_source_update(sceneItemSource, settings);
|
||||||
|
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
req->SendErrorResponse("specified scene item doesn't exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show or hide a specified source item in a specified scene.
|
||||||
|
*
|
||||||
|
* @param {String} `source` Scene item name in the specified scene.
|
||||||
|
* @param {boolean} `render` true = shown ; false = hidden
|
||||||
|
* @param {String (optional)} `scene-name` Name of the scene where the source resides. Defaults to the currently active scene.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetSceneItemRender
|
||||||
|
* @category scene items
|
||||||
|
* @since 0.3
|
||||||
|
* @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties.
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetSceneItemRender(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("source") ||
|
||||||
|
!req->hasField("render"))
|
||||||
|
{
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* itemName = obs_data_get_string(req->data, "source");
|
||||||
|
bool isVisible = obs_data_get_bool(req->data, "render");
|
||||||
|
|
||||||
|
if (!itemName) {
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* sceneName = obs_data_get_string(req->data, "scene-name");
|
||||||
|
OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName);
|
||||||
|
if (!scene) {
|
||||||
|
req->SendErrorResponse("requested scene doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSSceneItemAutoRelease sceneItem =
|
||||||
|
Utils::GetSceneItemFromName(scene, itemName);
|
||||||
|
if (sceneItem) {
|
||||||
|
obs_sceneitem_set_visible(sceneItem, isVisible);
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
req->SendErrorResponse("specified scene item doesn't exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the coordinates of a specified source item.
|
||||||
|
*
|
||||||
|
* @param {String (optional)} `scene-name` The name of the scene that the source item belongs to. Defaults to the current scene.
|
||||||
|
* @param {String} `item` The name of the source item.
|
||||||
|
* @param {double} `x` X coordinate.
|
||||||
|
* @param {double} `y` Y coordinate.
|
||||||
|
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetSceneItemPosition
|
||||||
|
* @category scene items
|
||||||
|
* @since 4.0.0
|
||||||
|
* @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties.
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetSceneItemPosition(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("item") ||
|
||||||
|
!req->hasField("x") || !req->hasField("y")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString itemName = obs_data_get_string(req->data, "item");
|
||||||
|
if (itemName.isEmpty()) {
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString sceneName = obs_data_get_string(req->data, "scene-name");
|
||||||
|
OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName);
|
||||||
|
if (!scene) {
|
||||||
|
req->SendErrorResponse("requested scene could not be found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSSceneItem sceneItem = Utils::GetSceneItemFromName(scene, itemName);
|
||||||
|
if (sceneItem) {
|
||||||
|
vec2 item_position = { 0 };
|
||||||
|
item_position.x = obs_data_get_double(req->data, "x");
|
||||||
|
item_position.y = obs_data_get_double(req->data, "y");
|
||||||
|
obs_sceneitem_set_pos(sceneItem, &item_position);
|
||||||
|
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
req->SendErrorResponse("specified scene item doesn't exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the transform of the specified source item.
|
||||||
|
*
|
||||||
|
* @param {String (optional)} `scene-name` The name of the scene that the source item belongs to. Defaults to the current scene.
|
||||||
|
* @param {String} `item` The name of the source item.
|
||||||
|
* @param {double} `x-scale` Width scale factor.
|
||||||
|
* @param {double} `y-scale` Height scale factor.
|
||||||
|
* @param {double} `rotation` Source item rotation (in degrees).
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetSceneItemTransform
|
||||||
|
* @category scene items
|
||||||
|
* @since 4.0.0
|
||||||
|
* @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties.
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetSceneItemTransform(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("item") ||
|
||||||
|
!req->hasField("x-scale") ||
|
||||||
|
!req->hasField("y-scale") ||
|
||||||
|
!req->hasField("rotation"))
|
||||||
|
{
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString itemName = obs_data_get_string(req->data, "item");
|
||||||
|
if (itemName.isEmpty()) {
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString sceneName = obs_data_get_string(req->data, "scene-name");
|
||||||
|
OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName);
|
||||||
|
if (!scene) {
|
||||||
|
req->SendErrorResponse("requested scene doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 scale;
|
||||||
|
scale.x = obs_data_get_double(req->data, "x-scale");
|
||||||
|
scale.y = obs_data_get_double(req->data, "y-scale");
|
||||||
|
float rotation = obs_data_get_double(req->data, "rotation");
|
||||||
|
|
||||||
|
OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromName(scene, itemName);
|
||||||
|
if (sceneItem) {
|
||||||
|
obs_sceneitem_set_scale(sceneItem, &scale);
|
||||||
|
obs_sceneitem_set_rot(sceneItem, rotation);
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
req->SendErrorResponse("specified scene item doesn't exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the crop coordinates of the specified source item.
|
||||||
|
*
|
||||||
|
* @param {String (optional)} `scene-name` the name of the scene that the source item belongs to. Defaults to the current scene.
|
||||||
|
* @param {String} `item` The name of the source.
|
||||||
|
* @param {int} `top` Pixel position of the top of the source item.
|
||||||
|
* @param {int} `bottom` Pixel position of the bottom of the source item.
|
||||||
|
* @param {int} `left` Pixel position of the left of the source item.
|
||||||
|
* @param {int} `right` Pixel position of the right of the source item.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetSceneItemCrop
|
||||||
|
* @category scene items
|
||||||
|
* @since 4.1.0
|
||||||
|
* @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties.
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetSceneItemCrop(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("item")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString itemName = obs_data_get_string(req->data, "item");
|
||||||
|
if (itemName.isEmpty()) {
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString sceneName = obs_data_get_string(req->data, "scene-name");
|
||||||
|
OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName);
|
||||||
|
if (!scene) {
|
||||||
|
req->SendErrorResponse("requested scene doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromName(scene, itemName);
|
||||||
|
if (sceneItem) {
|
||||||
|
struct obs_sceneitem_crop crop = { 0 };
|
||||||
|
crop.top = obs_data_get_int(req->data, "top");
|
||||||
|
crop.bottom = obs_data_get_int(req->data, "bottom");
|
||||||
|
crop.left = obs_data_get_int(req->data, "left");
|
||||||
|
crop.right = obs_data_get_int(req->data, "right");
|
||||||
|
|
||||||
|
obs_sceneitem_set_crop(sceneItem, &crop);
|
||||||
|
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
req->SendErrorResponse("specified scene item doesn't exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a scene item.
|
||||||
|
*
|
||||||
|
* @param {String (optional)} `scene` Name of the scene the source belongs to. Defaults to the current scene.
|
||||||
|
* @param {Object} `item` item to delete (required)
|
||||||
|
* @param {String} `item.name` name of the scene item (prefer `id`, including both is acceptable).
|
||||||
|
* @param {int} `item.id` id of the scene item.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name DeleteSceneItem
|
||||||
|
* @category scene items
|
||||||
|
* @since 4.5.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleDeleteSceneItem(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("item")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* sceneName = obs_data_get_string(req->data, "scene");
|
||||||
|
OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName);
|
||||||
|
if (!scene) {
|
||||||
|
req->SendErrorResponse("requested scene doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSDataAutoRelease item = obs_data_get_obj(req->data, "item");
|
||||||
|
OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromItem(scene, item);
|
||||||
|
if (!sceneItem) {
|
||||||
|
req->SendErrorResponse("item with id/name combination not found in specified scene");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_sceneitem_remove(sceneItem);
|
||||||
|
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DuplicateSceneItemData {
|
||||||
|
obs_sceneitem_t *referenceItem;
|
||||||
|
obs_source_t *fromSource;
|
||||||
|
obs_sceneitem_t *newItem;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void DuplicateSceneItem(void *_data, obs_scene_t *scene) {
|
||||||
|
DuplicateSceneItemData *data = (DuplicateSceneItemData *)_data;
|
||||||
|
data->newItem = obs_scene_add(scene, data->fromSource);
|
||||||
|
obs_sceneitem_set_visible(data->newItem, obs_sceneitem_visible(data->referenceItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duplicates a scene item.
|
||||||
|
*
|
||||||
|
* @param {String (optional)} `fromScene` Name of the scene to copy the item from. Defaults to the current scene.
|
||||||
|
* @param {String (optional)} `toScene` Name of the scene to create the item in. Defaults to the current scene.
|
||||||
|
* @param {Object} `item` item to duplicate (required)
|
||||||
|
* @param {String} `item.name` name of the scene item (prefer `id`, including both is acceptable).
|
||||||
|
* @param {int} `item.id` id of the scene item.
|
||||||
|
*
|
||||||
|
* @return {String} `scene` Name of the scene where the new item was created
|
||||||
|
* @return {Object} `item` New item info
|
||||||
|
* @return {int} `̀item.id` New item ID
|
||||||
|
* @return {String} `item.name` New item name
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name DuplicateSceneItem
|
||||||
|
* @category scene items
|
||||||
|
* @since 4.5.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleDuplicateSceneItem(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("item")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* fromSceneName = obs_data_get_string(req->data, "fromScene");
|
||||||
|
OBSSourceAutoRelease fromScene = Utils::GetSceneFromNameOrCurrent(fromSceneName);
|
||||||
|
if (!fromScene) {
|
||||||
|
req->SendErrorResponse("requested fromScene doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* toSceneName = obs_data_get_string(req->data, "toScene");
|
||||||
|
OBSSourceAutoRelease toScene = Utils::GetSceneFromNameOrCurrent(toSceneName);
|
||||||
|
if (!toScene) {
|
||||||
|
req->SendErrorResponse("requested toScene doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSDataAutoRelease item = obs_data_get_obj(req->data, "item");
|
||||||
|
OBSSceneItemAutoRelease referenceItem = Utils::GetSceneItemFromItem(fromScene, item);
|
||||||
|
if (!referenceItem) {
|
||||||
|
req->SendErrorResponse("item with id/name combination not found in specified scene");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DuplicateSceneItemData data;
|
||||||
|
data.fromSource = obs_sceneitem_get_source(referenceItem);
|
||||||
|
data.referenceItem = referenceItem;
|
||||||
|
|
||||||
|
obs_enter_graphics();
|
||||||
|
obs_scene_atomic_update(obs_scene_from_source(toScene), DuplicateSceneItem, &data);
|
||||||
|
obs_leave_graphics();
|
||||||
|
|
||||||
|
obs_sceneitem_t *newItem = data.newItem;
|
||||||
|
if (!newItem) {
|
||||||
|
req->SendErrorResponse("Error duplicating scene item");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSDataAutoRelease itemData = obs_data_create();
|
||||||
|
obs_data_set_int(itemData, "id", obs_sceneitem_get_id(newItem));
|
||||||
|
obs_data_set_string(itemData, "name", obs_source_get_name(obs_sceneitem_get_source(newItem)));
|
||||||
|
|
||||||
|
OBSDataAutoRelease responseData = obs_data_create();
|
||||||
|
obs_data_set_obj(responseData, "item", itemData);
|
||||||
|
obs_data_set_string(responseData, "scene", obs_source_get_name(toScene));
|
||||||
|
|
||||||
|
req->SendOKResponse(responseData);
|
||||||
|
}
|
148
src/WSRequestHandler_Scenes.cpp
Normal file
148
src/WSRequestHandler_Scenes.cpp
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
#include <QString>
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} `Scene`
|
||||||
|
* @property {String} `name` Name of the currently active scene.
|
||||||
|
* @property {Array<Source>} `sources` Ordered list of the current scene's source items.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch to the specified scene.
|
||||||
|
*
|
||||||
|
* @param {String} `scene-name` Name of the scene to switch to.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetCurrentScene
|
||||||
|
* @category scenes
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetCurrentScene(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("scene-name")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* sceneName = obs_data_get_string(req->data, "scene-name");
|
||||||
|
OBSSourceAutoRelease source = obs_get_source_by_name(sceneName);
|
||||||
|
|
||||||
|
if (source) {
|
||||||
|
obs_frontend_set_current_scene(source);
|
||||||
|
req->SendOKResponse();
|
||||||
|
} else {
|
||||||
|
req->SendErrorResponse("requested scene does not exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current scene's name and source items.
|
||||||
|
*
|
||||||
|
* @return {String} `name` Name of the currently active scene.
|
||||||
|
* @return {Array<Source>} `sources` Ordered list of the current scene's source items.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetCurrentScene
|
||||||
|
* @category scenes
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetCurrentScene(WSRequestHandler* req) {
|
||||||
|
OBSSourceAutoRelease currentScene = obs_frontend_get_current_scene();
|
||||||
|
OBSDataArrayAutoRelease sceneItems = Utils::GetSceneItems(currentScene);
|
||||||
|
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_string(data, "name", obs_source_get_name(currentScene));
|
||||||
|
obs_data_set_array(data, "sources", sceneItems);
|
||||||
|
|
||||||
|
req->SendOKResponse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of scenes in the currently active profile.
|
||||||
|
*
|
||||||
|
* @return {String} `current-scene` Name of the currently active scene.
|
||||||
|
* @return {Array<Scene>} `scenes` Ordered list of the current profile's scenes (See `[GetCurrentScene](#getcurrentscene)` for more information).
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetSceneList
|
||||||
|
* @category scenes
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetSceneList(WSRequestHandler* req) {
|
||||||
|
OBSSourceAutoRelease currentScene = obs_frontend_get_current_scene();
|
||||||
|
OBSDataArrayAutoRelease scenes = Utils::GetScenes();
|
||||||
|
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_string(data, "current-scene",
|
||||||
|
obs_source_get_name(currentScene));
|
||||||
|
obs_data_set_array(data, "scenes", scenes);
|
||||||
|
|
||||||
|
req->SendOKResponse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the order of scene items in the requested scene.
|
||||||
|
*
|
||||||
|
* @param {String (optional)} `scene` Name of the scene to reorder (defaults to current).
|
||||||
|
* @param {Array<Scene>} `items` Ordered list of objects with name and/or id specified. Id preferred due to uniqueness per scene
|
||||||
|
* @param {int (optional)} `items[].id` Id of a specific scene item. Unique on a scene by scene basis.
|
||||||
|
* @param {String (optional)} `items[].name` Name of a scene item. Sufficiently unique if no scene items share sources within the scene.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name ReorderSceneItems
|
||||||
|
* @category scenes
|
||||||
|
* @since 4.5.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleReorderSceneItems(WSRequestHandler* req) {
|
||||||
|
QString sceneName = obs_data_get_string(req->data, "scene");
|
||||||
|
OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName);
|
||||||
|
if (!scene) {
|
||||||
|
req->SendErrorResponse("requested scene doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSDataArrayAutoRelease items = obs_data_get_array(req->data, "items");
|
||||||
|
if (!items) {
|
||||||
|
req->SendErrorResponse("sceneItem order not specified");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t count = obs_data_array_count(items);
|
||||||
|
|
||||||
|
std::vector<obs_sceneitem_t*> newOrder;
|
||||||
|
newOrder.reserve(count);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
OBSDataAutoRelease item = obs_data_array_item(items, i);
|
||||||
|
|
||||||
|
OBSSceneItemAutoRelease sceneItem = Utils::GetSceneItemFromItem(scene, item);
|
||||||
|
obs_sceneitem_release(sceneItem); // ref dec
|
||||||
|
|
||||||
|
if (!sceneItem) {
|
||||||
|
req->SendErrorResponse("Invalid sceneItem id or name specified");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t j = 0; j <= i; ++j) {
|
||||||
|
if (sceneItem == newOrder[j]) {
|
||||||
|
req->SendErrorResponse("Duplicate sceneItem in specified order");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newOrder.push_back(sceneItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success = obs_scene_reorder_items(obs_scene_from_source(scene), newOrder.data(), count);
|
||||||
|
if (!success) {
|
||||||
|
req->SendErrorResponse("Invalid sceneItem order");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto const& item: newOrder) {
|
||||||
|
obs_sceneitem_release(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
1428
src/WSRequestHandler_Sources.cpp
Normal file
1428
src/WSRequestHandler_Sources.cpp
Normal file
File diff suppressed because it is too large
Load Diff
288
src/WSRequestHandler_Streaming.cpp
Normal file
288
src/WSRequestHandler_Streaming.cpp
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
#include <QString>
|
||||||
|
#include "Utils.h"
|
||||||
|
#include "WSEvents.h"
|
||||||
|
|
||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
#define STREAM_SERVICE_ID "websocket_custom_service"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current streaming and recording status.
|
||||||
|
*
|
||||||
|
* @return {boolean} `streaming` Current streaming status.
|
||||||
|
* @return {boolean} `recording` Current recording status.
|
||||||
|
* @return {String (optional)} `stream-timecode` Time elapsed since streaming started (only present if currently streaming).
|
||||||
|
* @return {String (optional)} `rec-timecode` Time elapsed since recording started (only present if currently recording).
|
||||||
|
* @return {boolean} `preview-only` Always false. Retrocompatibility with OBSRemote.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetStreamingStatus
|
||||||
|
* @category streaming
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req) {
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_bool(data, "streaming", obs_frontend_streaming_active());
|
||||||
|
obs_data_set_bool(data, "recording", obs_frontend_recording_active());
|
||||||
|
obs_data_set_bool(data, "preview-only", false);
|
||||||
|
|
||||||
|
const char* tc = nullptr;
|
||||||
|
if (obs_frontend_streaming_active()) {
|
||||||
|
tc = WSEvents::Instance->GetStreamingTimecode();
|
||||||
|
obs_data_set_string(data, "stream-timecode", tc);
|
||||||
|
bfree((void*)tc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obs_frontend_recording_active()) {
|
||||||
|
tc = WSEvents::Instance->GetRecordingTimecode();
|
||||||
|
obs_data_set_string(data, "rec-timecode", tc);
|
||||||
|
bfree((void*)tc);
|
||||||
|
}
|
||||||
|
|
||||||
|
req->SendOKResponse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle streaming on or off.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name StartStopStreaming
|
||||||
|
* @category streaming
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleStartStopStreaming(WSRequestHandler* req) {
|
||||||
|
if (obs_frontend_streaming_active())
|
||||||
|
HandleStopStreaming(req);
|
||||||
|
else
|
||||||
|
HandleStartStreaming(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start streaming.
|
||||||
|
* Will return an `error` if streaming is already active.
|
||||||
|
*
|
||||||
|
* @param {Object (optional)} `stream` Special stream configuration. Please note: these won't be saved to OBS' configuration.
|
||||||
|
* @param {String (optional)} `stream.type` If specified ensures the type of stream matches the given type (usually 'rtmp_custom' or 'rtmp_common'). If the currently configured stream type does not match the given stream type, all settings must be specified in the `settings` object or an error will occur when starting the stream.
|
||||||
|
* @param {Object (optional)} `stream.metadata` Adds the given object parameters as encoded query string parameters to the 'key' of the RTMP stream. Used to pass data to the RTMP service about the streaming. May be any String, Numeric, or Boolean field.
|
||||||
|
* @param {Object (optional)} `stream.settings` Settings for the stream.
|
||||||
|
* @param {String (optional)} `stream.settings.server` The publish URL.
|
||||||
|
* @param {String (optional)} `stream.settings.key` The publish key of the stream.
|
||||||
|
* @param {boolean (optional)} `stream.settings.use-auth` Indicates whether authentication should be used when connecting to the streaming server.
|
||||||
|
* @param {String (optional)} `stream.settings.username` If authentication is enabled, the username for the streaming server. Ignored if `use-auth` is not set to `true`.
|
||||||
|
* @param {String (optional)} `stream.settings.password` If authentication is enabled, the password for the streaming server. Ignored if `use-auth` is not set to `true`.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name StartStreaming
|
||||||
|
* @category streaming
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleStartStreaming(WSRequestHandler* req) {
|
||||||
|
if (obs_frontend_streaming_active() == false) {
|
||||||
|
OBSService configuredService = obs_frontend_get_streaming_service();
|
||||||
|
OBSService newService = nullptr;
|
||||||
|
|
||||||
|
// TODO: fix service memory leak
|
||||||
|
|
||||||
|
if (req->hasField("stream")) {
|
||||||
|
OBSDataAutoRelease streamData = obs_data_get_obj(req->data, "stream");
|
||||||
|
OBSDataAutoRelease newSettings = obs_data_get_obj(streamData, "settings");
|
||||||
|
OBSDataAutoRelease newMetadata = obs_data_get_obj(streamData, "metadata");
|
||||||
|
|
||||||
|
OBSDataAutoRelease csHotkeys =
|
||||||
|
obs_hotkeys_save_service(configuredService);
|
||||||
|
|
||||||
|
QString currentType = obs_service_get_type(configuredService);
|
||||||
|
QString newType = obs_data_get_string(streamData, "type");
|
||||||
|
if (newType.isEmpty() || newType.isNull()) {
|
||||||
|
newType = currentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Supporting adding metadata parameters to key query string
|
||||||
|
QString query = Utils::ParseDataToQueryString(newMetadata);
|
||||||
|
if (!query.isEmpty()
|
||||||
|
&& obs_data_has_user_value(newSettings, "key"))
|
||||||
|
{
|
||||||
|
const char* key = obs_data_get_string(newSettings, "key");
|
||||||
|
int keylen = strlen(key);
|
||||||
|
|
||||||
|
bool hasQuestionMark = false;
|
||||||
|
for (int i = 0; i < keylen; i++) {
|
||||||
|
if (key[i] == '?') {
|
||||||
|
hasQuestionMark = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasQuestionMark) {
|
||||||
|
query.prepend('&');
|
||||||
|
} else {
|
||||||
|
query.prepend('?');
|
||||||
|
}
|
||||||
|
|
||||||
|
query.prepend(key);
|
||||||
|
obs_data_set_string(newSettings, "key", query.toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newType == currentType) {
|
||||||
|
// Service type doesn't change: apply settings to current service
|
||||||
|
|
||||||
|
// By doing this, you can send a request to the websocket
|
||||||
|
// that only contains settings you want to change, instead of
|
||||||
|
// having to do a get and then change them
|
||||||
|
|
||||||
|
OBSDataAutoRelease currentSettings = obs_service_get_settings(configuredService);
|
||||||
|
OBSDataAutoRelease updatedSettings = obs_data_create();
|
||||||
|
|
||||||
|
obs_data_apply(updatedSettings, currentSettings); //first apply the existing settings
|
||||||
|
obs_data_apply(updatedSettings, newSettings); //then apply the settings from the request should they exist
|
||||||
|
|
||||||
|
newService = obs_service_create(
|
||||||
|
newType.toUtf8(), STREAM_SERVICE_ID,
|
||||||
|
updatedSettings, csHotkeys);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Service type changed: override service settings
|
||||||
|
newService = obs_service_create(
|
||||||
|
newType.toUtf8(), STREAM_SERVICE_ID,
|
||||||
|
newSettings, csHotkeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_frontend_set_streaming_service(newService);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_frontend_streaming_start();
|
||||||
|
|
||||||
|
// Stream settings provided in StartStreaming are not persisted to disk
|
||||||
|
if (newService != nullptr) {
|
||||||
|
obs_frontend_set_streaming_service(configuredService);
|
||||||
|
}
|
||||||
|
|
||||||
|
req->SendOKResponse();
|
||||||
|
} else {
|
||||||
|
req->SendErrorResponse("streaming already active");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop streaming.
|
||||||
|
* Will return an `error` if streaming is not active.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name StopStreaming
|
||||||
|
* @category streaming
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleStopStreaming(WSRequestHandler* req) {
|
||||||
|
if (obs_frontend_streaming_active() == true) {
|
||||||
|
obs_frontend_streaming_stop();
|
||||||
|
req->SendOKResponse();
|
||||||
|
} else {
|
||||||
|
req->SendErrorResponse("streaming not active");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets one or more attributes of the current streaming server settings. Any options not passed will remain unchanged. Returns the updated settings in response. If 'type' is different than the current streaming service type, all settings are required. Returns the full settings of the stream (the same as GetStreamSettings).
|
||||||
|
*
|
||||||
|
* @param {String} `type` The type of streaming service configuration, usually `rtmp_custom` or `rtmp_common`.
|
||||||
|
* @param {Object} `settings` The actual settings of the stream.
|
||||||
|
* @param {String (optional)} `settings.server` The publish URL.
|
||||||
|
* @param {String (optional)} `settings.key` The publish key.
|
||||||
|
* @param {boolean (optional)} `settings.use-auth` Indicates whether authentication should be used when connecting to the streaming server.
|
||||||
|
* @param {String (optional)} `settings.username` The username for the streaming service.
|
||||||
|
* @param {String (optional)} `settings.password` The password for the streaming service.
|
||||||
|
* @param {boolean} `save` Persist the settings to disk.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetStreamSettings
|
||||||
|
* @category streaming
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetStreamSettings(WSRequestHandler* req) {
|
||||||
|
OBSService service = obs_frontend_get_streaming_service();
|
||||||
|
|
||||||
|
OBSDataAutoRelease requestSettings = obs_data_get_obj(req->data, "settings");
|
||||||
|
if (!requestSettings) {
|
||||||
|
req->SendErrorResponse("'settings' are required'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString serviceType = obs_service_get_type(service);
|
||||||
|
QString requestedType = obs_data_get_string(req->data, "type");
|
||||||
|
|
||||||
|
if (requestedType != nullptr && requestedType != serviceType) {
|
||||||
|
OBSDataAutoRelease hotkeys = obs_hotkeys_save_service(service);
|
||||||
|
service = obs_service_create(
|
||||||
|
requestedType.toUtf8(), STREAM_SERVICE_ID, requestSettings, hotkeys);
|
||||||
|
} else {
|
||||||
|
// If type isn't changing, we should overlay the settings we got
|
||||||
|
// to the existing settings. By doing so, you can send a request that
|
||||||
|
// only contains the settings you want to change, instead of having to
|
||||||
|
// do a get and then change them
|
||||||
|
|
||||||
|
OBSDataAutoRelease existingSettings = obs_service_get_settings(service);
|
||||||
|
OBSDataAutoRelease newSettings = obs_data_create();
|
||||||
|
|
||||||
|
// Apply existing settings
|
||||||
|
obs_data_apply(newSettings, existingSettings);
|
||||||
|
// Then apply the settings from the request
|
||||||
|
obs_data_apply(newSettings, requestSettings);
|
||||||
|
|
||||||
|
obs_service_update(service, newSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
//if save is specified we should immediately save the streaming service
|
||||||
|
if (obs_data_get_bool(req->data, "save")) {
|
||||||
|
obs_frontend_save_streaming_service();
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSDataAutoRelease serviceSettings = obs_service_get_settings(service);
|
||||||
|
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "type", requestedType.toUtf8());
|
||||||
|
obs_data_set_obj(response, "settings", serviceSettings);
|
||||||
|
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current streaming server settings.
|
||||||
|
*
|
||||||
|
* @return {String} `type` The type of streaming service configuration. Possible values: 'rtmp_custom' or 'rtmp_common'.
|
||||||
|
* @return {Object} `settings` Stream settings object.
|
||||||
|
* @return {String} `settings.server` The publish URL.
|
||||||
|
* @return {String} `settings.key` The publish key of the stream.
|
||||||
|
* @return {boolean} `settings.use-auth` Indicates whether authentication should be used when connecting to the streaming server.
|
||||||
|
* @return {String} `settings.username` The username to use when accessing the streaming server. Only present if `use-auth` is `true`.
|
||||||
|
* @return {String} `settings.password` The password to use when accessing the streaming server. Only present if `use-auth` is `true`.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetStreamSettings
|
||||||
|
* @category streaming
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetStreamSettings(WSRequestHandler* req) {
|
||||||
|
OBSService service = obs_frontend_get_streaming_service();
|
||||||
|
|
||||||
|
const char* serviceType = obs_service_get_type(service);
|
||||||
|
OBSDataAutoRelease settings = obs_service_get_settings(service);
|
||||||
|
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "type", serviceType);
|
||||||
|
obs_data_set_obj(response, "settings", settings);
|
||||||
|
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the current streaming server settings to disk.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SaveStreamSettings
|
||||||
|
* @category streaming
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSaveStreamSettings(WSRequestHandler* req) {
|
||||||
|
obs_frontend_save_streaming_service();
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
173
src/WSRequestHandler_StudioMode.cpp
Normal file
173
src/WSRequestHandler_StudioMode.cpp
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
#include <QString>
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if Studio Mode is currently enabled.
|
||||||
|
*
|
||||||
|
* @return {boolean} `studio-mode` Indicates if Studio Mode is enabled.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetStudioModeStatus
|
||||||
|
* @category studio mode
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetStudioModeStatus(WSRequestHandler* req) {
|
||||||
|
bool previewActive = obs_frontend_preview_program_mode_active();
|
||||||
|
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_bool(response, "studio-mode", previewActive);
|
||||||
|
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the currently previewed scene and its list of sources.
|
||||||
|
* Will return an `error` if Studio Mode is not enabled.
|
||||||
|
*
|
||||||
|
* @return {String} `name` The name of the active preview scene.
|
||||||
|
* @return {Array<Source>} `sources`
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetPreviewScene
|
||||||
|
* @category studio mode
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetPreviewScene(WSRequestHandler* req) {
|
||||||
|
if (!obs_frontend_preview_program_mode_active()) {
|
||||||
|
req->SendErrorResponse("studio mode not enabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OBSSourceAutoRelease scene = obs_frontend_get_current_preview_scene();
|
||||||
|
OBSDataArrayAutoRelease sceneItems = Utils::GetSceneItems(scene);
|
||||||
|
|
||||||
|
OBSDataAutoRelease data = obs_data_create();
|
||||||
|
obs_data_set_string(data, "name", obs_source_get_name(scene));
|
||||||
|
obs_data_set_array(data, "sources", sceneItems);
|
||||||
|
|
||||||
|
req->SendOKResponse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the active preview scene.
|
||||||
|
* Will return an `error` if Studio Mode is not enabled.
|
||||||
|
*
|
||||||
|
* @param {String} `scene-name` The name of the scene to preview.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetPreviewScene
|
||||||
|
* @category studio mode
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetPreviewScene(WSRequestHandler* req) {
|
||||||
|
if (!obs_frontend_preview_program_mode_active()) {
|
||||||
|
req->SendErrorResponse("studio mode not enabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req->hasField("scene-name")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* scene_name = obs_data_get_string(req->data, "scene-name");
|
||||||
|
OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(scene_name);
|
||||||
|
|
||||||
|
if (scene) {
|
||||||
|
obs_frontend_set_current_preview_scene(scene);
|
||||||
|
req->SendOKResponse();
|
||||||
|
} else {
|
||||||
|
req->SendErrorResponse("specified scene doesn't exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transitions the currently previewed scene to the main output.
|
||||||
|
* Will return an `error` if Studio Mode is not enabled.
|
||||||
|
*
|
||||||
|
* @param {Object (optional)} `with-transition` Change the active transition before switching scenes. Defaults to the active transition.
|
||||||
|
* @param {String} `with-transition.name` Name of the transition.
|
||||||
|
* @param {int (optional)} `with-transition.duration` Transition duration (in milliseconds).
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name TransitionToProgram
|
||||||
|
* @category studio mode
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleTransitionToProgram(WSRequestHandler* req) {
|
||||||
|
if (!obs_frontend_preview_program_mode_active()) {
|
||||||
|
req->SendErrorResponse("studio mode not enabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req->hasField("with-transition")) {
|
||||||
|
OBSDataAutoRelease transitionInfo =
|
||||||
|
obs_data_get_obj(req->data, "with-transition");
|
||||||
|
|
||||||
|
if (obs_data_has_user_value(transitionInfo, "name")) {
|
||||||
|
QString transitionName =
|
||||||
|
obs_data_get_string(transitionInfo, "name");
|
||||||
|
if (transitionName.isEmpty()) {
|
||||||
|
req->SendErrorResponse("invalid request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success = Utils::SetTransitionByName(transitionName);
|
||||||
|
if (!success) {
|
||||||
|
req->SendErrorResponse("specified transition doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obs_data_has_user_value(transitionInfo, "duration")) {
|
||||||
|
int transitionDuration =
|
||||||
|
obs_data_get_int(transitionInfo, "duration");
|
||||||
|
Utils::SetTransitionDuration(transitionDuration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils::TransitionToProgram();
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables Studio Mode.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name EnableStudioMode
|
||||||
|
* @category studio mode
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleEnableStudioMode(WSRequestHandler* req) {
|
||||||
|
obs_frontend_set_preview_program_mode(true);
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables Studio Mode.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name DisableStudioMode
|
||||||
|
* @category studio mode
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleDisableStudioMode(WSRequestHandler* req) {
|
||||||
|
obs_frontend_set_preview_program_mode(false);
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles Studio Mode.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name ToggleStudioMode
|
||||||
|
* @category studio mode
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleToggleStudioMode(WSRequestHandler* req) {
|
||||||
|
bool previewProgramMode = obs_frontend_preview_program_mode_active();
|
||||||
|
obs_frontend_set_preview_program_mode(!previewProgramMode);
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
126
src/WSRequestHandler_Transitions.cpp
Normal file
126
src/WSRequestHandler_Transitions.cpp
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
#include <QString>
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
#include "WSRequestHandler.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of all transitions available in the frontend's dropdown menu.
|
||||||
|
*
|
||||||
|
* @return {String} `current-transition` Name of the currently active transition.
|
||||||
|
* @return {Array<Object>} `transitions` List of transitions.
|
||||||
|
* @return {String} `transitions.*.name` Name of the transition.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetTransitionList
|
||||||
|
* @category transitions
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetTransitionList(WSRequestHandler* req) {
|
||||||
|
OBSSourceAutoRelease currentTransition = obs_frontend_get_current_transition();
|
||||||
|
obs_frontend_source_list transitionList = {};
|
||||||
|
obs_frontend_get_transitions(&transitionList);
|
||||||
|
|
||||||
|
OBSDataArrayAutoRelease transitions = obs_data_array_create();
|
||||||
|
for (size_t i = 0; i < transitionList.sources.num; i++) {
|
||||||
|
OBSSource transition = transitionList.sources.array[i];
|
||||||
|
|
||||||
|
OBSDataAutoRelease obj = obs_data_create();
|
||||||
|
obs_data_set_string(obj, "name", obs_source_get_name(transition));
|
||||||
|
obs_data_array_push_back(transitions, obj);
|
||||||
|
}
|
||||||
|
obs_frontend_source_list_free(&transitionList);
|
||||||
|
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "current-transition",
|
||||||
|
obs_source_get_name(currentTransition));
|
||||||
|
obs_data_set_array(response, "transitions", transitions);
|
||||||
|
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the currently selected transition in the frontend's dropdown menu.
|
||||||
|
*
|
||||||
|
* @return {String} `name` Name of the selected transition.
|
||||||
|
* @return {int (optional)} `duration` Transition duration (in milliseconds) if supported by the transition.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetCurrentTransition
|
||||||
|
* @category transitions
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetCurrentTransition(WSRequestHandler* req) {
|
||||||
|
OBSSourceAutoRelease currentTransition = obs_frontend_get_current_transition();
|
||||||
|
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_string(response, "name",
|
||||||
|
obs_source_get_name(currentTransition));
|
||||||
|
|
||||||
|
if (!obs_transition_fixed(currentTransition))
|
||||||
|
obs_data_set_int(response, "duration", Utils::GetTransitionDuration());
|
||||||
|
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the active transition.
|
||||||
|
*
|
||||||
|
* @param {String} `transition-name` The name of the transition.
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetCurrentTransition
|
||||||
|
* @category transitions
|
||||||
|
* @since 0.3
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetCurrentTransition(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("transition-name")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString name = obs_data_get_string(req->data, "transition-name");
|
||||||
|
bool success = Utils::SetTransitionByName(name);
|
||||||
|
if (success)
|
||||||
|
req->SendOKResponse();
|
||||||
|
else
|
||||||
|
req->SendErrorResponse("requested transition does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the duration of the currently selected transition if supported.
|
||||||
|
*
|
||||||
|
* @param {int} `duration` Desired duration of the transition (in milliseconds).
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name SetTransitionDuration
|
||||||
|
* @category transitions
|
||||||
|
* @since 4.0.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleSetTransitionDuration(WSRequestHandler* req) {
|
||||||
|
if (!req->hasField("duration")) {
|
||||||
|
req->SendErrorResponse("missing request parameters");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ms = obs_data_get_int(req->data, "duration");
|
||||||
|
Utils::SetTransitionDuration(ms);
|
||||||
|
req->SendOKResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the duration of the currently selected transition if supported.
|
||||||
|
*
|
||||||
|
* @return {int} `transition-duration` Duration of the current transition (in milliseconds).
|
||||||
|
*
|
||||||
|
* @api requests
|
||||||
|
* @name GetTransitionDuration
|
||||||
|
* @category transitions
|
||||||
|
* @since 4.1.0
|
||||||
|
*/
|
||||||
|
void WSRequestHandler::HandleGetTransitionDuration(WSRequestHandler* req) {
|
||||||
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
obs_data_set_int(response, "transition-duration",
|
||||||
|
Utils::GetTransitionDuration());
|
||||||
|
|
||||||
|
req->SendOKResponse(response);
|
||||||
|
}
|
168
src/WSServer.cpp
Normal file
168
src/WSServer.cpp
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
/*
|
||||||
|
obs-websocket
|
||||||
|
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <QtWebSockets/QWebSocket>
|
||||||
|
#include <QtCore/QThread>
|
||||||
|
#include <QtCore/QByteArray>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <obs-frontend-api.h>
|
||||||
|
|
||||||
|
#include "WSServer.h"
|
||||||
|
#include "obs-websocket.h"
|
||||||
|
#include "Config.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
|
QT_USE_NAMESPACE
|
||||||
|
|
||||||
|
WSServer* WSServer::Instance = nullptr;
|
||||||
|
|
||||||
|
WSServer::WSServer(QObject* parent)
|
||||||
|
: QObject(parent),
|
||||||
|
_wsServer(Q_NULLPTR),
|
||||||
|
_clients(),
|
||||||
|
_clMutex(QMutex::Recursive)
|
||||||
|
{
|
||||||
|
_wsServer = new QWebSocketServer(
|
||||||
|
QStringLiteral("obs-websocket"),
|
||||||
|
QWebSocketServer::NonSecureMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
WSServer::~WSServer() {
|
||||||
|
Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSServer::Start(quint16 port) {
|
||||||
|
if (port == _wsServer->serverPort())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(_wsServer->isListening())
|
||||||
|
Stop();
|
||||||
|
|
||||||
|
bool serverStarted = _wsServer->listen(QHostAddress::Any, port);
|
||||||
|
if (serverStarted) {
|
||||||
|
blog(LOG_INFO, "server started successfully on TCP port %d", port);
|
||||||
|
|
||||||
|
connect(_wsServer, SIGNAL(newConnection()),
|
||||||
|
this, SLOT(onNewConnection()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QString errorString = _wsServer->errorString();
|
||||||
|
blog(LOG_ERROR,
|
||||||
|
"error: failed to start server on TCP port %d: %s",
|
||||||
|
port, errorString.toUtf8().constData());
|
||||||
|
|
||||||
|
QMainWindow* mainWindow = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
|
||||||
|
obs_frontend_push_ui_translation(obs_module_get_string);
|
||||||
|
QString title = tr("OBSWebsocket.Server.StartFailed.Title");
|
||||||
|
QString msg = tr("OBSWebsocket.Server.StartFailed.Message").arg(port);
|
||||||
|
obs_frontend_pop_ui_translation();
|
||||||
|
|
||||||
|
QMessageBox::warning(mainWindow, title, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSServer::Stop() {
|
||||||
|
QMutexLocker locker(&_clMutex);
|
||||||
|
for(QWebSocket* pClient : _clients) {
|
||||||
|
pClient->close();
|
||||||
|
}
|
||||||
|
locker.unlock();
|
||||||
|
|
||||||
|
_wsServer->close();
|
||||||
|
|
||||||
|
blog(LOG_INFO, "server stopped successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSServer::broadcast(QString message) {
|
||||||
|
QMutexLocker locker(&_clMutex);
|
||||||
|
for(QWebSocket* pClient : _clients) {
|
||||||
|
if (Config::Current()->AuthRequired
|
||||||
|
&& (pClient->property(PROP_AUTHENTICATED).toBool() == false)) {
|
||||||
|
// Skip this client if unauthenticated
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pClient->sendTextMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSServer::onNewConnection() {
|
||||||
|
QWebSocket* pSocket = _wsServer->nextPendingConnection();
|
||||||
|
if (pSocket) {
|
||||||
|
connect(pSocket, SIGNAL(textMessageReceived(const QString&)),
|
||||||
|
this, SLOT(onTextMessageReceived(QString)));
|
||||||
|
connect(pSocket, SIGNAL(disconnected()),
|
||||||
|
this, SLOT(onSocketDisconnected()));
|
||||||
|
|
||||||
|
pSocket->setProperty(PROP_AUTHENTICATED, false);
|
||||||
|
|
||||||
|
QMutexLocker locker(&_clMutex);
|
||||||
|
_clients << pSocket;
|
||||||
|
locker.unlock();
|
||||||
|
|
||||||
|
QHostAddress clientAddr = pSocket->peerAddress();
|
||||||
|
QString clientIp = Utils::FormatIPAddress(clientAddr);
|
||||||
|
|
||||||
|
blog(LOG_INFO, "new client connection from %s:%d",
|
||||||
|
clientIp.toUtf8().constData(), pSocket->peerPort());
|
||||||
|
|
||||||
|
obs_frontend_push_ui_translation(obs_module_get_string);
|
||||||
|
QString title = tr("OBSWebsocket.NotifyConnect.Title");
|
||||||
|
QString msg = tr("OBSWebsocket.NotifyConnect.Message")
|
||||||
|
.arg(Utils::FormatIPAddress(clientAddr));
|
||||||
|
obs_frontend_pop_ui_translation();
|
||||||
|
|
||||||
|
Utils::SysTrayNotify(msg, QSystemTrayIcon::Information, title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSServer::onTextMessageReceived(QString message) {
|
||||||
|
QWebSocket* pSocket = qobject_cast<QWebSocket*>(sender());
|
||||||
|
if (pSocket) {
|
||||||
|
WSRequestHandler handler(pSocket);
|
||||||
|
handler.processIncomingMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WSServer::onSocketDisconnected() {
|
||||||
|
QWebSocket* pSocket = qobject_cast<QWebSocket*>(sender());
|
||||||
|
if (pSocket) {
|
||||||
|
pSocket->setProperty(PROP_AUTHENTICATED, false);
|
||||||
|
|
||||||
|
QMutexLocker locker(&_clMutex);
|
||||||
|
_clients.removeAll(pSocket);
|
||||||
|
locker.unlock();
|
||||||
|
|
||||||
|
pSocket->deleteLater();
|
||||||
|
|
||||||
|
QHostAddress clientAddr = pSocket->peerAddress();
|
||||||
|
QString clientIp = Utils::FormatIPAddress(clientAddr);
|
||||||
|
|
||||||
|
blog(LOG_INFO, "client %s:%d disconnected",
|
||||||
|
clientIp.toUtf8().constData(), pSocket->peerPort());
|
||||||
|
|
||||||
|
obs_frontend_push_ui_translation(obs_module_get_string);
|
||||||
|
QString title = tr("OBSWebsocket.NotifyDisconnect.Title");
|
||||||
|
QString msg = tr("OBSWebsocket.NotifyDisconnect.Message")
|
||||||
|
.arg(Utils::FormatIPAddress(clientAddr));
|
||||||
|
obs_frontend_pop_ui_translation();
|
||||||
|
|
||||||
|
Utils::SysTrayNotify(msg, QSystemTrayIcon::Information, title);
|
||||||
|
}
|
||||||
|
}
|
@ -29,24 +29,24 @@ QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
|
|||||||
QT_FORWARD_DECLARE_CLASS(QWebSocket)
|
QT_FORWARD_DECLARE_CLASS(QWebSocket)
|
||||||
|
|
||||||
class WSServer : public QObject {
|
class WSServer : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit WSServer(QObject* parent = Q_NULLPTR);
|
explicit WSServer(QObject* parent = Q_NULLPTR);
|
||||||
virtual ~WSServer();
|
virtual ~WSServer();
|
||||||
void Start(quint16 port);
|
void Start(quint16 port);
|
||||||
void Stop();
|
void Stop();
|
||||||
void broadcast(QString message);
|
void broadcast(QString message);
|
||||||
static WSServer* Instance;
|
static WSServer* Instance;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onNewConnection();
|
void onNewConnection();
|
||||||
void onTextMessageReceived(QString message);
|
void onTextMessageReceived(QString message);
|
||||||
void onSocketDisconnected();
|
void onSocketDisconnected();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWebSocketServer* _wsServer;
|
QWebSocketServer* _wsServer;
|
||||||
QList<QWebSocket*> _clients;
|
QList<QWebSocket*> _clients;
|
||||||
QMutex _clMutex;
|
QMutex _clMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WSSERVER_H
|
#endif // WSSERVER_H
|
104
src/forms/settings-dialog.cpp
Normal file
104
src/forms/settings-dialog.cpp
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
obs-websocket
|
||||||
|
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <obs-frontend-api.h>
|
||||||
|
|
||||||
|
#include "../obs-websocket.h"
|
||||||
|
#include "../Config.h"
|
||||||
|
#include "../WSServer.h"
|
||||||
|
#include "settings-dialog.h"
|
||||||
|
|
||||||
|
#define CHANGE_ME "changeme"
|
||||||
|
|
||||||
|
SettingsDialog::SettingsDialog(QWidget* parent) :
|
||||||
|
QDialog(parent, Qt::Dialog),
|
||||||
|
ui(new Ui::SettingsDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(ui->authRequired, &QCheckBox::stateChanged,
|
||||||
|
this, &SettingsDialog::AuthCheckboxChanged);
|
||||||
|
connect(ui->buttonBox, &QDialogButtonBox::accepted,
|
||||||
|
this, &SettingsDialog::FormAccepted);
|
||||||
|
|
||||||
|
|
||||||
|
AuthCheckboxChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsDialog::showEvent(QShowEvent* event) {
|
||||||
|
Config* conf = Config::Current();
|
||||||
|
|
||||||
|
ui->serverEnabled->setChecked(conf->ServerEnabled);
|
||||||
|
ui->serverPort->setValue(conf->ServerPort);
|
||||||
|
|
||||||
|
ui->debugEnabled->setChecked(conf->DebugEnabled);
|
||||||
|
ui->alertsEnabled->setChecked(conf->AlertsEnabled);
|
||||||
|
|
||||||
|
ui->authRequired->setChecked(conf->AuthRequired);
|
||||||
|
ui->password->setText(CHANGE_ME);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsDialog::ToggleShowHide() {
|
||||||
|
if (!isVisible())
|
||||||
|
setVisible(true);
|
||||||
|
else
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsDialog::AuthCheckboxChanged() {
|
||||||
|
if (ui->authRequired->isChecked())
|
||||||
|
ui->password->setEnabled(true);
|
||||||
|
else
|
||||||
|
ui->password->setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsDialog::FormAccepted() {
|
||||||
|
Config* conf = Config::Current();
|
||||||
|
|
||||||
|
conf->ServerEnabled = ui->serverEnabled->isChecked();
|
||||||
|
conf->ServerPort = ui->serverPort->value();
|
||||||
|
|
||||||
|
conf->DebugEnabled = ui->debugEnabled->isChecked();
|
||||||
|
conf->AlertsEnabled = ui->alertsEnabled->isChecked();
|
||||||
|
|
||||||
|
if (ui->authRequired->isChecked()) {
|
||||||
|
if (ui->password->text() != CHANGE_ME) {
|
||||||
|
conf->SetPassword(ui->password->text());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Config::Current()->Secret.isEmpty())
|
||||||
|
conf->AuthRequired = true;
|
||||||
|
else
|
||||||
|
conf->AuthRequired = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
conf->AuthRequired = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
conf->Save();
|
||||||
|
|
||||||
|
if (conf->ServerEnabled)
|
||||||
|
WSServer::Instance->Start(conf->ServerPort);
|
||||||
|
else
|
||||||
|
WSServer::Instance->Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingsDialog::~SettingsDialog() {
|
||||||
|
delete ui;
|
||||||
|
}
|
@ -21,26 +21,24 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
namespace Ui {
|
#include "ui_settings-dialog.h"
|
||||||
class SettingsDialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingsDialog : public QDialog
|
class SettingsDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SettingsDialog(QWidget* parent = 0);
|
explicit SettingsDialog(QWidget* parent = 0);
|
||||||
~SettingsDialog();
|
~SettingsDialog();
|
||||||
void showEvent(QShowEvent* event);
|
void showEvent(QShowEvent* event);
|
||||||
void ToggleShowHide();
|
void ToggleShowHide();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void AuthCheckboxChanged();
|
void AuthCheckboxChanged();
|
||||||
void FormAccepted();
|
void FormAccepted();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::SettingsDialog* ui;
|
Ui::SettingsDialog* ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SETTINGSDIALOG_H
|
#endif // SETTINGSDIALOG_H
|
151
src/forms/settings-dialog.ui
Normal file
151
src/forms/settings-dialog.ui
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>SettingsDialog</class>
|
||||||
|
<widget class="QDialog" name="SettingsDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>407</width>
|
||||||
|
<height>195</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>OBSWebsocket.Settings.DialogTitle</string>
|
||||||
|
</property>
|
||||||
|
<property name="sizeGripEnabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="sizeConstraint">
|
||||||
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QCheckBox" name="authRequired">
|
||||||
|
<property name="text">
|
||||||
|
<string>OBSWebsocket.Settings.AuthRequired</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="lbl_password">
|
||||||
|
<property name="text">
|
||||||
|
<string>OBSWebsocket.Settings.Password</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QLineEdit" name="password">
|
||||||
|
<property name="echoMode">
|
||||||
|
<enum>QLineEdit::Password</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QCheckBox" name="serverEnabled">
|
||||||
|
<property name="text">
|
||||||
|
<string>OBSWebsocket.Settings.ServerEnable</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="lbl_serverPort">
|
||||||
|
<property name="text">
|
||||||
|
<string>OBSWebsocket.Settings.ServerPort</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QSpinBox" name="serverPort">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>1024</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>65535</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>4444</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="1">
|
||||||
|
<widget class="QCheckBox" name="alertsEnabled">
|
||||||
|
<property name="text">
|
||||||
|
<string>OBSWebsocket.Settings.AlertsEnable</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="1">
|
||||||
|
<widget class="QCheckBox" name="debugEnabled">
|
||||||
|
<property name="text">
|
||||||
|
<string>OBSWebsocket.Settings.DebugEnable</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>SettingsDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>294</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>314</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>SettingsDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>300</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>314</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
80
src/obs-websocket.cpp
Normal file
80
src/obs-websocket.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
obs-websocket
|
||||||
|
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <obs-module.h>
|
||||||
|
#include <obs-frontend-api.h>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "obs-websocket.h"
|
||||||
|
#include "WSServer.h"
|
||||||
|
#include "WSEvents.h"
|
||||||
|
#include "Config.h"
|
||||||
|
#include "forms/settings-dialog.h"
|
||||||
|
|
||||||
|
void ___source_dummy_addref(obs_source_t*) {}
|
||||||
|
void ___sceneitem_dummy_addref(obs_sceneitem_t*) {}
|
||||||
|
void ___data_dummy_addref(obs_data_t*) {}
|
||||||
|
void ___data_array_dummy_addref(obs_data_array_t*) {}
|
||||||
|
void ___output_dummy_addref(obs_output_t*) {}
|
||||||
|
|
||||||
|
OBS_DECLARE_MODULE()
|
||||||
|
OBS_MODULE_USE_DEFAULT_LOCALE("obs-websocket", "en-US")
|
||||||
|
|
||||||
|
SettingsDialog* settings_dialog;
|
||||||
|
|
||||||
|
bool obs_module_load(void) {
|
||||||
|
blog(LOG_INFO, "you can haz websockets (version %s)", OBS_WEBSOCKET_VERSION);
|
||||||
|
blog(LOG_INFO, "qt version (compile-time): %s ; qt version (run-time): %s",
|
||||||
|
QT_VERSION_STR, qVersion());
|
||||||
|
|
||||||
|
// Core setup
|
||||||
|
Config* config = Config::Current();
|
||||||
|
config->Load();
|
||||||
|
|
||||||
|
WSServer::Instance = new WSServer();
|
||||||
|
WSEvents::Instance = new WSEvents(WSServer::Instance);
|
||||||
|
|
||||||
|
if (config->ServerEnabled)
|
||||||
|
WSServer::Instance->Start(config->ServerPort);
|
||||||
|
|
||||||
|
// UI setup
|
||||||
|
QAction* menu_action = (QAction*)obs_frontend_add_tools_menu_qaction(
|
||||||
|
obs_module_text("OBSWebsocket.Menu.SettingsItem"));
|
||||||
|
|
||||||
|
obs_frontend_push_ui_translation(obs_module_get_string);
|
||||||
|
QMainWindow* main_window = (QMainWindow*)obs_frontend_get_main_window();
|
||||||
|
settings_dialog = new SettingsDialog(main_window);
|
||||||
|
obs_frontend_pop_ui_translation();
|
||||||
|
|
||||||
|
auto menu_cb = [] {
|
||||||
|
settings_dialog->ToggleShowHide();
|
||||||
|
};
|
||||||
|
menu_action->connect(menu_action, &QAction::triggered, menu_cb);
|
||||||
|
|
||||||
|
// Loading finished
|
||||||
|
blog(LOG_INFO, "module loaded!");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void obs_module_unload() {
|
||||||
|
blog(LOG_INFO, "goodbye!");
|
||||||
|
}
|
||||||
|
|
46
src/obs-websocket.h
Normal file
46
src/obs-websocket.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
obs-websocket
|
||||||
|
Copyright (C) 2016-2017 Stéphane Lepin <stephane.lepin@gmail.com>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OBSWEBSOCKET_H
|
||||||
|
#define OBSWEBSOCKET_H
|
||||||
|
|
||||||
|
#include <obs.hpp>
|
||||||
|
|
||||||
|
void ___source_dummy_addref(obs_source_t*);
|
||||||
|
void ___sceneitem_dummy_addref(obs_sceneitem_t*);
|
||||||
|
void ___data_dummy_addref(obs_data_t*);
|
||||||
|
void ___data_array_dummy_addref(obs_data_array_t*);
|
||||||
|
void ___output_dummy_addref(obs_output_t*);
|
||||||
|
|
||||||
|
using OBSSourceAutoRelease =
|
||||||
|
OBSRef<obs_source_t*, ___source_dummy_addref, obs_source_release>;
|
||||||
|
using OBSSceneItemAutoRelease =
|
||||||
|
OBSRef<obs_sceneitem_t*, ___sceneitem_dummy_addref, obs_sceneitem_release>;
|
||||||
|
using OBSDataAutoRelease =
|
||||||
|
OBSRef<obs_data_t*, ___data_dummy_addref, obs_data_release>;
|
||||||
|
using OBSDataArrayAutoRelease =
|
||||||
|
OBSRef<obs_data_array_t*, ___data_array_dummy_addref, obs_data_array_release>;
|
||||||
|
using OBSOutputAutoRelease =
|
||||||
|
OBSRef<obs_output_t*, ___output_dummy_addref, obs_output_release>;
|
||||||
|
|
||||||
|
#define PROP_AUTHENTICATED "wsclient_authenticated"
|
||||||
|
#define OBS_WEBSOCKET_VERSION "4.5.1"
|
||||||
|
|
||||||
|
#define blog(level, msg, ...) blog(level, "[obs-websocket] " msg, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#endif // OBSWEBSOCKET_H
|
Reference in New Issue
Block a user