Skip to content

Instantly share code, notes, and snippets.

@ksarpotdar
ksarpotdar / Broadcast.js
Created January 14, 2025 02:55 — forked from toshvelaga/Broadcast.js
Using the Youtube Live Streaming API to go live
import React, { useState, useEffect, useRef } from 'react'
import Navbar from '../../components/Navbar/Navbar'
import BroadcastButton from '../../components/Buttons/BroadcastButton'
import Timer from '../../components/Timer/Timer'
import formatTime from '../../utils/formatTime'
import getCookie from '../../utils/getCookie'
import API from '../../api/api'
import './Broadcast.css'
const CAPTURE_OPTIONS = {
/**
Main thread (e.g. index.js)
**/
const audioCtx = new AudioContext()
// Loads module script via AudioWorklet.
audioCtx.audioWorklet.addModule('reverb-processor.js')
.then(() => getLiveAudio(audioCtx))
.then((liveIn) => {
// After the resolution of module loading, an AudioWorkletNode can be constructed.
@ksarpotdar
ksarpotdar / ffmpeg.js
Created April 10, 2023 15:42 — forked from mkhahani/ffmpeg.js
Injecting audio/video stream into mediasoup using ffmpeg/gstreamer
// Class to handle child process used for running FFmpeg
const childProcess = require('child_process');
const Streamer = require('./streamer');
module.exports = class FFmpeg extends Streamer {
constructor(options) {
super(options);
this.time = options.time || '00:00:00.0'; // https://ffmpeg.org/ffmpeg-utils.html#time-duration-syntax
@ksarpotdar
ksarpotdar / group-objects-by-property.md
Created July 8, 2022 15:12 — forked from mikaello/group-objects-by-property.md
Group Array of JavaScript Objects by Key or Property Value

Group array of JavaScript objects by keys

This fork of JamieMason's implementation changes the key parameter to be an array of keys instead of just a single key. This makes it possible to group by multiple properties instead of just one.

Implementation

const groupBy = keys => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = keys.map(key => obj[key]).join('-');
@ksarpotdar
ksarpotdar / group-objects-by-property.md
Created July 8, 2022 15:12 — forked from JamieMason/group-objects-by-property.md
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
@ksarpotdar
ksarpotdar / elementToObject
Created July 1, 2022 15:41 — forked from alain75007/elementToObject
Convert element to object then to json
function elementToObject(element, o) {
var el = $(element);
var o = {
tagName: el.tagName
};
var i = 0;
for (i ; i < el.attributes.length; i++) {
o[el.attributes[i].name] = el.attributes[i].value;
}
@ksarpotdar
ksarpotdar / nearby-coordinates.sql
Created May 4, 2022 04:22 — forked from statickidz/nearby-coordinates.sql
Ordering with SQL by nearest latitude & longitude coordinates (MySQL & SQLite)
---
METHOD 1
This should roughly sort the items on distance in MySQL, and should work in SQLite.
If you need to sort them preciser, you could try using the Pythagorean theorem (a^2 + b^2 = c^2) to get the exact distance.
---
SELECT *
FROM table
ORDER BY ((lat-$user_lat)*(lat-$user_lat)) + ((lng - $user_lng)*(lng - $user_lng)) ASC
@ksarpotdar
ksarpotdar / howto_nat_traversal.md
Created April 12, 2022 14:03 — forked from mildred/howto_nat_traversal.md
How To TCP NAT Traversal using Node.js and a STUN Server

How To TCP NAT Traversal using Node.js and a STUN Server

With the scarecity of IPv4 addresses, and IPv6 still not available at large, NAT traversal is becoming a necessity. Especially with the generalisation of Carrier-grade NATs that you can find on mobile connections. Even with IPv6 you may suffer NAT66. Imagine your mobile device that gets only a single Ipv6 address, and you want to share it on your computer.

The solution might be in a decentralized protocol for address attribution such

@ksarpotdar
ksarpotdar / distributed-mediasoup.js
Created January 24, 2022 18:03 — forked from gurupras/distributed-mediasoup.js
mediasoup horizontal scaling
onServerStartup () {
const { serverId, ip } = getServerInfo() // serverId does not change across restarts
this.serverId = serverId
// We don't have any routers or producers (yet). Clear any value that exists in the DB related to our serverId
clearSharedDB(serverId, 'routers')
clearSharedDB(serverId, 'producers')
// Update the DB with our serverId and ip so that others will know how to reach us
registerServerInDB(serverId, ip)
<template>
<div class="ui cards" style="margin: 10px">
<div class="ui icon input" style="width: 100%">
<input type="text" placeholder="Search..." v-model="searchQuery" />
<i class="search icon"></i>
</div>
<div
class="card ui fluid"
v-for="product in searchedProducts"
:key="product.id"