├── LICENSE ├── NOTICE ├── README.md ├── all-build.sh ├── base-displayaudio └── Dockerfile ├── docker-compose.yml ├── pull-push-all.sh └── remote-desktop-server ├── Dockerfile ├── mediacontroller.py ├── rebind.so ├── requirements.txt └── run.sh /LICENSE: -------------------------------------------------------------------------------- 1 | Version 2.0, January 2004 2 | http://www.apache.org/licenses/ 3 | 4 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 5 | 6 | 1. Definitions. 7 | 8 | "License" shall mean the terms and conditions for use, reproduction, 9 | and distribution as defined by Sections 1 through 9 of this document. 10 | 11 | "Licensor" shall mean the copyright owner or entity authorized by 12 | the copyright owner that is granting the License. 13 | 14 | "Legal Entity" shall mean the union of the acting entity and all 15 | other entities that control, are controlled by, or are under common 16 | control with that entity. For the purposes of this definition, 17 | "control" means (i) the power, direct or indirect, to cause the 18 | direction or management of such entity, whether by contract or 19 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity 23 | exercising permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, 26 | including but not limited to software source code, documentation 27 | source, and configuration files. 28 | 29 | "Object" form shall mean any form resulting from mechanical 30 | transformation or translation of a Source form, including but 31 | not limited to compiled object code, generated documentation, 32 | and conversions to other media types. 33 | 34 | "Work" shall mean the work of authorship, whether in Source or 35 | Object form, made available under the License, as indicated by a 36 | copyright notice that is included in or attached to the work 37 | (an example is provided in the Appendix below). 38 | 39 | "Derivative Works" shall mean any work, whether in Source or Object 40 | form, that is based on (or derived from) the Work and for which the 41 | editorial revisions, annotations, elaborations, or other modifications 42 | represent, as a whole, an original work of authorship. For the purposes 43 | of this License, Derivative Works shall not include works that remain 44 | separable from, or merely link (or bind by name) to the interfaces of, 45 | the Work and Derivative Works thereof. 46 | 47 | "Contribution" shall mean any work of authorship, including 48 | the original version of the Work and any modifications or additions 49 | to that Work or Derivative Works thereof, that is intentionally 50 | submitted to Licensor for inclusion in the Work by the copyright owner 51 | or by an individual or Legal Entity authorized to submit on behalf of 52 | the copyright owner. For the purposes of this definition, "submitted" 53 | means any form of electronic, verbal, or written communication sent 54 | to the Licensor or its representatives, including but not limited to 55 | communication on electronic mailing lists, source code control systems, 56 | and issue tracking systems that are managed by, or on behalf of, the 57 | Licensor for the purpose of discussing and improving the Work, but 58 | excluding communication that is conspicuously marked or otherwise 59 | designated in writing by the copyright owner as "Not a Contribution." 60 | 61 | "Contributor" shall mean Licensor and any individual or Legal Entity 62 | on behalf of whom a Contribution has been received by Licensor and 63 | subsequently incorporated within the Work. 64 | 65 | 2. Grant of Copyright License. Subject to the terms and conditions of 66 | this License, each Contributor hereby grants to You a perpetual, 67 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 68 | copyright license to reproduce, prepare Derivative Works of, 69 | publicly display, publicly perform, sublicense, and distribute the 70 | Work and such Derivative Works in Source or Object form. 71 | 72 | 3. Grant of Patent License. Subject to the terms and conditions of 73 | this License, each Contributor hereby grants to You a perpetual, 74 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 75 | (except as stated in this section) patent license to make, have made, 76 | use, offer to sell, sell, import, and otherwise transfer the Work, 77 | where such license applies only to those patent claims licensable 78 | by such Contributor that are necessarily infringed by their 79 | Contribution(s) alone or by combination of their Contribution(s) 80 | with the Work to which such Contribution(s) was submitted. If You 81 | institute patent litigation against any entity (including a 82 | cross-claim or counterclaim in a lawsuit) alleging that the Work 83 | or a Contribution incorporated within the Work constitutes direct 84 | or contributory patent infringement, then any patent licenses 85 | granted to You under this License for that Work shall terminate 86 | as of the date such litigation is filed. 87 | 88 | 4. Redistribution. You may reproduce and distribute copies of the 89 | Work or Derivative Works thereof in any medium, with or without 90 | modifications, and in Source or Object form, provided that You 91 | meet the following conditions: 92 | 93 | (a) You must give any other recipients of the Work or 94 | Derivative Works a copy of this License; and 95 | 96 | (b) You must cause any modified files to carry prominent notices 97 | stating that You changed the files; and 98 | 99 | (c) You must retain, in the Source form of any Derivative Works 100 | that You distribute, all copyright, patent, trademark, and 101 | attribution notices from the Source form of the Work, 102 | excluding those notices that do not pertain to any part of 103 | the Derivative Works; and 104 | 105 | (d) If the Work includes a "NOTICE" text file as part of its 106 | distribution, then any Derivative Works that You distribute must 107 | include a readable copy of the attribution notices contained 108 | within such NOTICE file, excluding those notices that do not 109 | pertain to any part of the Derivative Works, in at least one 110 | of the following places: within a NOTICE text file distributed 111 | as part of the Derivative Works; within the Source form or 112 | documentation, if provided along with the Derivative Works; or, 113 | within a display generated by the Derivative Works, if and 114 | wherever such third-party notices normally appear. The contents 115 | of the NOTICE file are for informational purposes only and 116 | do not modify the License. You may add Your own attribution 117 | notices within Derivative Works that You distribute, alongside 118 | or as an addendum to the NOTICE text from the Work, provided 119 | that such additional attribution notices cannot be construed 120 | as modifying the License. 121 | 122 | You may add Your own copyright statement to Your modifications and 123 | may provide additional or different license terms and conditions 124 | for use, reproduction, or distribution of Your modifications, or 125 | for any such Derivative Works as a whole, provided Your use, 126 | reproduction, and distribution of the Work otherwise complies with 127 | the conditions stated in this License. 128 | 129 | 5. Submission of Contributions. Unless You explicitly state otherwise, 130 | any Contribution intentionally submitted for inclusion in the Work 131 | by You to the Licensor shall be under the terms and conditions of 132 | this License, without any additional terms or conditions. 133 | Notwithstanding the above, nothing herein shall supersede or modify 134 | the terms of any separate license agreement you may have executed 135 | with Licensor regarding such Contributions. 136 | 137 | 6. Trademarks. This License does not grant permission to use the trade 138 | names, trademarks, service marks, or product names of the Licensor, 139 | except as required for reasonable and customary use in describing the 140 | origin of the Work and reproducing the content of the NOTICE file. 141 | 142 | 7. Disclaimer of Warranty. Unless required by applicable law or 143 | agreed to in writing, Licensor provides the Work (and each 144 | Contributor provides its Contributions) on an "AS IS" BASIS, 145 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 146 | implied, including, without limitation, any warranties or conditions 147 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 148 | PARTICULAR PURPOSE. You are solely responsible for determining the 149 | appropriateness of using or redistributing the Work and assume any 150 | risks associated with Your exercise of permissions under this License. 151 | 152 | 8. Limitation of Liability. In no event and under no legal theory, 153 | whether in tort (including negligence), contract, or otherwise, 154 | unless required by applicable law (such as deliberate and grossly 155 | negligent acts) or agreed to in writing, shall any Contributor be 156 | liable to You for damages, including any direct, indirect, special, 157 | incidental, or consequential damages of any character arising as a 158 | result of this License or out of the use or inability to use the 159 | Work (including but not limited to damages for loss of goodwill, 160 | work stoppage, computer failure or malfunction, or any and all 161 | other commercial damages or losses), even if such Contributor 162 | has been advised of the possibility of such damages. 163 | 164 | 9. Accepting Warranty or Additional Liability. While redistributing 165 | the Work or Derivative Works thereof, You may choose to offer, 166 | and charge a fee for, acceptance of support, warranty, indemnity, 167 | or other liability obligations and/or rights consistent with this 168 | License. However, in accepting such obligations, You may act only 169 | on Your own behalf and on Your sole responsibility, not on behalf 170 | of any other Contributor, and only if You agree to indemnify, 171 | defend, and hold each Contributor harmless for any liability 172 | incurred by, or claims asserted against, such Contributor by reason 173 | of your accepting any such warranty or additional liability. 174 | 175 | END OF TERMS AND CONDITIONS 176 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | remote-desktop-server 2 | Copyright 2018-2020 Webrecorder Software, Rhizome, and Contributors. 3 | 4 | Distributed under the Apache License 2.0. 5 | See LICENSE for details. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Remote Desktop Server Contains for Webrecorder/oldweb.today 2 | 3 | This repository represents the remote desktop system used by Webrecorder and new oldweb.today 4 | to stream the display and audio from remote browsers. 5 | 6 | In Webrecorder/OWT, the system is used to stream contents of web browsers but can apply to any Linux desktop application. 7 | 8 | ## Desktop Streaming Options 9 | 10 | The system provides several connection options for streaming a Linux desktop and audio using VNC and WebRTC. 11 | 12 | The options are: 13 | 14 | - Full WebRTC: Streaming desktop via WebRTC connection (H264 or VP8) and audio (Opus). 15 | 16 | - VNC Video + WebRTC Audio: Streaming desktop via VNC and audio using WebRTC (Opus). 17 | 18 | - Vnc Video + WS Audio: Streaming desktop via VNC and audio stream over a WebSocket connection (either MP3 or OPUS) 19 | 20 | 21 | The `oldwebtoday/remote-desktop-server` supports options for all three and the method can be determined at runtime via the client. 22 | 23 | The system is designed to work with an in-browser client, which can determine which connection method to use. 24 | See [oldweb-today/shepherd-client](https://github.com/oldweb-today/shepherd-client) for more info. 25 | 26 | 27 | 28 | ## Architecture 29 | 30 | The system is comprised of two Docker containers: 31 | 32 | - `oldwebtoday/base-displayaudio`: This container sets up the base infrastructure, installing GStreamer, x11vnc, Python, etc.. necessary for streaming 33 | 34 | - `oldwebtoday/remote-desktop-server`: This container sets up a Python based media controller, which receives messages via WebSocket. The controller acts 35 | as a signalling server to set up the WebRTC connection. When using streaming audio, it transmits audio packets directly over the WebSocket. 36 | When using VNC, the x11vnc server is used with websockify to transmit VNC data over a separate websocket. 37 | 38 | -------------------------------------------------------------------------------- /all-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CURR_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 4 | pushd $CURR_DIR/ 5 | 6 | docker-compose build 7 | 8 | popd 9 | -------------------------------------------------------------------------------- /base-displayaudio/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:bionic 2 | 3 | # Adapted from https://github.com/radiokit/docker-gstreamer/blob/master/Dockerfile 4 | RUN apt-get -y update 5 | 6 | # Install compiler etc. 7 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \ 8 | autoconf \ 9 | automake \ 10 | autopoint \ 11 | bison \ 12 | flex \ 13 | libtool \ 14 | yasm \ 15 | nasm \ 16 | git-core \ 17 | build-essential \ 18 | gettext \ 19 | pulseaudio \ 20 | gtk-doc-tools 21 | 22 | # Install dependencies necessary to build our custom GStreamer build 23 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \ 24 | libglib2.0-dev \ 25 | libpthread-stubs0-dev \ 26 | libssl-dev \ 27 | liborc-dev \ 28 | libmpg123-dev \ 29 | libmp3lame-dev \ 30 | libsoup2.4-dev \ 31 | libshout3-dev \ 32 | libpulse-dev \ 33 | libopus-dev \ 34 | libgirepository1.0-dev \ 35 | libsrtp2-dev \ 36 | libvpx-dev \ 37 | libx11-dev \ 38 | libxv-dev \ 39 | libxt-dev \ 40 | libx264-dev \ 41 | libgnutls28-dev \ 42 | python-gi-dev \ 43 | python-dev \ 44 | libxfixes-dev 45 | 46 | 47 | ARG GIT_COMMIT=1.16.2 48 | ARG LIB_NICE_VERSION=0.1.16 49 | 50 | # 51 | # Fetch and build GStreamer 52 | RUN git clone -b $GIT_COMMIT git://anongit.freedesktop.org/git/gstreamer/gstreamer && \ 53 | cd gstreamer && \ 54 | ./autogen.sh --prefix=/usr --disable-gtk-doc && \ 55 | make -j`nproc` && \ 56 | make install && \ 57 | cd .. && \ 58 | rm -rvf /gstreamer 59 | 60 | # Fetch and build gst-plugins-base 61 | RUN git clone -b $GIT_COMMIT --depth 1 git://anongit.freedesktop.org/git/gstreamer/gst-plugins-base && \ 62 | cd gst-plugins-base && \ 63 | ./autogen.sh --prefix=/usr \ 64 | --disable-gtk-doc \ 65 | --disable-adder \ 66 | --disable-app \ 67 | #--disable-videoconvert \ 68 | --disable-gio \ 69 | --disable-subparse \ 70 | #--disable-tcp \ 71 | #--disable-videotestsrc \ 72 | --disable-videorate \ 73 | --disable-videoscale \ 74 | #--disable-x \ 75 | --disable-xvideo \ 76 | --disable-xshm \ 77 | --disable-alsa \ 78 | --disable-cdparanoia \ 79 | --disable-ivorbis \ 80 | --disable-libvisual \ 81 | --disable-pango \ 82 | --disable-theora && \ 83 | make -j`nproc` && \ 84 | make install && \ 85 | cd .. && \ 86 | rm -rvf /gst-plugins-base 87 | 88 | 89 | # libnice 90 | 91 | 92 | RUN git clone -b $LIB_NICE_VERSION git://anongit.freedesktop.org/libnice/libnice \ 93 | && cd libnice \ 94 | && git checkout $LIB_NICE_VERSION \ 95 | && ./autogen.sh --prefix=/usr --with-gstreamer --enable-static --enable-static-plugins --enable-shared --without-gstreamer-0.10 --disable-gtk-doc --enable-compile-warnings=no \ 96 | && make install && \ 97 | cd .. && \ 98 | rm -rvf /libnice 99 | 100 | 101 | # Fetch and build gst-plugins-good 102 | RUN git clone -b $GIT_COMMIT --depth 1 git://anongit.freedesktop.org/git/gstreamer/gst-plugins-good && \ 103 | cd gst-plugins-good && \ 104 | ./autogen.sh --prefix=/usr \ 105 | --enable-ximagesrc-xfixes \ 106 | --disable-gtk-doc \ 107 | --disable-alpha \ 108 | --disable-avi \ 109 | --disable-deinterlace \ 110 | --disable-dtmf \ 111 | --disable-effectv \ 112 | --disable-flv \ 113 | --disable-flx \ 114 | --disable-goom \ 115 | --disable-goom2k1 \ 116 | --disable-imagefreeze \ 117 | --disable-interleave \ 118 | --disable-isomp4 \ 119 | #--disable-matroska \ 120 | --disable-monoscope \ 121 | #--disable-rtp \ 122 | #--disable-rtpmanager \ 123 | --disable-rtsp \ 124 | --disable-shapewipe \ 125 | --disable-smpte \ 126 | --disable-udp \ 127 | --disable-videobox \ 128 | --disable-videocrop \ 129 | --disable-videofilter \ 130 | --disable-videomixer \ 131 | --disable-y4m \ 132 | --disable-directsound \ 133 | --disable-waveform \ 134 | --disable-oss \ 135 | --disable-oss4 \ 136 | --disable-sunaudio \ 137 | --disable-osx_audio \ 138 | --disable-osx_video \ 139 | --disable-gst_v4l2 \ 140 | #--disable-x \ 141 | --disable-aalib \ 142 | --disable-aalibtest \ 143 | --disable-cairo \ 144 | --disable-flac \ 145 | --disable-gdk_pixbuf \ 146 | --disable-jack \ 147 | --disable-jpeg \ 148 | --disable-libcaca \ 149 | --disable-libdv \ 150 | --disable-libpng \ 151 | --disable-dv1394 \ 152 | #--disable-vpx 153 | && \ 154 | make -j`nproc` && \ 155 | make install && \ 156 | cd .. && \ 157 | rm -rvf /gst-plugins-good 158 | 159 | # Fetch and build gst-plugins-bad 160 | #RUN git clone -b $GIT_BRANCH --depth 1 git://anongit.freedesktop.org/git/gstreamer/gst-plugins-bad && \ 161 | #cd gst-plugins-bad && \ 162 | #git checkout $GIT_BRANCH && \ 163 | #RUN git clone -b webrtc-port-range --depth 1 https://gitlab.freedesktop.org/ikreymer/gst-plugins-bad.git && \ 164 | RUN git clone -b $GIT_COMMIT --depth 1 https://github.com/GStreamer/gst-plugins-bad.git && \ 165 | cd gst-plugins-bad && \ 166 | ./autogen.sh --prefix=/usr \ 167 | --disable-gtk-doc \ 168 | --disable-accurip \ 169 | --disable-adpcmdec \ 170 | --disable-adpcmenc \ 171 | --disable-aiff \ 172 | --disable-videoframe_audiolevel \ 173 | --disable-asfmux \ 174 | --disable-compositor \ 175 | --disable-bayer \ 176 | --disable-camerabin2 \ 177 | --disable-coloreffects \ 178 | --disable-dvbsuboverlay \ 179 | --disable-dvdspu \ 180 | --disable-faceoverlay \ 181 | --disable-festival \ 182 | --disable-fieldanalysis \ 183 | --disable-freeverb \ 184 | --disable-frei0r \ 185 | --disable-gaudieffects \ 186 | --disable-geometrictransform \ 187 | --disable-gdp \ 188 | --disable-inter \ 189 | --disable-interlace \ 190 | --disable-ivfparse \ 191 | --disable-ivtc \ 192 | --disable-jp2kdecimator \ 193 | --disable-jpegformat \ 194 | --disable-librfb \ 195 | --disable-midi \ 196 | --disable-mpegdemux \ 197 | --disable-mpegtsdemux \ 198 | --disable-mpegtsmux \ 199 | --disable-mpegpsmux \ 200 | --disable-mxf \ 201 | --disable-netsim \ 202 | --disable-onvif \ 203 | --disable-pcapparse \ 204 | --disable-pnm \ 205 | --disable-rawparse \ 206 | --disable-sdp \ 207 | --disable-siren \ 208 | --disable-smooth \ 209 | --disable-speed \ 210 | --disable-subenc \ 211 | --disable-timecode \ 212 | --disable-videofilters \ 213 | --disable-videoparsers \ 214 | --disable-videosignal \ 215 | --disable-vmnc \ 216 | --disable-y4m \ 217 | --disable-yadif \ 218 | --disable-directsound \ 219 | --disable-wasapi \ 220 | --disable-direct3d \ 221 | --disable-winscreencap \ 222 | --disable-winks \ 223 | --disable-android_media \ 224 | --disable-apple_media \ 225 | --disable-bluez \ 226 | --disable-avc \ 227 | --disable-shm \ 228 | --disable-vcd \ 229 | --disable-opensles \ 230 | --disable-uvch264 \ 231 | --disable-nvenc \ 232 | --disable-tinyalsa \ 233 | --disable-msdk \ 234 | --disable-assrender \ 235 | --disable-voamrwbenc \ 236 | --disable-voaacenc \ 237 | --disable-bs2b \ 238 | --disable-bz2 \ 239 | --disable-chromaprint \ 240 | --disable-curl \ 241 | --disable-dash \ 242 | --disable-dc1394 \ 243 | --disable-decklink \ 244 | --disable-directfb \ 245 | --disable-wayland \ 246 | --disable-webp \ 247 | --disable-daala \ 248 | --disable-dts \ 249 | --disable-resindvd \ 250 | --disable-faac \ 251 | --disable-faad \ 252 | --disable-fbdev \ 253 | --disable-fdk_aac \ 254 | --disable-flite \ 255 | --disable-gsm \ 256 | --disable-fluidsynth \ 257 | --disable-kate \ 258 | --disable-kms \ 259 | --disable-ladspa \ 260 | --disable-lv2 \ 261 | --disable-libde265 \ 262 | --disable-libmms \ 263 | #--disable-srtp \ 264 | #--disable-dtls \ 265 | --disable-ttml \ 266 | --disable-modplug \ 267 | --disable-mpeg2enc \ 268 | --disable-mplex \ 269 | --disable-musepack \ 270 | --disable-neon \ 271 | --disable-ofa \ 272 | --disable-openal \ 273 | --disable-opencv \ 274 | --disable-openexr \ 275 | --disable-openh264 \ 276 | --disable-openjpeg \ 277 | --disable-openmpt \ 278 | --disable-openni2 \ 279 | --disable-rsvg \ 280 | --disable-gl \ 281 | --disable-gtk3 \ 282 | --disable-qt \ 283 | --disable-vulkan \ 284 | --disable-teletextdec \ 285 | --disable-wildmidi \ 286 | --disable-smoothstreaming \ 287 | --disable-sndfile \ 288 | --disable-soundtouch \ 289 | --disable-spc \ 290 | --disable-gme \ 291 | --disable-dvb \ 292 | --disable-acm \ 293 | --disable-vdpau \ 294 | --disable-sbc \ 295 | --disable-schro \ 296 | --disable-zbar \ 297 | --disable-rtmp \ 298 | --disable-spandsp \ 299 | --disable-hls \ 300 | --disable-x265 \ 301 | --disable-webrtcdsp && \ 302 | make -j`nproc` && \ 303 | make install && \ 304 | cd .. && \ 305 | rm -rvf /gst-plugins-bad && echo "" 306 | 307 | 308 | # Fetch and build gst-plugins-ugly 309 | RUN git clone -b $GIT_COMMIT --depth 1 git://anongit.freedesktop.org/git/gstreamer/gst-plugins-ugly && \ 310 | cd gst-plugins-ugly && \ 311 | ./autogen.sh --prefix=/usr \ 312 | --disable-gtk-doc \ 313 | --disable-asfdemux \ 314 | --disable-dvdlpcmdec \ 315 | --disable-dvdsub \ 316 | --disable-xingmux \ 317 | --disable-realmedia \ 318 | --disable-a52dec \ 319 | --disable-amrnb \ 320 | --disable-amrwb \ 321 | --disable-cdio \ 322 | --disable-dvdread \ 323 | --disable-sidplay \ 324 | #--disable-x264 \ 325 | && \ 326 | make -j`nproc` && \ 327 | make install && \ 328 | cd .. && \ 329 | rm -rvf /gst-plugins-ugly 330 | 331 | 332 | 333 | 334 | # install gst-python 335 | RUN git clone -b $GIT_COMMIT --depth 1 git://anongit.freedesktop.org/git/gstreamer/gst-python && \ 336 | cd gst-python && \ 337 | ./autogen.sh --prefix=/usr && \ 338 | make -j`nproc` && \ 339 | make install && \ 340 | cd .. && \ 341 | rm -rvf /gst-python 342 | 343 | # Do some cleanup 344 | RUN DEBIAN_FRONTEND=noninteractive apt-get clean && \ 345 | apt-get autoremove -y 346 | 347 | # configure pulseaudio 348 | RUN echo "load-module module-native-protocol-tcp auth-anonymous=1 auth-ip-acl=0.0.0.0/0" >> /etc/pulse/default.pa 349 | RUN echo "load-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/.X11-unix/pulse-socket" >> /etc/pulse/default.pa 350 | 351 | RUN sed -i '/load-module module-console-kit/s/^/#/' /etc/pulse/default.pa 352 | 353 | # env vars 354 | ENV DISPLAY :99 355 | 356 | ENV SCREEN_WIDTH 1360 357 | ENV SCREEN_HEIGHT 1020 358 | ENV SCREEN_DEPTH 16 359 | 360 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | # Build All Base Images 4 | services: 5 | # Base for display + audio transport 6 | base-displayaudio: 7 | image: oldwebtoday/base-displayaudio 8 | build: 9 | context: ./base-displayaudio 10 | args: 11 | GIT_COMMIT: '1.16.2' 12 | 13 | # VNC + WetRTC AUDIO 14 | remote-desktop-server: 15 | image: oldwebtoday/remote-desktop-server 16 | build: ./remote-desktop-server 17 | depends_on: 18 | - base-displayaudio 19 | 20 | -------------------------------------------------------------------------------- /pull-push-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | action=pull 4 | echo "$1" 5 | 6 | if [ ! -z $1 ]; then 7 | action=$1 8 | fi 9 | 10 | docker $action oldwebtoday/base-displayaudio 11 | docker $action oldwebtoday/remote-desktop-server 12 | 13 | -------------------------------------------------------------------------------- /remote-desktop-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM oldwebtoday/base-displayaudio 2 | 3 | RUN DEBIAN_FRONTEND=noninteractive apt-get -y update && \ 4 | DEBIAN_FRONTEND=noninteractive apt-get -qqy --no-install-recommends install \ 5 | x11vnc \ 6 | xvfb \ 7 | sudo \ 8 | python3-pip 9 | 10 | WORKDIR /app/ 11 | 12 | COPY requirements.txt /app/ 13 | 14 | RUN pip3 install -U setuptools pip 15 | 16 | RUN pip3 install -U -r requirements.txt 17 | 18 | COPY rebind.so /usr/local/lib/rebind.so 19 | 20 | COPY . /app/ 21 | 22 | RUN ln -s /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so /usr/lib/libpython2.7.so 23 | 24 | CMD /app/run.sh 25 | 26 | 27 | -------------------------------------------------------------------------------- /remote-desktop-server/mediacontroller.py: -------------------------------------------------------------------------------- 1 | import websockets 2 | import socket 3 | import asyncio 4 | import os 5 | import sys 6 | import json 7 | import argparse 8 | import logging 9 | import hmac 10 | import base64 11 | import hashlib 12 | import time 13 | import subprocess 14 | from concurrent.futures._base import TimeoutError 15 | 16 | import gi 17 | gi.require_version('Gst', '1.0') 18 | from gi.repository import Gst 19 | gi.require_version('GstWebRTC', '1.0') 20 | from gi.repository import GstWebRTC 21 | gi.require_version('GstSdp', '1.0') 22 | from gi.repository import GstSdp 23 | 24 | 25 | # ============================================================================ 26 | AUDIO_PIPELINE = "pulsesrc ! audioconvert ! opusenc frame-size=5 ! rtpopuspay ! queue max-size-time=200 min-threshold-time=200000000 max-size-time=220000000 ! capsfilter caps=application/x-rtp,media=audio,encoding-name=OPUS,payload=96" 27 | 28 | VP8_PIPELINE = "ximagesrc show-pointer=false ! videoconvert ! queue ! vp8enc deadline=1 buffer-size=100 buffer-initial-size=100 buffer-optimal-size=100 keyframe-max-dist=30 cpu-used=-16 ! rtpvp8pay ! queue ! capsfilter caps=application/x-rtp,media=video,encoding-name=VP8,payload=97" 29 | H264_PIPELINE = "ximagesrc show-pointer=false ! videoconvert ! queue ! x264enc tune=0x00000004 key-int-max=30 ! video/x-h264,profile=constrained-baseline,packetization-mode=1 ! rtph264pay ! queue max-size-time=50 ! capsfilter caps=application/x-rtp,media=video,encoding-name=H264,payload=97" 30 | 31 | PIPELINES = {'VP8': VP8_PIPELINE, 32 | 'H264': H264_PIPELINE 33 | } 34 | 35 | # standalone audio pipelines 36 | AUDIO_MS_MP3_PIPELINE = 'gst-launch-1.0 -v pulsesrc buffer-time=128000 latency-time=32000 ! audioconvert ! lamemp3enc target=bitrate cbr=true bitrate=192 ! tcpserversink port=5555' 37 | 38 | AUDIO_MS_OPUS_PIPELINE = 'gst-launch-1.0 -v pulsesrc buffer-time=128000 latency-time=32000 ! audio/x-raw, channels=2, rate=24000 ! audioconvert ! opusenc complexity=0 frame-size=5 ! webmmux streamable=true ! tcpserversink port=5555' 39 | 40 | 41 | # ============================================================================ 42 | class WebRTCHandler: 43 | def __init__(self, ws, keepalive_timeout=30): 44 | self.ws = ws 45 | self.pipe = None 46 | self.webrtc = None 47 | self.keepalive_timeout = keepalive_timeout 48 | self.buff_size = 16384*4 49 | #self.buff_size = 64000 * 3 50 | #self.buff_size = 128000 51 | def send_sdp_offer(self, offer): 52 | text = offer.sdp.as_text() 53 | print('Sending offer:\n%s' % text) 54 | msg = json.dumps({'sdp': {'type': 'offer', 'sdp': text}}) 55 | 56 | loop = asyncio.new_event_loop() 57 | loop.run_until_complete(self.ws.send(msg)) 58 | 59 | def on_offer_created(self, promise, _, __): 60 | promise.wait() 61 | reply = promise.get_reply() 62 | offer = reply.get_value('offer') 63 | 64 | promise = Gst.Promise.new() 65 | self.webrtc.emit('set-local-description', offer, promise) 66 | promise.interrupt() 67 | self.send_sdp_offer(offer) 68 | 69 | def on_negotiation_needed(self, element): 70 | promise = Gst.Promise.new_with_change_func(self.on_offer_created, element, None) 71 | element.emit('create-offer', None, promise) 72 | 73 | def send_ice_candidate_message(self, _, mlineindex, candidate): 74 | 75 | icemsg = json.dumps({'ice': {'candidate': candidate, 'sdpMLineIndex': mlineindex}}) 76 | 77 | loop = asyncio.new_event_loop() 78 | loop.run_until_complete(self.ws.send(icemsg)) 79 | 80 | async def start_ms_audio(self, format): 81 | if format == 'mp3': 82 | command = AUDIO_MS_MP3_PIPELINE 83 | else: 84 | command = AUDIO_MS_OPUS_PIPELINE 85 | 86 | print('Opening {command}'.format(**locals())) 87 | pid = subprocess.Popen(command.split(' ')) 88 | wait_for_port(5555) 89 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 90 | s.connect(("localhost", 5555)) 91 | print('connected for MsAudio') 92 | self.sending = True 93 | while self.sending: 94 | data = s.recv(self.buff_size) 95 | await self.ws.send(data) 96 | s.close() 97 | os.kill(pid) 98 | 99 | def generate_rest_api_credentials(self, username, secret): 100 | # Coturn REST API 101 | # usercombo -> "timestamp.username", 102 | # turn user -> usercombo, 103 | # turn password -> base64(hmac(input_buffer = usercombo, key = shared-secret)). 104 | time_limit = int(os.environ.get("WEBRTC_TURN_TIME_LIMIT", '3600')) 105 | separator = os.environ.get("WEBRTC_TURN_REST_API_SEPARATOR", '.').encode() 106 | turn_username = username.encode() 107 | turn_secret = secret.encode() 108 | now = "{}".format(int(time.time() + time_limit)).encode() 109 | username = separator.join([now, turn_username]) 110 | password = base64.b64encode(hmac.new(turn_secret, username, digestmod=hashlib.sha1).digest()) 111 | 112 | return {"username": username.decode("utf8"), "password": password.decode("utf8")} 113 | 114 | 115 | async def send_ice_credentials(self): 116 | username = os.environ.get("REQ_ID") + 'client' 117 | secret = os.environ.get('WEBRTC_TURN_REST_AUTH_SECRET') 118 | credentials = self.generate_rest_api_credentials(username, secret) 119 | await self.ws.send(json.dumps(credentials)) 120 | 121 | def launch_x11vnc(self, vnc_video=True): 122 | display = os.environ.get('DISPLAY') 123 | command = 'x11vnc -forever -ncache_cr -xdamage -usepw -shared -rfbport 5900 -display ' + display 124 | if not vnc_video: 125 | command = command + ' --slow_fb 10 --noxrandr' 126 | process_exist = subprocess.call(['ps', '-C', 'x11vnc']) 127 | if process_exist == 0: 128 | print("Killing x11vnc") 129 | subprocess.call('pkill -9 x11vnc', shell=True) 130 | print("starting x11vnc [{}]".format(command)) 131 | pid = subprocess.Popen(command.split(' ')).pid 132 | print('x11 pid is {}'.format(pid)) 133 | 134 | websockify_pid = subprocess.Popen(['websockify', '6080', 'localhost:5900']).pid 135 | 136 | def start_pipeline(self, video_formats, audio_only): 137 | pipeline = None 138 | video = None 139 | 140 | if not audio_only: 141 | for format_type in video_formats: 142 | pipeline = PIPELINES.get(format_type) 143 | if pipeline: 144 | print('Video Format: ' + format_type) 145 | break 146 | 147 | pipeline = pipeline or VP8_PIPELINE 148 | video = Gst.parse_bin_from_description(pipeline, True) 149 | 150 | audio = Gst.parse_bin_from_description(AUDIO_PIPELINE, True) 151 | 152 | webrtc = Gst.ElementFactory.make("webrtcbin", "sendonly") 153 | webrtc.set_property('bundle-policy', 'max-bundle') 154 | 155 | pipe = Gst.Pipeline.new('main') 156 | 157 | if video: 158 | pipe.add(video) 159 | pipe.add(audio) 160 | pipe.add(webrtc) 161 | 162 | if video: 163 | video.link(webrtc) 164 | 165 | audio.link(webrtc) 166 | 167 | self.pipe = pipe 168 | 169 | self.webrtc = self.pipe.get_by_name('sendonly') 170 | 171 | self.webrtc.connect('on-negotiation-needed', self.on_negotiation_needed) 172 | self.webrtc.connect('on-ice-candidate', self.send_ice_candidate_message) 173 | #self.webrtc.connect('notify::ice-connection-state', self.on_conn_changed) 174 | self.pipe.set_state(Gst.State.PLAYING) 175 | 176 | async def handle_message(self, message): 177 | #assert (self.webrtc) 178 | msg = json.loads(message) 179 | if 'webrtc' in msg: 180 | video_formats = msg.get('webrtc_video') 181 | audio_only = not video_formats 182 | self.launch_x11vnc(audio_only) 183 | time.sleep(1) 184 | print('sending ice credentials') 185 | await self.send_ice_credentials() 186 | self.start_pipeline(video_formats, audio_only) 187 | if 'ms_audio' in msg: 188 | ms_audio = msg['ms_audio'] 189 | if ms_audio == 'reset': 190 | self.sending = False 191 | else: 192 | await self.start_ms_audio(ms_audio) 193 | 194 | if 'sdp' in msg: 195 | sdp = msg['sdp'] 196 | assert(sdp['type'] == 'answer') 197 | sdp = sdp['sdp'] 198 | print('Received answer:\n%s' % sdp) 199 | res, sdpmsg = GstSdp.SDPMessage.new() 200 | GstSdp.sdp_message_parse_buffer(bytes(sdp.encode()), sdpmsg) 201 | answer = GstWebRTC.WebRTCSessionDescription.new(GstWebRTC.WebRTCSDPType.ANSWER, sdpmsg) 202 | promise = Gst.Promise.new() 203 | 204 | self.webrtc.emit('set-remote-description', answer, promise) 205 | promise.interrupt() 206 | elif 'ice' in msg: 207 | ice = msg['ice'] 208 | candidate = ice['candidate'] 209 | sdpmlineindex = ice['sdpMLineIndex'] 210 | self.webrtc.emit('add-ice-candidate', sdpmlineindex, candidate) 211 | 212 | async def loop(self): 213 | assert self.ws 214 | while True: 215 | message = await self.recv_msg_ping() 216 | if message.startswith('HELLO'): 217 | await self.ws.send('HELLO') 218 | 219 | elif message.startswith('ERROR'): 220 | print(message) 221 | return 1 222 | else: 223 | await self.handle_message(message) 224 | 225 | return 0 226 | 227 | async def recv_msg_ping(self): 228 | ''' 229 | Wait for a message forever, and send a regular ping to prevent bad routers 230 | from closing the connection. 231 | ''' 232 | msg = None 233 | while msg is None: 234 | try: 235 | msg = await asyncio.wait_for(self.ws.recv(), self.keepalive_timeout) 236 | #msg = await self.ws.recv() 237 | except TimeoutError: 238 | print('Signaling: Send Keep-Alive Ping') 239 | await self.ws.ping() 240 | 241 | return msg 242 | 243 | def disconnect(self): 244 | if self.ws and self.ws.open: 245 | # Don't care about errors 246 | asyncio.ensure_future(self.ws.close(reason='hangup')) 247 | 248 | if self.pipe: 249 | self.pipe.set_state(Gst.State.NULL) 250 | 251 | 252 | # ============================================================================ 253 | class WebRTCServer(): 254 | def __init__(self): 255 | self.curr = None 256 | self.keepalive_timeout = 30 257 | 258 | async def handler_loop(self, ws, path=None): 259 | ''' 260 | All incoming messages are handled here. @path is unused. 261 | ''' 262 | if self.curr: 263 | print('Pipeline Already Running?') 264 | 265 | handler = WebRTCHandler(ws, self.keepalive_timeout) 266 | self.curr = handler 267 | 268 | try: 269 | await handler.loop() 270 | except websockets.ConnectionClosed: 271 | print('Client Disconnected') 272 | 273 | finally: 274 | print('Closing Connection') 275 | handler.disconnect() 276 | 277 | print('Exiting') 278 | sys.exit(0) 279 | 280 | def run_server(self, server_addr, keepalive_timeout): 281 | print("Signaling: Listening on https://{}:{}".format(*server_addr)) 282 | 283 | self.keepalive_timeout = keepalive_timeout 284 | 285 | logger = logging.getLogger('websockets.server') 286 | 287 | logger.setLevel(logging.ERROR) 288 | logger.addHandler(logging.StreamHandler()) 289 | 290 | wsd = websockets.serve(self.handler_loop, *server_addr, max_queue=4) 291 | 292 | asyncio.get_event_loop().run_until_complete(wsd) 293 | asyncio.get_event_loop().run_forever() 294 | 295 | 296 | def check_plugins(self): 297 | needed = ["opus", "vpx", "nice", "webrtc", "dtls", 298 | "srtp", "rtp", "rtpmanager"] 299 | 300 | missing = list(filter(lambda p: Gst.Registry.get().find_plugin(p) is None, needed)) 301 | if len(missing): 302 | print('Missing gstreamer plugins:', missing) 303 | return False 304 | return True 305 | 306 | 307 | def init_cli(self): 308 | Gst.init(None) 309 | if not self.check_plugins(): 310 | sys.exit(1) 311 | 312 | parser = argparse.ArgumentParser() 313 | parser.add_argument('--addr', default='0.0.0.0', help='Address to listen on') 314 | parser.add_argument('--port', default=80, type=int, help='Port to listen on') 315 | parser.add_argument('--keepalive-timeout', dest='keepalive_timeout', default=30, type=int, help='Timeout for keepalive (in seconds)') 316 | 317 | args = parser.parse_args() 318 | 319 | self.run_server((args.addr, args.port), args.keepalive_timeout) 320 | 321 | 322 | def wait_for_port(port, host='localhost', timeout=5.0): 323 | start_time = time.perf_counter() 324 | while True: 325 | try: 326 | with socket.create_connection((host, port), timeout=timeout): 327 | break 328 | except Exception as ex: 329 | time.sleep(0.01) 330 | if time.perf_counter() - start_time >= timeout: 331 | raise Exception("Waited too long for the port {} on host {} to start accepting connections.".format(port, host)) 332 | 333 | if __name__=='__main__': 334 | WebRTCServer().init_cli() 335 | 336 | 337 | -------------------------------------------------------------------------------- /remote-desktop-server/rebind.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oldweb-today/remote-desktop-server/887124c2dd92b171325a0cb461d094eceffea171/remote-desktop-server/rebind.so -------------------------------------------------------------------------------- /remote-desktop-server/requirements.txt: -------------------------------------------------------------------------------- 1 | websockets 2 | websockify 3 | -------------------------------------------------------------------------------- /remote-desktop-server/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "### Start Xvfb" 4 | export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH" 5 | 6 | Xvfb $DISPLAY -listen tcp -screen 0 $GEOMETRY -ac +extension RANDR & 7 | 8 | 9 | echo "### Init X11 Password" 10 | mkdir -p ~/.vnc 11 | x11vnc -storepasswd ${VNC_PASS:-secret} ~/.vnc/passwd 12 | 13 | 14 | echo "### Start PulseAudio" 15 | pulseaudio -D 16 | 17 | 18 | echo "### Start Media Controller" 19 | function run_forever() { 20 | while 'true' 21 | do 22 | echo "Execute '$@'" 23 | "$@" 24 | if [ $? -eq 0 ]; then 25 | if [[ -n "$IDLE_TIMEOUT" ]]; then 26 | echo "Waiting for $IDLE_TIMEOUT before exiting..." 27 | sleep $IDLE_TIMEOUT 28 | fi 29 | echo "Done" 30 | exit 0 31 | fi 32 | 33 | sleep 1 34 | done 35 | } 36 | 37 | run_forever python3 -u /app/mediacontroller.py --port 6082 38 | 39 | --------------------------------------------------------------------------------