inveta / peer-stream

Lightweight WebRTC SDK for UnrealEngine's PixelStreaming
https://inveta.cn
406 stars 107 forks source link
pixel realtime stream unreal video webrtc

UE5 Pixel Streaming SDK 中文 English

Compared to EpicGame's heavily-designed SDK for Pixel Streaming, peer-stream.js is a lightweight WebRTC library with 0 dependency, containing a frontend component (using WebComponents API), along with a signaling server (using NodeJS).

Demo

# install WebSocket
npm install ws@8.5.0

# start Signaling Server
node signal.js

# start packaged UE5
start path/to/UE5.exe -PixelStreamingURL="ws://localhost:88"

# visit webpage
start http://localhost:88/signal.html

signal.json

options type default usage
PORT number 88 WebSocket/HTTP port for player & UE5
UE5 string[] [] run command when player connected (UE5 auto start)
one2one bool false one-to-one mapping for player & UE5
auth string '' HTTP Basic Auth username:password
boot bool false node signal.js on system boot
exeUeCoolTime number 60 Time interval between starting the same UE instance again next time
preload int 1 Number of pre started UE instances

Load Balance

signal.js accept multi UE5 & player connections, where each UE5 maps to multi-players with load-balancing. Turn one2one on to keep one-to-one mapping. Provide UE5 to start UE5 automatically. All configs in signal.json.

Unreal Engine

enable the plugin:

Plugins > Built-In > Graphics > Pixel Streaming > Enabled
Editor Preferences > Level Editor > Play > Additional Launch Parameters
start path/to/UE5.exe -{key}={value}

common startup options:

 -PixelStreamingURL="ws://localhost:88"
 -RenderOffScreen
 -Unattended
 -GraphicsAdapter=0
 -ForceRes
 -ResX=1280
 -ResY=720
 -PixelStreamingWebRTCFps=30
 -Windowed
 -AudioMixer
 -AllowPixelStreamingCommands
 -PixelStreamingEncoderRateControl=VBR

peer-stream.js

HTML:

<script src="https://github.com/inveta/peer-stream/raw/main//localhost:88/peer-stream.js"></script>
<video is="peer-stream" id="ws://127.0.0.1:88/"></video>

or JavaScript:

<script type="module">
import "//localhost:88/peer-stream.js";
const ps = document.createElement("video", { is: "peer-stream" });
ps.id = "ws://127.0.0.1:88/";
document.body.append(ps);
</script>

Messages

sending messages:

// object will be JSON.stringify()
ps.emitMessage(msg: string | object);

receiving messages:

ps.addEventListener("message", e => {
    // JSON.parse(e.detail)
});

Requirement

© MIT License

Copyright (c) 2020-2024 Inveta

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.