From fba0b6a37d65dfa77c8b14a4a91131acce6160d7 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Feb 2024 13:00:41 -0500 Subject: [PATCH] multiplayer ipx --- README.md | 140 ++++++++++---------- archive/dockerfile | 82 ++++++------ client.conf | 2 +- default.pa | 6 +- dockerfile | 124 ++++++++--------- dosbox.conf | 250 +++++++++++++++++++++++++++++++++++ gh-actions-with-aks-aci.yaml | 152 ++++++++++----------- keen.yml | 68 +++++----- keen/FILE_ID.DIZ | 16 +-- multiplayer.yml | 97 ++++++++++++++ nginx.conf | 80 +++++------ supervisord.conf | 100 +++++++------- webaudio.js | 242 ++++++++++++++++----------------- xstartup | 3 + 14 files changed, 850 insertions(+), 512 deletions(-) create mode 100644 dosbox.conf create mode 100644 multiplayer.yml create mode 100644 xstartup diff --git a/README.md b/README.md index 4f331b6..1120b7a 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,70 @@ -# DOSBOX IN A CONTAINER WITH VNC CLIENT -- NOW WITH SOUND! - -So much fun! After 3 years, I decided to bite the bullet and figure out how to add sound... and now it has it. I completely overhauled the Dockerfile to use Suerpvisor to start the processes because there were simply too many after adding support for sound. The rest of it is similar to the original, which is in an archive folder in this repo. In any case, I hope you enjoy it! - -1. Clone the repo: `git clone https://github.com/theonemule/dos-game.git` -1. Place a copy of your game in the folder. I am using the shareware version of Commander Keen here. -1. Replace the `COPY keen /dos/keen` with your game (ie. COPY wolf3d /dos/wolf3d). 1. You can also change the default password or override it with a -e parameter when you run the image. -1. Now, with Docker, build the image. I’m assuming you already have Docker installed and are somewhat familiar with it. CD to the directory in a console and run the command… - ```` - docker build -t mydosbox . - ```` -1. Run the image. - ```` - docker run -p 6080:80 mydosbox - ```` - -1. Open a browser and point it to http://localhost:6080/vnc.html -1. You should see a prompt for the password. Type it in, and you should be able to connect to your container with DosBox running. The game is started automatically. -1. Once your image is built, you can push it to your image repository with docker push, but you’ll need to tag it appropriately. - -# USE WITH KUBERNETES -Kubernetes is another part of the equation when it comes to container apps. Containers on Kubernetes are deployed into pods, which are then usually a part of a deployment with one or more pods associated. Deployments can also be used to create scalable sets of pods for high availability on a Kubernetes cluster. If you’re unfamiliar with Kubernetes, check out this webinar below, where I go in-depth. - -Deployments and services can be defined declaratively with a YAML file. Below is a Kubernetes YAML file that defines a deployment and a service for my retro gaming container. - -The deployment is simple – it points to a single container image called blaize/keen and then tells Kubernetes what ports to expose for the container. The service defines how the deployment will be exposed on a network. In this case, it’s using a TCP load balancer, exposing port 80 and mapping that to the port exposed by the deployment. The service uses selectors on the label app to match the service with the deployment. - -```` -apiVersion: v1 -kind: Service -metadata: - name: keen-service - labels: - app: keen-deployment -spec: - ports: - - port: 80 - targetPort: 6080 - selector: - app: keen-deployment - type: LoadBalancer ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: keen-deployment -spec: - selector: - matchLabels: - app: keen-deployment - replicas: 1 - template: - metadata: - labels: - app: keen-deployment - spec: - containers: - - name: master - image: blaize/keen - ports: - - containerPort: 80 -```` - -To connect, use this, first create a file called keen.yaml file, configure your instance kubectl to work with your instance of Kubernetes, then run deploy the sample. - -```` -kubectl create -f keen.yaml -```` - -When this is deployed to Kubernetes, Kubernetes will configure the external network to open on port 80 to listen to incoming requests. When used on Azure Kubernetes Services, AKS will create and map a public IP address (htttp://[your ip address]/vnc.html) for the service. Once connected, you can point your browser to the IP address of your cluster and have fun playing your retro games! +# DOSBOX IN A CONTAINER WITH VNC CLIENT -- NOW WITH SOUND! + +So much fun! After 3 years, I decided to bite the bullet and figure out how to add sound... and now it has it. I completely overhauled the Dockerfile to use Suerpvisor to start the processes because there were simply too many after adding support for sound. The rest of it is similar to the original, which is in an archive folder in this repo. In any case, I hope you enjoy it! + +1. Clone the repo: `git clone https://github.com/theonemule/dos-game.git` +1. Place a copy of your game in the folder. I am using the shareware version of Commander Keen here. +1. Replace the `COPY keen /dos/keen` with your game (ie. COPY wolf3d /dos/wolf3d). 1. You can also change the default password or override it with a -e parameter when you run the image. +1. Now, with Docker, build the image. I’m assuming you already have Docker installed and are somewhat familiar with it. CD to the directory in a console and run the command… + ```` + docker build -t mydosbox . + ```` +1. Run the image. + ```` + docker run -p 6080:80 mydosbox + ```` + +1. Open a browser and point it to http://localhost:6080/vnc.html +1. You should see a prompt for the password. Type it in, and you should be able to connect to your container with DosBox running. The game is started automatically. +1. Once your image is built, you can push it to your image repository with docker push, but you’ll need to tag it appropriately. + +# USE WITH KUBERNETES +Kubernetes is another part of the equation when it comes to container apps. Containers on Kubernetes are deployed into pods, which are then usually a part of a deployment with one or more pods associated. Deployments can also be used to create scalable sets of pods for high availability on a Kubernetes cluster. If you’re unfamiliar with Kubernetes, check out this webinar below, where I go in-depth. + +Deployments and services can be defined declaratively with a YAML file. Below is a Kubernetes YAML file that defines a deployment and a service for my retro gaming container. + +The deployment is simple – it points to a single container image called blaize/keen and then tells Kubernetes what ports to expose for the container. The service defines how the deployment will be exposed on a network. In this case, it’s using a TCP load balancer, exposing port 80 and mapping that to the port exposed by the deployment. The service uses selectors on the label app to match the service with the deployment. + +```` +apiVersion: v1 +kind: Service +metadata: + name: keen-service + labels: + app: keen-deployment +spec: + ports: + - port: 80 + targetPort: 6080 + selector: + app: keen-deployment + type: LoadBalancer +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: keen-deployment +spec: + selector: + matchLabels: + app: keen-deployment + replicas: 1 + template: + metadata: + labels: + app: keen-deployment + spec: + containers: + - name: master + image: blaize/keen + ports: + - containerPort: 80 +```` + +To connect, use this, first create a file called keen.yaml file, configure your instance kubectl to work with your instance of Kubernetes, then run deploy the sample. + +```` +kubectl create -f keen.yaml +```` + +When this is deployed to Kubernetes, Kubernetes will configure the external network to open on port 80 to listen to incoming requests. When used on Azure Kubernetes Services, AKS will create and map a public IP address (htttp://[your ip address]/vnc.html) for the service. Once connected, you can point your browser to the IP address of your cluster and have fun playing your retro games! diff --git a/archive/dockerfile b/archive/dockerfile index a8db814..ce33e4b 100644 --- a/archive/dockerfile +++ b/archive/dockerfile @@ -1,41 +1,41 @@ -FROM ubuntu:22.04 -ENV USER=root -ENV PASSWORD=password1 -ENV DEBIAN_FRONTEND=noninteractive -ENV DEBCONF_NONINTERACTIVE_SEEN=true -COPY keen /dos/keen -RUN apt-get update && \ - echo "tzdata tzdata/Areas select America" > ~/tx.txt && \ - echo "tzdata tzdata/Zones/America select New York" >> ~/tx.txt && \ - debconf-set-selections ~/tx.txt && \ - apt-get install -y curl tightvncserver ratpoison dosbox novnc websockify bzip2 gstreamer1.0-plugins-good gstreamer1.0-pulseaudio gstreamer1.0-tools libglu1-mesa libgtk2.0-0 libncursesw5 libopenal1 libsdl-image1.2 libsdl-ttf2.0-0 libsdl1.2debian libsndfile1 pulseaudio supervisor ucspi-tcp wget - -COPY default.pa client.conf /etc/pulse/ -COPY webaudio.js /usr/share/novnc/core/ - -RUN ln -s /usr/share/novnc/vnc_lite.html /usr/share/novnc/index.html \ - && sed -i 's/display:flex/display:none/' /usr/share/novnc/app/styles/lite.css \ - && sed -i "/import RFB/a \ - import WebAudio from './core/webaudio.js'" \ - /usr/share/novnc/vnc_lite.html \ - && sed -i "/function connected(e)/a \ - var wa = new WebAudio('ws://10.0.1.92:8081/websockify'); \ - document.getElementsByTagName('canvas')[0].addEventListener('keydown', e => { wa.start(); });" \ - /usr/share/novnc/vnc_lite.html - -RUN mkdir ~/.vnc/ && \ - mkdir ~/.dosbox && \ - echo $PASSWORD | vncpasswd -f > ~/.vnc/passwd && \ - chmod 0600 ~/.vnc/passwd && \ - echo "set border 0" > ~/.ratpoisonrc && \ - echo "exec dosbox -conf ~/.dosbox/dosbox.conf -fullscreen -c 'MOUNT C: /dos' -c 'C:' -c 'cd keen' -c 'keen1'">> ~/.ratpoisonrc && \ - export DOSCONF=$(dosbox -printconf) && \ - cp $DOSCONF ~/.dosbox/dosbox.conf && \ - sed -i 's/usescancodes=true/usescancodes=false/' ~/.dosbox/dosbox.conf && \ - openssl req -x509 -nodes -newkey rsa:2048 -keyout ~/novnc.pem -out ~/novnc.pem -days 3650 -subj "/C=US/ST=NY/L=NY/O=NY/OU=NY/CN=NY emailAddress=email@example.com" -EXPOSE 80 - -COPY supervisord.conf /etc/supervisor/supervisord.conf -ENTRYPOINT [ "supervisord", "-c", "/etc/supervisor/supervisord.conf" ] - -# CMD vncserver && websockify -D --web=/usr/share/novnc/ --cert=~/novnc.pem 80 localhost:5901 && tail -f /dev/null +FROM ubuntu:22.04 +ENV USER=root +ENV PASSWORD=password1 +ENV DEBIAN_FRONTEND=noninteractive +ENV DEBCONF_NONINTERACTIVE_SEEN=true +COPY keen /dos/keen +RUN apt-get update && \ + echo "tzdata tzdata/Areas select America" > ~/tx.txt && \ + echo "tzdata tzdata/Zones/America select New York" >> ~/tx.txt && \ + debconf-set-selections ~/tx.txt && \ + apt-get install -y curl tightvncserver ratpoison dosbox novnc websockify bzip2 gstreamer1.0-plugins-good gstreamer1.0-pulseaudio gstreamer1.0-tools libglu1-mesa libgtk2.0-0 libncursesw5 libopenal1 libsdl-image1.2 libsdl-ttf2.0-0 libsdl1.2debian libsndfile1 pulseaudio supervisor ucspi-tcp wget + +COPY default.pa client.conf /etc/pulse/ +COPY webaudio.js /usr/share/novnc/core/ + +RUN ln -s /usr/share/novnc/vnc_lite.html /usr/share/novnc/index.html \ + && sed -i 's/display:flex/display:none/' /usr/share/novnc/app/styles/lite.css \ + && sed -i "/import RFB/a \ + import WebAudio from './core/webaudio.js'" \ + /usr/share/novnc/vnc_lite.html \ + && sed -i "/function connected(e)/a \ + var wa = new WebAudio('ws://10.0.1.92:8081/websockify'); \ + document.getElementsByTagName('canvas')[0].addEventListener('keydown', e => { wa.start(); });" \ + /usr/share/novnc/vnc_lite.html + +RUN mkdir ~/.vnc/ && \ + mkdir ~/.dosbox && \ + echo $PASSWORD | vncpasswd -f > ~/.vnc/passwd && \ + chmod 0600 ~/.vnc/passwd && \ + echo "set border 0" > ~/.ratpoisonrc && \ + echo "exec dosbox -conf ~/.dosbox/dosbox.conf -fullscreen -c 'MOUNT C: /dos' -c 'C:' -c 'cd keen' -c 'keen1'">> ~/.ratpoisonrc && \ + export DOSCONF=$(dosbox -printconf) && \ + cp $DOSCONF ~/.dosbox/dosbox.conf && \ + sed -i 's/usescancodes=true/usescancodes=false/' ~/.dosbox/dosbox.conf && \ + openssl req -x509 -nodes -newkey rsa:2048 -keyout ~/novnc.pem -out ~/novnc.pem -days 3650 -subj "/C=US/ST=NY/L=NY/O=NY/OU=NY/CN=NY emailAddress=email@example.com" +EXPOSE 80 + +COPY supervisord.conf /etc/supervisor/supervisord.conf +ENTRYPOINT [ "supervisord", "-c", "/etc/supervisor/supervisord.conf" ] + +# CMD vncserver && websockify -D --web=/usr/share/novnc/ --cert=~/novnc.pem 80 localhost:5901 && tail -f /dev/null diff --git a/client.conf b/client.conf index 439169f..a0e5ee1 100644 --- a/client.conf +++ b/client.conf @@ -1 +1 @@ -default-server=unix:/tmp/pulseaudio.socket +default-server=unix:/tmp/pulseaudio.socket diff --git a/default.pa b/default.pa index 02942e5..9d08bc5 100644 --- a/default.pa +++ b/default.pa @@ -1,3 +1,3 @@ -#!/usr/bin/pulseaudio -nF -load-module module-native-protocol-unix socket=/tmp/pulseaudio.socket auth-anonymous=1 -load-module module-always-sink +#!/usr/bin/pulseaudio -nF +load-module module-native-protocol-unix socket=/tmp/pulseaudio.socket auth-anonymous=1 +load-module module-always-sink diff --git a/dockerfile b/dockerfile index 9a0f0d6..5034bb2 100644 --- a/dockerfile +++ b/dockerfile @@ -1,68 +1,56 @@ -FROM ubuntu:22.04 - -#User Settings for VNC -ENV USER=root -ENV PASSWORD=password1 - -#Variables for installation -ENV DEBIAN_FRONTEND=noninteractive -ENV DEBCONF_NONINTERACTIVE_SEEN=true -ENV XKB_DEFAULT_RULES=base - -#Install dependencies -RUN apt-get update && \ - echo "tzdata tzdata/Areas select America" > ~/tx.txt && \ - echo "tzdata tzdata/Zones/America select New York" >> ~/tx.txt && \ - debconf-set-selections ~/tx.txt && \ - apt-get install -y unzip gnupg apt-transport-https wget software-properties-common ratpoison novnc websockify libxv1 libglu1-mesa xauth x11-utils xorg tightvncserver libegl1-mesa xauth x11-xkb-utils software-properties-common bzip2 gstreamer1.0-plugins-good gstreamer1.0-pulseaudio gstreamer1.0-tools libglu1-mesa libgtk2.0-0 libncursesw5 libopenal1 libsdl-image1.2 libsdl-ttf2.0-0 libsdl1.2debian libsndfile1 nginx pulseaudio supervisor ucspi-tcp wget build-essential ccache dosbox - -#Copy the files for audio and NGINX -COPY default.pa client.conf /etc/pulse/ -COPY nginx.conf /etc/nginx/ -COPY webaudio.js /usr/share/novnc/core/ - -#Inject code for audio in the NoVNC client -RUN sed -i "/import RFB/a \ - import WebAudio from '/core/webaudio.js'" \ - /usr/share/novnc/app/ui.js \ - && sed -i "/UI.rfb.resizeSession/a \ - var loc = window.location, new_uri; \ - if (loc.protocol === 'https:') { \ - new_uri = 'wss:'; \ - } else { \ - new_uri = 'ws:'; \ - } \ - new_uri += '//' + loc.host; \ - new_uri += '/audio'; \ - var wa = new WebAudio(new_uri); \ - document.addEventListener('keydown', e => { wa.start(); });" \ - /usr/share/novnc/app/ui.js - -#Install VirtualGL and TurboVNC -RUN wget https://gigenet.dl.sourceforge.net/project/virtualgl/3.1/virtualgl_3.1_amd64.deb && \ - wget https://zenlayer.dl.sourceforge.net/project/turbovnc/3.0.3/turbovnc_3.0.3_amd64.deb && \ - dpkg -i virtualgl_*.deb && \ - dpkg -i turbovnc_*.deb - - -# Configure DOSBOX -RUN mkdir ~/.vnc/ && \ - mkdir ~/.dosbox && \ - echo $PASSWORD | vncpasswd -f > ~/.vnc/passwd && \ - chmod 0600 ~/.vnc/passwd && \ - echo "set border 0" > ~/.ratpoisonrc && \ - echo "exec dosbox -conf ~/.dosbox/dosbox.conf -fullscreen -c 'MOUNT C: /dos' -c 'C:' -c 'cd keen' -c 'keen1'">> ~/.ratpoisonrc && \ - export DOSCONF=$(dosbox -printconf) && \ - cp $DOSCONF ~/.dosbox/dosbox.conf && \ - sed -i 's/usescancodes=true/usescancodes=false/' ~/.dosbox/dosbox.conf && \ - openssl req -x509 -nodes -newkey rsa:2048 -keyout ~/novnc.pem -out ~/novnc.pem -days 3650 -subj "/C=US/ST=NY/L=NY/O=NY/OU=NY/CN=NY emailAddress=email@example.com" - - -COPY keen /dos/keen -COPY doom /dos/doom - -EXPOSE 80 - -#Copy in supervisor configuration for startup -COPY supervisord.conf /etc/supervisor/supervisord.conf -ENTRYPOINT [ "supervisord", "-c", "/etc/supervisor/supervisord.conf" ] +FROM ubuntu:22.04 + +#User Settings for VNC +ENV USER=root +ENV PASSWORD=password1 + +#Variables for installation +ENV DEBIAN_FRONTEND=noninteractive +ENV DEBCONF_NONINTERACTIVE_SEEN=true +ENV XKB_DEFAULT_RULES=base + +#Install dependencies +RUN apt-get update && \ + echo "tzdata tzdata/Areas select America" > ~/tx.txt && \ + echo "tzdata tzdata/Zones/America select New York" >> ~/tx.txt && \ + debconf-set-selections ~/tx.txt && \ + apt-get install -y unzip gnupg apt-transport-https wget software-properties-common novnc websockify libxv1 libglu1-mesa xauth x11-utils xorg tightvncserver libegl1-mesa xauth x11-xkb-utils software-properties-common bzip2 gstreamer1.0-plugins-good gstreamer1.0-pulseaudio gstreamer1.0-tools libglu1-mesa libgtk2.0-0 libncursesw5 libopenal1 libsdl-image1.2 libsdl-ttf2.0-0 libsdl1.2debian libsndfile1 nginx pulseaudio supervisor ucspi-tcp wget build-essential ccache dosbox + +RUN mkdir ~/.vnc && \ + mkdir ~/.dosbox + +#Copy the files for audio and NGINX +COPY default.pa client.conf /etc/pulse/ +COPY nginx.conf /etc/nginx/ +COPY webaudio.js /usr/share/novnc/core/ +COPY dosbox.conf /root/.dosbox/dosbox.conf +COPY xstartup /root/.vnc/xstartup + +#Inject code for audio in the NoVNC client +RUN sed -i "/import RFB/a \ + import WebAudio from '/core/webaudio.js'" \ + /usr/share/novnc/app/ui.js \ + && sed -i "/UI.rfb.resizeSession/a \ + var loc = window.location, new_uri; \ + if (loc.protocol === 'https:') { \ + new_uri = 'wss:'; \ + } else { \ + new_uri = 'ws:'; \ + } \ + new_uri += '//' + loc.host; \ + new_uri += '/audio'; \ + var wa = new WebAudio(new_uri); \ + document.addEventListener('keydown', e => { wa.start(); });" \ + /usr/share/novnc/app/ui.js + +RUN echo $PASSWORD | vncpasswd -f > ~/.vnc/passwd && \ + chmod 0600 ~/.vnc/passwd + +COPY keen /dos/keen +COPY doom /dos/doom + +EXPOSE 80 + +#Copy in supervisor configuration for startup +COPY supervisord.conf /etc/supervisor/supervisord.conf +ENTRYPOINT [ "supervisord", "-c", "/etc/supervisor/supervisord.conf" ] diff --git a/dosbox.conf b/dosbox.conf new file mode 100644 index 0000000..356c954 --- /dev/null +++ b/dosbox.conf @@ -0,0 +1,250 @@ +# This is the configuration file for DOSBox 0.74-3. (Please use the latest version of DOSBox) +# Lines starting with a # are comment lines and are ignored by DOSBox. +# They are used to (briefly) document the effect of each option. + +[sdl] +# fullscreen: Start dosbox directly in fullscreen. (Press ALT-Enter to go back) +# fulldouble: Use double buffering in fullscreen. It can reduce screen flickering, but it can also result in a slow DOSBox. +# fullresolution: What resolution to use for fullscreen: original, desktop or fixed size (e.g. 1024x768). +# Using your monitor's native resolution (desktop) with aspect=true might give the best results. +# If you end up with small window on a large screen, try an output different from surface. +# On Windows 10 with display scaling (Scale and layout) set to a value above 100%, it is recommended +# to use a lower full/windowresolution, in order to avoid window size problems. +# windowresolution: Scale the window to this size IF the output device supports hardware scaling. +# (output=surface does not!) +# output: What video system to use for output. +# Possible values: surface, overlay, opengl, openglnb. +# autolock: Mouse will automatically lock, if you click on the screen. (Press CTRL-F10 to unlock) +# sensitivity: Mouse sensitivity. +# waitonerror: Wait before closing the console if dosbox has an error. +# priority: Priority levels for dosbox. Second entry behind the comma is for when dosbox is not focused/minimized. +# pause is only valid for the second entry. +# Possible values: lowest, lower, normal, higher, highest, pause. +# mapperfile: File used to load/save the key/event mappings from. Resetmapper only works with the default value. +# usescancodes: Avoid usage of symkeys, might not work on all operating systems. + +fullscreen=true +fulldouble=false +fullresolution=desktop +windowresolution=desktop +output=overlay +autolock=true +sensitivity=100 +waitonerror=true +priority=higher,normal +mapperfile=mapper-0.74-3.map +usescancodes=false + +[dosbox] +# language: Select another language file. +# machine: The type of machine DOSBox tries to emulate. +# Possible values: hercules, cga, tandy, pcjr, ega, vgaonly, svga_s3, svga_et3000, svga_et4000, svga_paradise, vesa_nolfb, vesa_oldvbe. +# captures: Directory where things like wave, midi, screenshot get captured. +# memsize: Amount of memory DOSBox has in megabytes. +# This value is best left at its default to avoid problems with some games, +# though few games might require a higher value. +# There is generally no speed advantage when raising this value. + +language= +machine=svga_s3 +captures=capture +memsize=16 + +[render] +# frameskip: How many frames DOSBox skips before drawing one. +# aspect: Do aspect correction, if your output method doesn't support scaling this can slow things down! +# scaler: Scaler used to enlarge/enhance low resolution modes. If 'forced' is appended, +# then the scaler will be used even if the result might not be desired. +# To fit a scaler in the resolution used at full screen may require a border or side bars, +# to fill the screen entirely, depending on your hardware, a different scaler/fullresolution might work. +# Possible values: none, normal2x, normal3x, advmame2x, advmame3x, advinterp2x, advinterp3x, hq2x, hq3x, 2xsai, super2xsai, supereagle, tv2x, tv3x, rgb2x, rgb3x, scan2x, scan3x. + +frameskip=0 +aspect=true +scaler=normal2x forced + +[cpu] +# core: CPU Core used in emulation. auto will switch to dynamic if available and +# appropriate. +# Possible values: auto, dynamic, normal, simple. +# cputype: CPU Type used in emulation. auto is the fastest choice. +# Possible values: auto, 386, 386_slow, 486_slow, pentium_slow, 386_prefetch. +# cycles: Amount of instructions DOSBox tries to emulate each millisecond. +# Setting this value too high results in sound dropouts and lags. +# Cycles can be set in 3 ways: +# 'auto' tries to guess what a game needs. +# It usually works, but can fail for certain games. +# 'fixed #number' will set a fixed amount of cycles. This is what you usually +# need if 'auto' fails. (Example: fixed 4000). +# 'max' will allocate as much cycles as your computer is able to +# handle. +# Possible values: auto, fixed, max. +# cycleup: Amount of cycles to decrease/increase with keycombos.(CTRL-F11/CTRL-F12) +# cycledown: Setting it lower than 100 will be a percentage. + +core=auto +cputype=auto +cycles=auto +cycleup=10 +cycledown=20 + +[mixer] +# nosound: Enable silent mode, sound is still emulated though. +# rate: Mixer sample rate, setting any device's rate higher than this will probably lower their sound quality. +# Possible values: 44100, 48000, 32000, 22050, 16000, 11025, 8000, 49716. +# blocksize: Mixer block size, larger blocks might help sound stuttering but sound will also be more lagged. +# Possible values: 1024, 2048, 4096, 8192, 512, 256. +# prebuffer: How many milliseconds of data to keep on top of the blocksize. + +nosound=false +rate=44100 +blocksize=1024 +prebuffer=25 + +[midi] +# mpu401: Type of MPU-401 to emulate. +# Possible values: intelligent, uart, none. +# mididevice: Device that will receive the MIDI data from MPU-401. +# Possible values: default, win32, alsa, oss, coreaudio, coremidi, none. +# midiconfig: Special configuration options for the device driver. This is usually the id of the device you want to use +# (find the id with mixer/listmidi). +# Or in the case of coreaudio, you can specify a soundfont here. +# See the README/Manual for more details. + +mpu401=intelligent +mididevice=default +midiconfig= + +[sblaster] +# sbtype: Type of Soundblaster to emulate. gb is Gameblaster. +# Possible values: sb1, sb2, sbpro1, sbpro2, sb16, gb, none. +# sbbase: The IO address of the soundblaster. +# Possible values: 220, 240, 260, 280, 2a0, 2c0, 2e0, 300. +# irq: The IRQ number of the soundblaster. +# Possible values: 7, 5, 3, 9, 10, 11, 12. +# dma: The DMA number of the soundblaster. +# Possible values: 1, 5, 0, 3, 6, 7. +# hdma: The High DMA number of the soundblaster. +# Possible values: 1, 5, 0, 3, 6, 7. +# sbmixer: Allow the soundblaster mixer to modify the DOSBox mixer. +# oplmode: Type of OPL emulation. On 'auto' the mode is determined by sblaster type. All OPL modes are Adlib-compatible, except for 'cms'. +# Possible values: auto, cms, opl2, dualopl2, opl3, none. +# oplemu: Provider for the OPL emulation. compat might provide better quality (see oplrate as well). +# Possible values: default, compat, fast. +# oplrate: Sample rate of OPL music emulation. Use 49716 for highest quality (set the mixer rate accordingly). +# Possible values: 44100, 49716, 48000, 32000, 22050, 16000, 11025, 8000. + +sbtype=sb16 +sbbase=220 +irq=7 +dma=1 +hdma=5 +sbmixer=true +oplmode=auto +oplemu=default +oplrate=44100 + +[gus] +# gus: Enable the Gravis Ultrasound emulation. +# gusrate: Sample rate of Ultrasound emulation. +# Possible values: 44100, 48000, 32000, 22050, 16000, 11025, 8000, 49716. +# gusbase: The IO base address of the Gravis Ultrasound. +# Possible values: 240, 220, 260, 280, 2a0, 2c0, 2e0, 300. +# gusirq: The IRQ number of the Gravis Ultrasound. +# Possible values: 5, 3, 7, 9, 10, 11, 12. +# gusdma: The DMA channel of the Gravis Ultrasound. +# Possible values: 3, 0, 1, 5, 6, 7. +# ultradir: Path to Ultrasound directory. In this directory +# there should be a MIDI directory that contains +# the patch files for GUS playback. Patch sets used +# with Timidity should work fine. + +gus=false +gusrate=44100 +gusbase=240 +gusirq=5 +gusdma=3 +ultradir=C:\ULTRASND + +[speaker] +# pcspeaker: Enable PC-Speaker emulation. +# pcrate: Sample rate of the PC-Speaker sound generation. +# Possible values: 44100, 48000, 32000, 22050, 16000, 11025, 8000, 49716. +# tandy: Enable Tandy Sound System emulation. For 'auto', emulation is present only if machine is set to 'tandy'. +# Possible values: auto, on, off. +# tandyrate: Sample rate of the Tandy 3-Voice generation. +# Possible values: 44100, 48000, 32000, 22050, 16000, 11025, 8000, 49716. +# disney: Enable Disney Sound Source emulation. (Covox Voice Master and Speech Thing compatible). + +pcspeaker=true +pcrate=44100 +tandy=auto +tandyrate=44100 +disney=true + +[joystick] +# joysticktype: Type of joystick to emulate: auto (default), none, +# 2axis (supports two joysticks), +# 4axis (supports one joystick, first joystick used), +# 4axis_2 (supports one joystick, second joystick used), +# fcs (Thrustmaster), ch (CH Flightstick). +# none disables joystick emulation. +# auto chooses emulation depending on real joystick(s). +# (Remember to reset dosbox's mapperfile if you saved it earlier) +# Possible values: auto, 2axis, 4axis, 4axis_2, fcs, ch, none. +# timed: enable timed intervals for axis. Experiment with this option, if your joystick drifts (away). +# autofire: continuously fires as long as you keep the button pressed. +# swap34: swap the 3rd and the 4th axis. Can be useful for certain joysticks. +# buttonwrap: enable button wrapping at the number of emulated buttons. + +joysticktype=auto +timed=true +autofire=false +swap34=false +buttonwrap=false + +[serial] +# serial1: set type of device connected to com port. +# Can be disabled, dummy, modem, nullmodem, directserial. +# Additional parameters must be in the same line in the form of +# parameter:value. Parameter for all types is irq (optional). +# for directserial: realport (required), rxdelay (optional). +# (realport:COM1 realport:ttyS0). +# for modem: listenport (optional). +# for nullmodem: server, rxdelay, txdelay, telnet, usedtr, +# transparent, port, inhsocket (all optional). +# Example: serial1=modem listenport:5000 +# Possible values: dummy, disabled, modem, nullmodem, directserial. +# serial2: see serial1 +# Possible values: dummy, disabled, modem, nullmodem, directserial. +# serial3: see serial1 +# Possible values: dummy, disabled, modem, nullmodem, directserial. +# serial4: see serial1 +# Possible values: dummy, disabled, modem, nullmodem, directserial. + +serial1=dummy +serial2=dummy +serial3=disabled +serial4=disabled + +[dos] +# xms: Enable XMS support. +# ems: Enable EMS support. +# umb: Enable UMB support. +# keyboardlayout: Language code of the keyboard layout (or none). + +xms=true +ems=true +umb=true +keyboardlayout=auto + +[ipx] +# ipx: Enable ipx over UDP/IP emulation. + +ipx=true + +[autoexec] +# Lines in this section will be run at startup. +# You can put your MOUNT lines here. + + diff --git a/gh-actions-with-aks-aci.yaml b/gh-actions-with-aks-aci.yaml index 37cd849..53dc6f3 100644 --- a/gh-actions-with-aks-aci.yaml +++ b/gh-actions-with-aks-aci.yaml @@ -1,76 +1,76 @@ -apiVersion: v1 -kind: Service -metadata: - name: dindsvc - labels: - app: dinddindsvc -spec: - ports: - - port: 2375 - targetPort: 2375 - name: dockerd - selector: - app: dind - type: ClusterIP ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: dind -spec: - replicas: 1 - selector: - matchLabels: - app: dind - template: - metadata: - labels: - app: dind - spec: - containers: - - name: dind - image: "docker:dind" - imagePullPolicy: Always - command: ["dockerd", "--host", "tcp://0.0.0.0:2375"] - securityContext: - privileged: true - volumes: - - name: launcher-storage - emptyDir: {} ---- -apiVersion: actions.summerwind.dev/v1alpha1 -kind: RunnerDeployment -metadata: - name: dos-box-runner -spec: - replicas: 1 - template: - spec: - image: summerwind/actions-runner-dind - env: - - name: DOCKER_HOST - value: "tcp://dindsvc:2375" - dockerdWithinRunnerContainer: true - repository: theonemule/dos-game - tolerations: - - key: virtual-kubelet.io/provider - operator: "Exists" - effect: NoSchedule ---- -apiVersion: actions.summerwind.dev/v1alpha1 -kind: HorizontalRunnerAutoscaler -metadata: - name: dos-box-runner-autoscaler -spec: - scaleDownDelaySecondsAfterScaleOut: 300 - scaleTargetRef: - kind: RunnerDeployment - name: dos-box-runner - minReplicas: 0 - maxReplicas: 5 - metrics: - - type: TotalNumberOfQueuedAndInProgressWorkflowRuns - scaleUpThreshold: '1' - scaleDownThreshold: '0' - scaleUpFactor: '2' - scaleDownFactor: '0.5' +apiVersion: v1 +kind: Service +metadata: + name: dindsvc + labels: + app: dinddindsvc +spec: + ports: + - port: 2375 + targetPort: 2375 + name: dockerd + selector: + app: dind + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: dind +spec: + replicas: 1 + selector: + matchLabels: + app: dind + template: + metadata: + labels: + app: dind + spec: + containers: + - name: dind + image: "docker:dind" + imagePullPolicy: Always + command: ["dockerd", "--host", "tcp://0.0.0.0:2375"] + securityContext: + privileged: true + volumes: + - name: launcher-storage + emptyDir: {} +--- +apiVersion: actions.summerwind.dev/v1alpha1 +kind: RunnerDeployment +metadata: + name: dos-box-runner +spec: + replicas: 1 + template: + spec: + image: summerwind/actions-runner-dind + env: + - name: DOCKER_HOST + value: "tcp://dindsvc:2375" + dockerdWithinRunnerContainer: true + repository: theonemule/dos-game + tolerations: + - key: virtual-kubelet.io/provider + operator: "Exists" + effect: NoSchedule +--- +apiVersion: actions.summerwind.dev/v1alpha1 +kind: HorizontalRunnerAutoscaler +metadata: + name: dos-box-runner-autoscaler +spec: + scaleDownDelaySecondsAfterScaleOut: 300 + scaleTargetRef: + kind: RunnerDeployment + name: dos-box-runner + minReplicas: 0 + maxReplicas: 5 + metrics: + - type: TotalNumberOfQueuedAndInProgressWorkflowRuns + scaleUpThreshold: '1' + scaleDownThreshold: '0' + scaleUpFactor: '2' + scaleDownFactor: '0.5' diff --git a/keen.yml b/keen.yml index 45fcc78..60d429d 100644 --- a/keen.yml +++ b/keen.yml @@ -1,34 +1,34 @@ -apiVersion: v1 -kind: Service -metadata: - name: keen - labels: - app: keen -spec: - ports: - - port: 80 - targetPort: 80 - name: http - selector: - app: keen - type: LoadBalancer ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: keen -spec: - selector: - matchLabels: - app: keen - replicas: 1 - template: - metadata: - labels: - app: keen - spec: - containers: - - name: keen-kontainer - image: "blaizek8s.azurecr.io/k8s" - ports: - - containerPort: 80 +apiVersion: v1 +kind: Service +metadata: + name: keen + labels: + app: keen +spec: + ports: + - port: 80 + targetPort: 80 + name: http + selector: + app: keen + type: LoadBalancer +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: keen +spec: + selector: + matchLabels: + app: keen + replicas: 1 + template: + metadata: + labels: + app: keen + spec: + containers: + - name: keen-kontainer + image: "blaizek8s.azurecr.io/k8s" + ports: + - containerPort: 80 diff --git a/keen/FILE_ID.DIZ b/keen/FILE_ID.DIZ index 787e30d..a90eebf 100644 --- a/keen/FILE_ID.DIZ +++ b/keen/FILE_ID.DIZ @@ -1,8 +1,8 @@ - ³ÝÛÞÛÞÛÝÛÛÛ COMMANDER KEEN ÛÛÛÞÛÝÛÝÛÞ³ -Five months straight as the number one -selling shareware program--unprecedented!. -This vivid EGA game has four-way scrolling -levels and great arcade action. No other -IBM game as ever duplicated Nintendo action -better. You're lost on Mars, battling the -Vorticons. Dozens of great features. + ³ÝÛÞÛÞÛÝÛÛÛ COMMANDER KEEN ÛÛÛÞÛÝÛÝÛÞ³ +Five months straight as the number one +selling shareware program--unprecedented!. +This vivid EGA game has four-way scrolling +levels and great arcade action. No other +IBM game as ever duplicated Nintendo action +better. You're lost on Mars, battling the +Vorticons. Dozens of great features. diff --git a/multiplayer.yml b/multiplayer.yml new file mode 100644 index 0000000..f5a969d --- /dev/null +++ b/multiplayer.yml @@ -0,0 +1,97 @@ +apiVersion: v1 +kind: Service +metadata: + name: keenservice1 + labels: + app: keenservice1 +spec: + ports: + - port: 80 + targetPort: 80 + name: http + selector: + app: keen1 + type: LoadBalancer +--- +apiVersion: v1 +kind: Service +metadata: + name: keenipxservice1 +spec: + selector: + app: keen1 + ports: + - protocol: UDP + port: 19900 + targetPort: 19900 + type: ClusterIP + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: keen1 +spec: + selector: + matchLabels: + app: keen1 + replicas: 1 + template: + metadata: + labels: + app: keen1 + spec: + containers: + - name: keen-kontainer + image: "blaize/keen" + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: keenservice2 + labels: + app: keenservice2 +spec: + ports: + - port: 80 + targetPort: 80 + name: http + selector: + app: keen2 + type: LoadBalancer +--- +apiVersion: v1 +kind: Service +metadata: + name: keenipxservice2 +spec: + selector: + app: keen2 + ports: + - protocol: UDP + port: 19900 + targetPort: 19900 + type: ClusterIP + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: keen2 +spec: + selector: + matchLabels: + app: keen2 + replicas: 1 + template: + metadata: + labels: + app: keen2 + spec: + containers: + - name: keen-kontainer + image: "blaize/keen" + ports: + - containerPort: 80 \ No newline at end of file diff --git a/nginx.conf b/nginx.conf index 316a575..c85eb7a 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,40 +1,40 @@ -user root; -worker_processes 1; - - -events { - worker_connections 4096; -} - -http { - include mime.types; - default_type application/octet-stream; - - # Sending fille Optimization - sendfile on; - tcp_nopush on; - tcp_nodelay on; - - # Keepalive Connection - keepalive_timeout 65; - - server { - listen 80; - - location /audio { - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_pass http://127.0.0.1:8081; - } - - location / { - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_pass http://127.0.0.1:8080; - } - } -} +user root; +worker_processes 1; + + +events { + worker_connections 4096; +} + +http { + include mime.types; + default_type application/octet-stream; + + # Sending fille Optimization + sendfile on; + tcp_nopush on; + tcp_nodelay on; + + # Keepalive Connection + keepalive_timeout 65; + + server { + listen 80; + + location /audio { + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_pass http://127.0.0.1:8081; + } + + location / { + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_pass http://127.0.0.1:8080; + } + } +} diff --git a/supervisord.conf b/supervisord.conf index 0733375..1d9a999 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -1,50 +1,50 @@ -[supervisord] -nodaemon=true -pidfile=/root/supervisord.pid -logfile=/root/supervisord.log - -[program:beforevnc1] -command=/usr/bin/rm -rf /tmp/.X11-unix -autostart=true -autorestart=false -redirect_stderr=true - -[program:beforevnc2] -command=/usr/bin/rm -rf /tmp/.X1-lock -autostart=true -autorestart=false -redirect_stderr=true - -[program:vncserver] -command=vncserver -stdout_logfile=/root/x11vnc.log -redirect_stderr=true - -[program:websockify_vnc] -command=websockify --web /usr/share/novnc 8080 127.0.0.1:5901 -stdout_logfile=/root/websockify-vnc.log -redirect_stderr=true - -[program:pulseaudio] -command=/usr/bin/pulseaudio --disallow-module-loading -vvvv --disallow-exit --exit-idle-time=-1 -stdout_logfile=/root/pulseaudio.log -redirect_stderr=true - -[program:audiostream] -command=tcpserver 127.0.0.1 5902 gst-launch-1.0 -q pulsesrc server=/tmp/pulseaudio.socket ! audio/x-raw, channels=2, rate=24000 ! opusenc ! webmmux ! fdsink fd=1 -stdout_logfile=/root/audiostream.log -redirect_stderr=true - -[program:websockify_audio] -command=websockify 8081 127.0.0.1:5902 -stdout_logfile=/root/websockify-audio.log -redirect_stderr=true - -[program:nginx] -command=/usr/sbin/nginx -g "daemon off;" -autostart=true -autorestart=true -startretries=5 -numprocs=1 -startsecs=0 -stdout_logfile=/root/nginx.log +[supervisord] +nodaemon=true +pidfile=/root/supervisord.pid +logfile=/root/supervisord.log + +[program:beforevnc1] +command=/usr/bin/rm -rf /tmp/.X11-unix +autostart=true +autorestart=false +redirect_stderr=true + +[program:beforevnc2] +command=/usr/bin/rm -rf /tmp/.X1-lock +autostart=true +autorestart=false +redirect_stderr=true + +[program:vncserver] +command=vncserver +stdout_logfile=/root/x11vnc.log +redirect_stderr=true + +[program:websockify_vnc] +command=websockify --web /usr/share/novnc 8080 127.0.0.1:5901 +stdout_logfile=/root/websockify-vnc.log +redirect_stderr=true + +[program:pulseaudio] +command=/usr/bin/pulseaudio --disallow-module-loading -vvvv --disallow-exit --exit-idle-time=-1 +stdout_logfile=/root/pulseaudio.log +redirect_stderr=true + +[program:audiostream] +command=tcpserver 127.0.0.1 5902 gst-launch-1.0 -q pulsesrc server=/tmp/pulseaudio.socket ! audio/x-raw, channels=2, rate=24000 ! opusenc ! webmmux ! fdsink fd=1 +stdout_logfile=/root/audiostream.log +redirect_stderr=true + +[program:websockify_audio] +command=websockify 8081 127.0.0.1:5902 +stdout_logfile=/root/websockify-audio.log +redirect_stderr=true + +[program:nginx] +command=/usr/sbin/nginx -g "daemon off;" +autostart=true +autorestart=true +startretries=5 +numprocs=1 +startsecs=0 +stdout_logfile=/root/nginx.log diff --git a/webaudio.js b/webaudio.js index fdd538b..3b66f81 100644 --- a/webaudio.js +++ b/webaudio.js @@ -1,121 +1,121 @@ -export default class WebAudio { - constructor(url) { - this.url = url - - this.connected = false; - - //constants for audio behavoir - this.maximumAudioLag =0.25; //amount of seconds we can potentially be behind the server audio stream - this.syncLagInterval = 500; //check every x milliseconds if we are behind the server audio stream - this.updateBufferEvery = 20; //add recieved data to the player buffer every x milliseconds - this.reduceBufferInterval = 20; //trim the output audio stream buffer every x milliseconds so we don't overflow - this.maximumSecondsOfBuffering = .2; //maximum amount of data to store in the play buffer - this.connectionCheckInterval = 100; //check the connection every x milliseconds - - //register all our background timers. these need to be created only once - and will run independent of the object's streams/properties - setInterval(() => this.updateQueue(), this.updateBufferEvery); - setInterval(() => this.syncInterval(), this.syncLagInterval); - setInterval(() => this.reduceBuffer(), this.reduceBufferInterval); - setInterval(() => this.tryLastPacket(), this.connectionCheckInterval); - - } - - //registers all the event handlers for when this stream is closed - or when data arrives. - registerHandlers() { - this.mediaSource.addEventListener('sourceended', e => this.socketDisconnected(e)) - this.mediaSource.addEventListener('sourceclose', e => this.socketDisconnected(e)) - this.mediaSource.addEventListener('error', e => this.socketDisconnected(e)) - this.buffer.addEventListener('error', e => this.socketDisconnected(e)) - this.buffer.addEventListener('abort', e => this.socketDisconnected(e)) - } - - //starts the web audio stream. only call this method on button click. - start() { - if (!!this.connected) return; - if (!!this.audio) this.audio.remove(); - this.queue = null; - - this.mediaSource = new MediaSource() - this.mediaSource.addEventListener('sourceopen', e => this.onSourceOpen()) - //first we need a media source - and an audio object that contains it. - this.audio = document.createElement('audio'); - this.audio.src = window.URL.createObjectURL(this.mediaSource); - - //start our stream - we can only do this on user input - this.audio.play(); - } - - wsConnect() { - if (!!this.socket) this.socket.close(); - - this.socket = new WebSocket(this.url, ['binary', 'base64']) - this.socket.binaryType = 'arraybuffer' - this.socket.addEventListener('message', e => this.websocketDataArrived(e), false); - } - - //this is called when the media source contains data - onSourceOpen(e) { - this.buffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"') - this.registerHandlers(); - this.wsConnect(); - } - - //whenever data arrives in our websocket this is called. - websocketDataArrived(e) { - this.lastPacket = Date.now(); - this.connected = true; - this.queue = this.queue == null ? e.data : this.concat(this.queue, e.data); - } - - //whenever a disconnect happens this is called. - socketDisconnected(e) { - console.log(e); - this.connected = false; - } - - tryLastPacket() { - if (this.lastPacket == null) return; - if ((Date.now() - this.lastPacket) > 1000) { - this.socketDisconnected('timeout'); - } - } - - //this updates the buffer with the data from our queue - updateQueue() { - if (!(!!this.queue && !!this.buffer && !this.buffer.updating)) { - return; - } - - this.buffer.appendBuffer(this.queue); - this.queue = null; - } - - //reduces the stream buffer to the minimal size that we need for streaming - reduceBuffer() { - if (!(this.buffer && !this.buffer.updating && !!this.audio && !!this.audio.currentTime && this.audio.currentTime > 1)) { - return; - } - - this.buffer.remove(0, this.audio.currentTime - 1); - } - - //synchronizes the current time of the stream with the server - syncInterval() { - if (!(this.audio && this.audio.currentTime && this.audio.currentTime > 1 && this.buffer && this.buffer.buffered && this.buffer.buffered.length > 1)) { - return; - } - - var currentTime = this.audio.currentTime; - var targetTime = this.buffer.buffered.end(this.buffer.buffered.length - 1); - - if (targetTime > (currentTime + this.maximumAudioLag)) this.audio.fastSeek(targetTime); - } - - //joins two data arrays - helper function - concat(buffer1, buffer2) { - var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength); - tmp.set(new Uint8Array(buffer1), 0); - tmp.set(new Uint8Array(buffer2), buffer1.byteLength); - return tmp.buffer; - }; -} +export default class WebAudio { + constructor(url) { + this.url = url + + this.connected = false; + + //constants for audio behavoir + this.maximumAudioLag =0.25; //amount of seconds we can potentially be behind the server audio stream + this.syncLagInterval = 500; //check every x milliseconds if we are behind the server audio stream + this.updateBufferEvery = 20; //add recieved data to the player buffer every x milliseconds + this.reduceBufferInterval = 20; //trim the output audio stream buffer every x milliseconds so we don't overflow + this.maximumSecondsOfBuffering = .2; //maximum amount of data to store in the play buffer + this.connectionCheckInterval = 100; //check the connection every x milliseconds + + //register all our background timers. these need to be created only once - and will run independent of the object's streams/properties + setInterval(() => this.updateQueue(), this.updateBufferEvery); + setInterval(() => this.syncInterval(), this.syncLagInterval); + setInterval(() => this.reduceBuffer(), this.reduceBufferInterval); + setInterval(() => this.tryLastPacket(), this.connectionCheckInterval); + + } + + //registers all the event handlers for when this stream is closed - or when data arrives. + registerHandlers() { + this.mediaSource.addEventListener('sourceended', e => this.socketDisconnected(e)) + this.mediaSource.addEventListener('sourceclose', e => this.socketDisconnected(e)) + this.mediaSource.addEventListener('error', e => this.socketDisconnected(e)) + this.buffer.addEventListener('error', e => this.socketDisconnected(e)) + this.buffer.addEventListener('abort', e => this.socketDisconnected(e)) + } + + //starts the web audio stream. only call this method on button click. + start() { + if (!!this.connected) return; + if (!!this.audio) this.audio.remove(); + this.queue = null; + + this.mediaSource = new MediaSource() + this.mediaSource.addEventListener('sourceopen', e => this.onSourceOpen()) + //first we need a media source - and an audio object that contains it. + this.audio = document.createElement('audio'); + this.audio.src = window.URL.createObjectURL(this.mediaSource); + + //start our stream - we can only do this on user input + this.audio.play(); + } + + wsConnect() { + if (!!this.socket) this.socket.close(); + + this.socket = new WebSocket(this.url, ['binary', 'base64']) + this.socket.binaryType = 'arraybuffer' + this.socket.addEventListener('message', e => this.websocketDataArrived(e), false); + } + + //this is called when the media source contains data + onSourceOpen(e) { + this.buffer = this.mediaSource.addSourceBuffer('audio/webm; codecs="opus"') + this.registerHandlers(); + this.wsConnect(); + } + + //whenever data arrives in our websocket this is called. + websocketDataArrived(e) { + this.lastPacket = Date.now(); + this.connected = true; + this.queue = this.queue == null ? e.data : this.concat(this.queue, e.data); + } + + //whenever a disconnect happens this is called. + socketDisconnected(e) { + console.log(e); + this.connected = false; + } + + tryLastPacket() { + if (this.lastPacket == null) return; + if ((Date.now() - this.lastPacket) > 1000) { + this.socketDisconnected('timeout'); + } + } + + //this updates the buffer with the data from our queue + updateQueue() { + if (!(!!this.queue && !!this.buffer && !this.buffer.updating)) { + return; + } + + this.buffer.appendBuffer(this.queue); + this.queue = null; + } + + //reduces the stream buffer to the minimal size that we need for streaming + reduceBuffer() { + if (!(this.buffer && !this.buffer.updating && !!this.audio && !!this.audio.currentTime && this.audio.currentTime > 1)) { + return; + } + + this.buffer.remove(0, this.audio.currentTime - 1); + } + + //synchronizes the current time of the stream with the server + syncInterval() { + if (!(this.audio && this.audio.currentTime && this.audio.currentTime > 1 && this.buffer && this.buffer.buffered && this.buffer.buffered.length > 1)) { + return; + } + + var currentTime = this.audio.currentTime; + var targetTime = this.buffer.buffered.end(this.buffer.buffered.length - 1); + + if (targetTime > (currentTime + this.maximumAudioLag)) this.audio.fastSeek(targetTime); + } + + //joins two data arrays - helper function + concat(buffer1, buffer2) { + var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength); + tmp.set(new Uint8Array(buffer1), 0); + tmp.set(new Uint8Array(buffer2), buffer1.byteLength); + return tmp.buffer; + }; +} diff --git a/xstartup b/xstartup new file mode 100644 index 0000000..e2a0dfc --- /dev/null +++ b/xstartup @@ -0,0 +1,3 @@ +#!/bin/sh +# Command to start DOSBox +dosbox -conf ~/.dosbox/dosbox.conf -c "MOUNT C: /dos" -c 'C:' &