Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update manifest, .env changes and fix client port #11

Merged
merged 2 commits into from Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions video-stream/client/client.lua
@@ -1,16 +1,12 @@
local endpoint = SplitHostPort(GetCurrentServerEndpoint())

-- use client connecting endpoint
local streamURL = string.format("http://%s:3000/dui/index.html", endpoint)
local streamOfflineURL = string.format("http://%s:3000/dui/off.html", endpoint)

RegisterCommand('video-stream', function (source, arg, rawInput)
SetEntityCoords(PlayerPedId(), 320.217, 263.81, 82.974)
SetEntityHeading(PlayerPedId(), 180.0)
end)

-------------------

local streamOfflineURL <const> = string.format("nui://%s/public/dui/off.html", GetCurrentResourceName())

local scale = 1.5
local screenWidth = math.floor(1280 / scale)
local screenHeight = math.floor(720 / scale)
Expand Down Expand Up @@ -58,6 +54,12 @@ CreateThread(function ()
-- Give time for resource to start
Wait(3500)

-- Gather the stream url
local endpoint = SplitHostPort(GetCurrentServerEndpoint())

local port = GetConvarInt("video_stream_port", 3000)
local streamURL = string.format("http://%s:%d/dui/index.html", endpoint, port)

-- Check stream status
TriggerServerEvent('video-stream:status')
LoadInterior(cinemaIpl)
Expand Down
6 changes: 5 additions & 1 deletion video-stream/__resource.lua → video-stream/fxmanifest.lua
@@ -1,6 +1,8 @@
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
fx_version "cerulean"
game "gta5"

dependency 'yarn'
lua54 "yes"

client_scripts {
'client/utils.lua',
Expand All @@ -10,3 +12,5 @@ client_scripts {
server_scripts {
'server.js'
}

file "public/dui/off.html"
19 changes: 12 additions & 7 deletions video-stream/server.js
@@ -1,22 +1,25 @@
const path = require('path')
const fs = require('fs')
const dotenv = require('dotenv')

const resourcePath = global.GetResourcePath?
global.GetResourcePath(global.GetCurrentResourceName()) : global.__dirname

require('dotenv').config({ path: path.join(resourcePath, './.env') })
const config = dotenv.parse(fs.readFileSync(path.join(resourcePath, '.env')))

const http = require('http')
const WebSocket = require('ws')
const finalhandler = require('finalhandler')
const serveStatic = require('serve-static')
const { spawn } = require('child_process')
const ffmpegPath = process.env.FFMPEG_PATH || require('ffmpeg-static')
const ffmpegPath = config.FFMPEG_PATH || require('ffmpeg-static')
const NodeMediaServer = require('node-media-server')

const RTMP_ENABLED = process.env.RTMP_ENABLED || 0
const RTMP_PORT = process.env.RTMP_PORT || 1935
const RTMP_SECRET = process.env.RTMP_SECRET || 'secret'
const PORT = process.env.PORT || 3000
const STREAM_PATH = process.env.STREAM_PATH ||
const RTMP_ENABLED = config.RTMP_ENABLED || 0
const RTMP_PORT = config.RTMP_PORT || 1935
const RTMP_SECRET = config.RTMP_SECRET || 'secret'
const PORT = config.PORT || 3000
const STREAM_PATH = config.STREAM_PATH ||
`rtmp://localhost:${RTMP_PORT}/live/STREAM_NAME`

let streamProc
Expand Down Expand Up @@ -195,4 +198,6 @@ if (global.RegisterCommand) {
onPostPublish(streamProc)
}
}, true)

SetConvarReplicated("video_stream_port", config.PORT)
}