Code Monkey home page Code Monkey logo

jimthatcher / sport-streamer Goto Github PK

View Code? Open in Web Editor NEW
15.0 3.0 2.0 15.68 MB

Browser overlays providing scoreboard, player highlights, and ads for live sports streaming with OBS Studio and Elgato Stream Deck. Includes parser for serial connection to Daktronics All-Sport 5000 controllers.

License: MIT License

C# 29.20% JavaScript 3.14% CSS 0.60% HTML 20.96% TypeScript 46.10%
daktronics elgato obs sports stream-deck streamdeck streaming

sport-streamer's Introduction

Live Sport Streaming Manager

This is a very early release of a system for providing HTML/JavaScript-based graphic overlays for streaming live sporting events. First, a quick disclaimer: I'm a hobbyist with a passion for streaming our high school football games on YouTube. Although I've been a professional developer, that was MANY years ago, working in C, C++, and Java. This is all built in C#, HTML, JavaScript, and TypeScript using frameworks I'm not really familiar with. As you look through the code, if you have any current software development experience, you're going find code that is inefficient, hacky, and mayby just plain wrong. When you do, please submit an issue with recommendations to improve the code. I'm kind of proud of what this system can do, but I'm confident the code itself can be improved ... a lot. If you find this helpful, and you have software experience that could help improve it, I would really appreciate your help to really make this a great system.

The system is composed of five main components:

  1. A web server to access game-related data that provides REST APIs to access and manipulate the data.
  2. A SQLite database, managed through the web server.
  3. A React-based front-end web app for managing the database.
  4. A set of data-driven web pages that provide graphic overlays for: (a). Scoreboard (with team-specific graphics from the database, and live data feed from the Daktronics scoreboard controller), (b). Player hilights - show the player picture, name, jersey number, and position after a key play, (c). Sponsor ads - Show your sponsors some love by putting their ad on-screen during down-time in the game.
  5. A plugin for Elgoto Stream Deck devices to simplify game-time live changes to the graphic overlays.

The web server is built on ASP.NET Core, using Entity Framework to access the database. It provides a set of REST APIs for reading and updating the database and managing an in-memory database that holds game-time data for the clock and scoreboard (that data doesn't need to be saved after the game ends). The front-end web app is built from the base web app in rjwats' esp8266-react project (https://github.com/rjwats/esp8266-react). The graphic overlay pages are basic HTML/JavaScript using server-sent-events to keep the display up-to-date with changes on the web server. The Stream Deck plugin is based on the Stream Deck Plugin Template project (https://github.com/elgatosf/streamdeck-plugintemplate) provided by Elgato. There is a very good chance that I've grabbed ideas and code for other parts of the system from some projects I haven't mentioned. Thank you to each of the developers of those projects.

In developing this project I have used the GitHub Copilot AI-based "pair programmer" (https://github.com/features/copilot/). It's very impressive in what it can do as it recognizes patterns in the code I'm writing, and suggests what I'm likely planning to code next. Especially when I've been working in a new framework, like React, it has really helped me write the changes I wanted to make much more quickly than if I had to keep searching the web for how to do something I hadn't done before in React. It's not flawless - it'll happily help you reproduce bad coding patterns if that's what you've been doing recently. But this project is ready for others to start working with now because I've had a lot of assistance from Copilot.

How-to/Getting Started

To get started with the streaming manager you can either download the compiled binaries, or start with the code and build it yourself.

Build it yourself:

This project is built with .NET Core and ASP.NET Core. If you want to build it yourself, download or clone the repo, install the .NET Core SDK version 6 (available from https://dotnet.microsoft.com/en-us/download), and from the root folder of the source run "dotnet publish -c Release". After the build completes, you can switch to the ".\bin\Release\net6.0\publish" folder and run "sport-streamer.exe".

Use the pre-built binary:

If you just want to download the precompiled system, start by installing the ASP.NET Core Hosting Bundle from https://dotnet.microsoft.com/en-us/download/dotnet/6.0/runtime. That bundle includes both the .NET Core Runtime and the ASP.NET Core Runtime. Both are needed to run the web server.

Once you have the .NET Core runtime installed, download the "webAppBinaries.zip" from the Binaries folder. After the download completes, you will need to unblock the file in Windows before you will be able to use the included binaries. From File Explorer, right-click on the zip file and select "Properties". At the bottom of the General properties page you will see a checkbox option to Unblock the content downloaded from the Internet. This is part of Windows' protections against malware, so if you aren't comfortable trusting the prebuilt binaries, go back up to the Build it yourself section. Once you have unblocked the zip file, right-click on the zip file again and select the "Extract all ..." option, choose the folder you want to extract the app into, and click the Extract button. The extracted files will be inside a "publish" folder in your target directory. Open a command prompt to that "pubilsh" folder and run "sport-streamer.exe".

Accessing the app:

Whichever approach you use, after you run the app it will start up the web server listening on http://localhost:5000 and https://localhost:5001. The default configuration does not include listening on external IP addresses. You can then open a browser to http://localhost:5000/index.html. When the web app starts, it will create an empty database as "games.db".

image

The first time you sign in to the web app the app will accept the username and password you submit as the administrative user credentials, and stores those in the database. You'll need to remember that password for future sign-in. NOTE: The usernames and passwords are stored in clear text in the games.db database, and can be viewed by anyone with access to that file using simple SQLite tools. You should manage access to the app's root directory accordingly. Once in the app, you will be able to begin adding schools, games, players, and sponsors to your database by selecting the relevant item from the left menu.

image

The information for each school (name, mascot, color, logo, and win/loss record) is used for the scoreboard overlay. (There are some problems currently in the code for adding the logo files. After a logo is uploaded it will not appear in the list of schools until you select the school from the list and delete the "C:\fakepath" prefix from the file name. We'll work on fixing that.) When you upload a logo file from the Add school page the file is saved to the "publish\wwwroot\Images" folder. Once you have at least two schools added to your database you can create a game between those schools. Adding at least one game is a minimum requirement for the scoreboard overlay to function.

image

If you have physical access to the in-stadium scoreboard controller (and if it's a Daktronics controller) the web app can parse the real-time data (RTD) output from the 25-pin serial port on the controller. Connect the serial output to an RS232-to-USB converter into the laptop running the web app and your streaming software and the web app should auto-connect to the COM port and begin parsing the RTD stream to feed your scoreboard overlay. The overlay currently pulls clock, score, period, down, distance, possession, time out, time outs left, and flag from the Daktronics RTD. So far every stadium I've streamed from uses a Daktronics controller. If others have access to other controllers being used in your stadiums, and those controllers provide an RTD output through RS232 or USB, and the manufacturer provides documentation of the RTD protocol, I'll work on adding support for other controllers.

The information in the Players page (jersey number, name, position, year, and school/team) is used for the player hilight overlay. We don't currently use the height and weight, but those are included to support using the database for other roster-related uses. The primary use of the "school/team" field is currently for sorting players in the menu when adding player hilight actions in the Stream Deck plugin.

image

For the sponsor advertisement overlay, we really only need the image to place in the ad space. The image should be roughly 2:1 aspect ratio.

Contoso

That image will be transposed into the background to create the overlay for that sponsor.

image

Adding overlays to your streaming software:

The overlays are each provided as HTML/JavaScript web pages that can be added as Browser sources into OBS Studio and similar streaming software. The pages to add are:

  • Scoreboard: http://localhost:5000/overlay/ScoreBug.html
  • Player Hilight: http://localhost:5000/overlay/PlayerHL.html
  • Ads: http://localhost:5000/overlay/SponsorAd.html The pages each respond to server-sent envents to show or hide the overlay. Hiding the overlay makes the entire page transparent. This allows the sources to always be set as visible in OBS Studio, with their actual visibility being controlled through REST API requests that are sent to the server in response to button actions on your Stream Deck. The web pages are all in the "publish\wwwroot\overlays" directory. If they don't meet your needs as they are, feel free to edit the JavaScript to your preferences. Currently the scoreboard is optimized for American Football. If you customize one for a different sport, please submit an issue and a PR to add that into the project. I'd love to get developers with HTML/CSS/JavaScript experience to help take these from functional to beautiful.

Adding the Stream Deck plugin:

You can download the source for the Stream Deck plugin from the https://github.com/JimThatcher/SDPlugins-Sportscaster repository. Or you can download the installable plugin, com.evanscreekdev.sportscaster.streamDeckPlugin, from the Binaries folder. If you download the installable plugin you will need to unblock it from the file properties in File Explorer before you double-click on it to install it to your Stream Deck plugins folder. Oh, you'll need to have the latest Stream Deck software installed before you try to install the plugin. Once installed, you will see a "Sports Stream Manager" section added to your Stream Deck actions. See the README in the plugin repository for more information on using the plugin.

sport-streamer's People

Contributors

jimthatcher avatar

Stargazers

Igor Arkhipov avatar  avatar Brandon Cruz avatar Chase Castora avatar  avatar Paul Ortman avatar  avatar Paolo avatar FzForecast avatar Lawrence Thatcher avatar Liam Brenner avatar  avatar  avatar  avatar

Watchers

 avatar Lawrence Thatcher avatar FzForecast avatar

sport-streamer's Issues

Implement bulk add of players from CSV

Put code behind handleBulkAdd() method in PlayerListForm.tsx to open file select dialog to select a CSV file, then parse the CSV file and for each row in the file create a PlayerData object and call DbApi.createPlayerData() with each PlayerData.

Add date/time picker in ClientApp/src/project/GameSetupForm.tsx and GameAddForm.tsx

The game configuration forms need Date and Time pickers for the scheduled game time. This support needs to be added in:

  • ClientApp/src/project/GameSetupForm.tsx
  • ClientApp/src/project/GameAddForm.tsx
    Note that the getDateString function in each of those files, and several string<->date conversions in
    Controllers/GameDataController.cs will be needed to support adding time to the scheduled date of a game. The database stores game date/time as a numeric value to support sorting.

Update README to include adding NuGet to sources in .NET SDK

Update the Build it yourself Section in README.md

As mentioned in Issue #8, after a fresh install of the .NET SDK 6.0 the SDK's list of sources may by default be empty, resulting in it being unable to build or publish. This can be fixed by running the command:

dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org

The README should be updated to include this to help future users with the same problem.

  • This information could either be added to README.md directly, or a Wiki page could be created to include more detailed troubleshooting information, and then a link added to README.md.

Unable to Build Project (using `.NET SDK 6.0`)

Unable to Build Project

Overview:

When following steps from the README, upon running the publish command several errors occur stating that multiple .NET external dependencies were unable to be resolved.

So far this has only been verified with the .NET 6.0 SDK, as this is the version specified in the README.

Description:

I downloaded and installed the .NET 6.0 SDK using the link provided in the Build it yourself section of README.md using the provided installation wizard. After verifying the installation was successful, I ran the following command:

dotnet publish -c Release

This resulted in the following errors:

MSBuild version 17.3.2+561848881 for .NET
  Determining projects to restore...
C:\---\sport-streamer\sport-streamer.csproj : error NU1100: Unable to resolve 'Lib.AspNetCore.ServerSentEvents (>= 8.1.0)' for 'net6.0'.
C:\---\sport-streamer\sport-streamer.csproj : error NU1100: Unable to resolve 'Microsoft.AspNetCore.SpaProxy (>= 6.0.1)' for 'net6.0'.
C:\---\sport-streamer\sport-streamer.csproj : error NU1100: Unable to resolve 'Microsoft.EntityFrameworkCore.InMemory (>= 6.0.8)' for 'net6.0'.
C:\---\sport-streamer\sport-streamer.csproj : error NU1100: Unable to resolve 'Microsoft.EntityFrameworkCore.Sqlite (>= 6.0.8)' for 'net6.0'.
C:\---\sport-streamer\sport-streamer.csproj : error NU1100: Unable to resolve 'Microsoft.OpenApi (>= 1.3.2)' for 'net6.0'.
C:\---\sport-streamer\sport-streamer.csproj : error NU1100: Unable to resolve 'System.IdentityModel.Tokens.Jwt (>= 6.22.0)' for 'net6.0'.
C:\---\sport-streamer\sport-streamer.csproj : error NU1100: Unable to resolve 'System.IO.Ports (>= 6.0.0)' for 'net6.0'.
  Failed to restore C:\---\sport-streamer\sport-streamer.csproj (in 426 ms).

Setup:

  • Run on a Windows 11 laptop.
  • Project cloned from GitHub using (master) branch.
  • Working environment was within Visual Studio Code.
  • Command has been run using powershell, cmd, and bash - all with the same result.
  • Using .NET SDK v6.0

Remediation Attempts:

  • Close Visual Studio Code and reopen, allowing project/cache to reload
  • Run command outside of Visual Studio Code
  • Try using different versions of the .NET SDK
    • v7.0
    • v5.0
  • Download and attempt with .NET SDK VSCode integration

    Note: the VSCode integration is the .NET SDK coding pack. Duplicate check-list item has been removed.

uploading/changing image files

School Logo Uploads

There are a few issues found with uploading image files. This issue documents several known issues.
(more may be added when found)

Problems

  • When created, file paths are by default preceded by "C:/fakepath/"
  • Images fail to update upon form submission (requires a refresh)
  • Upload Image is a separate step/feature from Select Image
  • Once a school is created, a new logo image cannot be uploaded for it within the Edit School form

    The component in mention is: SchoolSetupForm.tsx.

Progress

--SECTION PENDING--

sport-streamer.exe needs to be run in administrator mode

SSL certificate errors with localhost

When attempting to run sport-streamer.exe to launch the web servers, this might be required to be done in Administrative Mode in order to load /index.html or reach any of the REST endpoints.

NOTE: This error has not been reproduceable after running in Administrator mode the first time.

Problem Description

After building the project and running sport-streamer.exe as described in the README, a cmd window will open and run normally.
This produces the expected output:

info: DakAccess.ConsoleData[0]
      ConsoleData ConnectConsole called.
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\...\sport-streamer\bin\Release\net6.0\publish

However, when attempting to access the app the entry site (http://localhost:5000/index.html) it may instead return a 404 code, listing the following error: ERR_SSL_PROTOCOL_ERROR.

Why this is a problem

No clues are given in the application log, no HTTP response data is received, at it generally appears like any other 404 error. The ERR_SSL_PROTOCOL_ERROR was only found upon clicking for more info.

Due to the inability to reproduce the error, running it in Administrator Mode once may be a suitable fix, but whether this may cause further issues is unknown. Either way, there is no documentation in the README or Wiki to guide users who may encounter this issue, making it a potential barrier to entry.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.