refactor: vendor content as regular files (remove git submodules) so CI builds don't need GitHub auth
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// Join a voice channel and do nothing
|
||||
|
||||
/*
|
||||
Install:
|
||||
- An Opus library: @discordjs/opus or opusscript
|
||||
- An encryption packages:
|
||||
+ sodium (best performance)
|
||||
+ libsodium-wrappers
|
||||
+ @stablelib/xchacha20poly1305
|
||||
- ffmpeg (install and add to your system environment)
|
||||
*/
|
||||
|
||||
const { Client } = require('../../src/index');
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async () => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
const channel = client.channels.cache.get('voice_channel');
|
||||
const connection = await client.voice.joinChannel(channel, {
|
||||
selfMute: true,
|
||||
selfDeaf: true,
|
||||
selfVideo: false,
|
||||
});
|
||||
// Leave voice
|
||||
setTimeout(() => {
|
||||
connection.disconnect();
|
||||
}, 5_000);
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,58 @@
|
||||
// Join a channel and play music, like a Discord bot.
|
||||
|
||||
/*
|
||||
Install:
|
||||
- An Opus library: @discordjs/opus or opusscript
|
||||
- An encryption packages:
|
||||
+ sodium (best performance)
|
||||
+ libsodium-wrappers
|
||||
+ @stablelib/xchacha20poly1305
|
||||
- ffmpeg (install and add to your system environment)
|
||||
*/
|
||||
|
||||
|
||||
const { Client } = require('../../src/index');
|
||||
const ytdl = require('@distube/ytdl-core'); // better than ytdl-core
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async client => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
const channel = client.channels.cache.get('voice_id');
|
||||
const connection = await client.voice.joinChannel(channel, {
|
||||
selfMute: true,
|
||||
selfDeaf: true,
|
||||
selfVideo: false,
|
||||
});
|
||||
const dispatcher = connection.playAudio(
|
||||
ytdl('https://www.youtube.com/watch?v=3KadWjpqDXs', {
|
||||
quality: 'highestaudio',
|
||||
}),
|
||||
);
|
||||
dispatcher.on('start', () => {
|
||||
console.log('audio is now playing!');
|
||||
// pause
|
||||
console.log('paused');
|
||||
dispatcher.pause();
|
||||
// resume
|
||||
setTimeout(() => {
|
||||
console.log('resumed');
|
||||
dispatcher.resume();
|
||||
}, 5_000);
|
||||
|
||||
// Set volume
|
||||
dispatcher.setVolume(0.5);
|
||||
console.log('50% volume');
|
||||
});
|
||||
|
||||
dispatcher.on('finish', () => {
|
||||
console.log('audio has finished playing!');
|
||||
});
|
||||
dispatcher.on('error', console.error);
|
||||
// Leave voice
|
||||
setTimeout(() => {
|
||||
console.log('disconnected');
|
||||
connection.disconnect();
|
||||
}, 30_000);
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
Credit: https://github.com/dank074/Discord-video-stream
|
||||
The use of video streaming in this library is an incomplete implementation with many bugs, primarily aimed at lazy users.
|
||||
The video streaming features in this library are sourced from https://github.com/dank074/Discord-video-stream.
|
||||
|
||||
Please use the @dank074/discord-video-stream library to access all advanced and professional features,
|
||||
along with comprehensive support. I will not actively fix bugs related to streaming and encourage everyone to
|
||||
use https://github.com/dank074/Discord-video-stream for stable and smooth streaming.
|
||||
|
||||
To reiterate: This is an incomplete implementation of the library https://github.com/dank074/Discord-video-stream.
|
||||
|
||||
Thanks to dank074 and longnguyen2004 for implementing new codecs (H264, H265).
|
||||
Thanks to mrjvs for discovering how Discord transmits data and the VP8 codec.
|
||||
|
||||
Please use the @dank074/discord-video-stream library for the best support.
|
||||
*/
|
||||
|
||||
/*
|
||||
Install:
|
||||
- An Opus library: @discordjs/opus or opusscript
|
||||
- An encryption packages:
|
||||
+ sodium (best performance)
|
||||
+ libsodium-wrappers
|
||||
+ @stablelib/xchacha20poly1305
|
||||
- ffmpeg (install and add to your system environment)
|
||||
*/
|
||||
|
||||
const { Client } = require('../../src/index');
|
||||
const client = new Client();
|
||||
|
||||
client.on('ready', async client => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
const channel = client.channels.cache.get('voice_channel');
|
||||
const connection = await client.voice.joinChannel(channel, {
|
||||
selfMute: true,
|
||||
selfDeaf: true,
|
||||
selfVideo: false, // Turn on the camera? If you turn on the camera, use the connection similar to
|
||||
// PlayAudio.js, and it will stream video through the camera. This is an implementation of screen sharing.
|
||||
videoCodec: 'H264',
|
||||
});
|
||||
const stream = await connection.createStreamConnection();
|
||||
// You can also access it by using `connection.streamConnection` (only after it has been initialized by the `createStreamConnection` function).
|
||||
// Split it into two separate streams (audio / video)
|
||||
// Or with a combined stream that will be automatically processed by FFmpeg.
|
||||
const input = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4';
|
||||
// Play
|
||||
const dispatcher = stream.playVideo(input, {
|
||||
fps: 60,
|
||||
bitrate: 4000,
|
||||
});
|
||||
const dispatcher2 = stream.playAudio(input);
|
||||
dispatcher.on('start', () => {
|
||||
console.log('video is now playing!');
|
||||
});
|
||||
|
||||
dispatcher.on('finish', () => {
|
||||
console.log('video has finished playing!');
|
||||
});
|
||||
dispatcher.on('error', console.error);
|
||||
|
||||
dispatcher2.on('start', () => {
|
||||
console.log('audio is now playing!');
|
||||
});
|
||||
|
||||
dispatcher2.on('finish', () => {
|
||||
console.log('audio has finished playing!');
|
||||
});
|
||||
dispatcher2.on('error', console.error);
|
||||
// Of course, you can also pause the stream using the `pause` function, but remember to pause both video and audio.
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,54 @@
|
||||
// https://v12.discordjs.guide/voice/receiving-audio.html#basic-usage
|
||||
|
||||
/*
|
||||
Install:
|
||||
- An Opus library: @discordjs/opus or opusscript
|
||||
- An encryption packages:
|
||||
+ sodium (best performance)
|
||||
+ libsodium-wrappers
|
||||
+ @stablelib/xchacha20poly1305
|
||||
- ffmpeg (install and add to your system environment)
|
||||
*/
|
||||
|
||||
|
||||
const { Client } = require('../../src/index');
|
||||
const client = new Client();
|
||||
|
||||
const fs = require('fs');
|
||||
const Speaker = require('speaker');
|
||||
|
||||
client.on('ready', async client => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
|
||||
const speaker = new Speaker({
|
||||
channels: 2, // 2 channels
|
||||
bitDepth: 16, // 16-bit samples
|
||||
sampleRate: 48000, // 48000 Hz sample rate
|
||||
});
|
||||
|
||||
const channel = client.channels.cache.get('voice_id');
|
||||
const connection = await client.voice.joinChannel(channel, {
|
||||
selfMute: true,
|
||||
selfDeaf: true,
|
||||
selfVideo: false,
|
||||
});
|
||||
|
||||
const audio = connection.receiver.createStream('user_id', {
|
||||
mode: 'pcm',
|
||||
end: 'manual',
|
||||
paddingSilence: true,
|
||||
});
|
||||
|
||||
audio.pipe(fs.createWriteStream('test.pcm'));
|
||||
|
||||
// After 15s
|
||||
setTimeout(() => {
|
||||
console.log('Stop recording');
|
||||
audio.destroy();
|
||||
// Play this record...
|
||||
fs.createReadStream('test.pcm').pipe(speaker);
|
||||
}, 15_000);
|
||||
});
|
||||
|
||||
|
||||
client.login('token');
|
||||
@@ -0,0 +1,45 @@
|
||||
// https://v12.discordjs.guide/voice/receiving-audio.html#basic-usage
|
||||
|
||||
/*
|
||||
Install:
|
||||
- An Opus library: @discordjs/opus or opusscript
|
||||
- An encryption packages:
|
||||
+ sodium (best performance)
|
||||
+ libsodium-wrappers
|
||||
+ @stablelib/xchacha20poly1305
|
||||
- ffmpeg (install and add to your system environment)
|
||||
*/
|
||||
|
||||
const { Client } = require('../../src/index');
|
||||
const client = new Client();
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
client.on('ready', async client => {
|
||||
console.log(`${client.user.username} is ready!`);
|
||||
|
||||
const channel = client.channels.cache.get('voice_id');
|
||||
const connection = await client.voice.joinChannel(channel, {
|
||||
selfMute: true,
|
||||
selfDeaf: true,
|
||||
selfVideo: false,
|
||||
});
|
||||
|
||||
const connectionStream = await connection.joinStreamConnection('user_id');
|
||||
|
||||
const video = connectionStream.receiver.createVideoStream('user_id', fs.createWriteStream('video.mkv')); // Output file using matroska container
|
||||
|
||||
video.on('ready', () => {
|
||||
console.log('FFmpeg process ready!');
|
||||
video.stream.stderr.on('data', data => {
|
||||
console.log(`FFmpeg: ${data}`);
|
||||
});
|
||||
});
|
||||
|
||||
// After 15s
|
||||
setTimeout(() => {
|
||||
video.destroy();
|
||||
}, 15_000);
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
Reference in New Issue
Block a user