Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gabrielmaialva33/discord-video-stream

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gabrielmaialva33/discord-video-stream - npm Package Compare versions

Comparing version 0.9.4 to 0.9.5

2

package.json
{
"name": "@gabrielmaialva33/discord-video-stream",
"version": "0.9.4",
"version": "0.9.5",
"description": "Experiment for making video streaming work for discord self bots",

@@ -5,0 +5,0 @@ "keywords": [

@@ -91,3 +91,3 @@ import WebSocket from 'ws'

status: VoiceConnectionStatus
server: string | null = null // websocket url
server: string | null = null
token: string | null = null

@@ -140,3 +140,5 @@ session_id: string | null = null

stop(): void {
this.interval && clearInterval(this.interval)
if (this.interval) {
clearInterval(this.interval)
}
this.status.started = false

@@ -149,3 +151,2 @@ this.ws?.close()

this.session_id = session_id
this.status.hasSession = true

@@ -158,3 +159,2 @@ this.start()

this.server = server
this.status.hasToken = true

@@ -172,31 +172,64 @@ this.start()

this.status.started = true
this.initializeWebSocket()
}
}
this.ws = new WebSocket('wss://' + this.server + '/?v=7', {
followRedirects: true,
})
this.ws.on('open', () => {
if (this.status.resuming) {
this.status.resuming = false
this.resume()
} else {
this.identify()
}
})
this.ws.on('error', (err) => {
console.error(err)
})
this.ws.on('close', (code) => {
const wasStarted = this.status.started
initializeWebSocket(): void {
this.ws = new WebSocket(`wss://${this.server}/?v=7`, { followRedirects: true })
this.ws.on('open', this.handleOpen.bind(this))
this.ws.on('error', this.handleError.bind(this))
this.ws.on('close', this.handleClose.bind(this))
this.ws.on('message', this.handleMessage.bind(this))
}
this.status.started = false
this.udp.ready = false
handleOpen(): void {
if (this.status.resuming) {
this.status.resuming = false
this.resume()
} else {
this.identify()
}
}
const canResume = code === 4_015 || code < 4_000
handleError(err: Error): void {
console.error(err)
}
if (canResume && wasStarted) {
this.status.resuming = true
this.start()
handleClose(code: number): void {
const wasStarted = this.status.started
this.status.started = false
this.udp.ready = false
const canResume = code === 4015 || code < 4000
if (canResume && wasStarted) {
this.status.resuming = true
this.start()
}
}
handleMessage(data: any): void {
const { op, d } = JSON.parse(data)
switch (op) {
case VoiceOpCodes.READY:
this.handleReady(d)
this.sendVoice()
this.setVideoStatus(false)
break
case VoiceOpCodes.HELLO:
this.setupHeartbeat(d.heartbeat_interval)
break
case VoiceOpCodes.SELECT_PROTOCOL_ACK:
this.handleSession(d)
break
case VoiceOpCodes.HEARTBEAT_ACK:
case VoiceOpCodes.SPEAKING:
break
case VoiceOpCodes.RESUMED:
this.status.started = true
this.udp.ready = true
break
default:
if (op >= 4000) {
console.error(`Error ${this.constructor.name} connection`, d)
}
})
this.setupEvents()
break
}

@@ -210,5 +243,4 @@ }

this.modes = d.modes
this.videoSsrc = this.ssrc + 1 // todo: set it from packet streams object
this.videoSsrc = this.ssrc + 1
this.rtxSsrc = this.ssrc + 2
this.udp.audioPacketizer.ssrc = this.ssrc

@@ -220,3 +252,2 @@ this.udp.videoPacketizer.ssrc = this.videoSsrc

this.secretkey = new Uint8Array(d.secret_key)
this.ready(this.udp)

@@ -226,31 +257,2 @@ this.udp.ready = true

setupEvents(): void {
this.ws?.on('message', (data: any) => {
const { op, d } = JSON.parse(data)
if (op === VoiceOpCodes.READY) {
// ready
this.handleReady(d)
this.sendVoice()
this.setVideoStatus(false)
} else if (op >= 4000) {
console.error(`Error ${this.constructor.name} connection`, d)
} else if (op === VoiceOpCodes.HELLO) {
this.setupHeartbeat(d.heartbeat_interval)
} else if (op === VoiceOpCodes.SELECT_PROTOCOL_ACK) {
// session description
this.handleSession(d)
} else if (op === VoiceOpCodes.SPEAKING) {
// ignore speaking updates
} else if (op === VoiceOpCodes.HEARTBEAT_ACK) {
// ignore heartbeat acknowledgements
} else if (op === VoiceOpCodes.RESUMED) {
this.status.started = true
this.udp.ready = true
} else {
//console.log("unhandled voice event", {op, d});
}
})
}
setupHeartbeat(interval: number): void {

@@ -266,13 +268,5 @@ if (this.interval) {

sendOpcode(code: number, data: any): void {
this.ws?.send(
JSON.stringify({
op: code,
d: data,
})
)
this.ws?.send(JSON.stringify({ op: code, d: data }))
}
/*
** identifies with media server with credentials
*/
identify(): void {

@@ -297,7 +291,2 @@ this.sendOpcode(VoiceOpCodes.IDENTIFY, {

/*
** Sets protocols and ip data used for video and audio.
** Uses vp8 for video
** Uses opus for audio
*/
setProtocols(ip: string, port: number): void {

@@ -374,8 +363,4 @@ this.sendOpcode(VoiceOpCodes.SELECT_PROTOCOL, {

sendVoice(): Promise<void> {
return new Promise<void>((resolve, _reject) => {
this.udp.createUdp().then(() => {
resolve()
})
})
return this.udp.createUdp().then(() => undefined)
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc