Skip to content

Instantly share code, notes, and snippets.

View toshvelaga's full-sized avatar
🔥
Koding

Tosh Velaga toshvelaga

🔥
Koding
View GitHub Profile
@toshvelaga
toshvelaga / nginx.conf
Created February 11, 2022 02:48
socket io nginx configuration
# Requests for socket.io are passed on to Node on port 3001
location ~* \.io {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy false;
proxy_pass http://localhost:3001;
proxy_redirect off;
@toshvelaga
toshvelaga / socket.js
Created February 11, 2022 02:15
Socket.io implementation in useEffect hook
useEffect(() => {
socket.current =
process.env.NODE_ENV === 'production'
? io(productionWsUrl + streamUrlParams, { transports: ['websocket'] })
: io(developmentWsUrl + streamUrlParams, { transports: ['websocket'] })
socket.current.on('connect', () => {
// either with send()
console.log('WebSocket Open')
})
@toshvelaga
toshvelaga / puppeteerStream.js
Created January 17, 2022 03:22
puppeteerStream.js
const { launch, getStream } = require('puppeteer-stream')
const fs = require('fs')
// node arguments are present from the third position going forward.
const args = process.argv.slice(2)
const file = fs.createWriteStream(`./reports/videos/${args[0]}.mp4`)
async function puppeteerStream() {
const browser = await launch()
@toshvelaga
toshvelaga / puppeteerRecord.js
Created January 17, 2022 03:08
puppeteerRecord.js
const puppeteer = require('puppeteer')
const { PuppeteerScreenRecorder } = require('puppeteer-screen-recorder')
// node arguments are present from the third position going forward.
const args = process.argv.slice(2)
;(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
@toshvelaga
toshvelaga / puppeteer.js
Created January 17, 2022 02:14
puppeteer.js
const puppeteer = require('puppeteer')
// node arguments are present from the third position going forward.
const args = process.argv.slice(2)
;(async () => {
const browser = await puppeteer.launch({ headless: true })
const page = await browser.newPage()
// create a room called room
@toshvelaga
toshvelaga / twilio.js
Created January 4, 2022 07:28
twilio STUN AND TURN SERVER CREDENTIALS
// twilio STUN AND TURN SERVER CREDENTIALS
app.post('/api/twilio', async (req, res) => {
const baseUrl = `https://api.twilio.com/2010-04-01/Accounts/${accountSid}/Tokens.json`
const token = await axios
.post(
baseUrl,
{},
{
auth: {
@toshvelaga
toshvelaga / ffmpegTee.js
Last active June 19, 2025 09:50
ffmpeg to stream live video using tee muxer
const ffmpegTee = (youtube, twitch, facebook) => {
return [
'-i',
'-',
// select first stream intended for output
'-map',
'0',
// video codec config: low latency, adaptive bitrate
'-c:v',
'libx264',
@toshvelaga
toshvelaga / ffmpeg.js
Last active June 19, 2025 09:49
stream to twitch and youtube RTMP destinations using FFmpeg
const ffmpeg = child_process.spawn('ffmpeg', [
// the input
'-i',
'-',
// video codec config: low latency, adaptive bitrate,
// list of presets: https://trac.ffmpeg.org/wiki/Encode/H.264
// tune zerolatency is good for fast encoding and low-latency streaming
// g:v 60 ==> https://www.reddit.com/r/ffmpeg/comments/redaa2/while_livestreaming_to_youtube_using_ffmpeg_i_get/
'-c:v',
@toshvelaga
toshvelaga / streamSpeechToText.js
Last active September 13, 2022 00:21
Uses google speech to text to turn audio into text in realtime
const express = require('express') // call express
const app = express() // define our app using express
const cors = require('cors')
const WebSocket = require('ws')
const EventEmitter = require('events').EventEmitter
require('dotenv').config()
//Configure Transcription Request for Google Speech to Text
const request = {
config: {
@toshvelaga
toshvelaga / switchStreamEx.js
Created November 8, 2021 10:23
switchStreamEx.js
import React, { useState, useEffect, useRef } from "react";
export default function App() {
const [isActive, setIsActive] = useState(false);
const [mediaStream, setMediaStream] = useState(null);
const [userFacing, setuserFacing] = useState(false);
const [videoUrl, setvideoUrl] = useState("");
const [chunks, setchunks] = useState([]);
const videoRef = useRef();