Skip to content

Instantly share code, notes, and snippets.

Yuji Sugiura leader22

Block or report user

Report or block leader22

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@leader22
leader22 / notworking.js
Created Feb 16, 2020
[NOT WORKING] Discord.js voice echo bot
View notworking.js
const { Readable } = require("stream");
const Discord = require("discord.js");
const client = new Discord.Client();
const TOKEN = "YOUR_TOKEN_HERE";
const SILENCE_FRAME = Buffer.from([0xF8, 0xFF, 0xFE]);
class Silence extends Readable {
_read() {
this.push(SILENCE_FRAME);
@leader22
leader22 / webrtc-p2p-dc.js
Created Jan 27, 2020
Use playwright for WebRTC P2P DataChannel testing
View webrtc-p2p-dc.js
const { firefox, webkit, chromium } = require("playwright");
(async () => {
// webkit x webkit can not be tested. no host-candidates appears by restriction
const b1 = await setup(webkit);
const b2 = await setup(firefox);
const offer = await b1.page.evaluate(async () => {
const pc = window.pc = new RTCPeerConnection();
const dc = window.dc = pc.createDataChannel("x");
@leader22
leader22 / util.js
Created Dec 12, 2019
Dump of chrome://webrtc-internals by Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36"
View util.js
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// #import {assertInstanceof} from './assert.m.js';
// #import {dispatchSimpleEvent} from './cr.m.js';
// // Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@leader22
leader22 / i16f32.js
Created Nov 29, 2019
Float32Array <-> Int16Array
View i16f32.js
export function float32ToInt16(buffer) {
let l = buffer.length;
const buf = new Int16Array(l);
while (l--) {
buf[l] = Math.min(1, buffer[l]) * 0x7FFF;
}
return buf;
}
export function int16ToFloat32(int16arr) {
@leader22
leader22 / server.js
Created Aug 14, 2019
verify websocket upgrade
View server.js
const httpServer = http.createServer();
const wsServer = new Server({ noServer: true });
httpServer.on("upgrade", async (req, socket, head) => {
debug("handle upgrade request");
let peerId = null;
try {
peerId = await service.peer.verifyPeerId(req.url);
} catch (err) {
View logger.js
const readline = require('readline');
const fs = require('fs');
const { EventEmitter } = require('events');
const bowser = require('bowser');
module.exports = function(logPath) {
const emitter = new EventEmitter();
const rl = readline.createInterface({
input: fs.createReadStream(logPath),
@leader22
leader22 / layout.jsx
Created May 27, 2019
The component to fix child content aspect size in flex window
View layout.jsx
import React from 'react';
import { useEffect, useRef } from 'react';
import styled from '@emotion/styled';
const Layout = ({ aspect, debug, children }) => {
const ref = useRef(null);
useEffect(() => {
const fixSize = () => {
const $container = ref.current;
const $content = $container.firstElementChild;
@leader22
leader22 / .eslintignore
Last active Apr 18, 2019
Use ESLint to lint TypeScript using React, React Hooks w/ Prettier
View .eslintignore
!.*
/node_modules
@leader22
leader22 / rtc-proxy.js
Last active Feb 21, 2019
Proxy all method calls on RTCPeerConnection
View rtc-proxy.js
function proxyIt(obj, name) {
const debug = (...args) => console.log(`[${name}]`, ...args);
debug('install proxy for', obj);
return Proxy.revocable(obj, {
set(target, propKey, value) {
debug(`set ${propKey}`);
return Reflect.set(target, propKey, value);
},
get(target, propKey) {
@leader22
leader22 / index.html
Last active Feb 5, 2019
Test RTCQuicTransport on Chrome M73↑ w/ Experimental Web Platform features flags
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test RTCQuicTransport</title>
<style>
p { font-size: 2rem; }
</style>
</head>
<body>
You can’t perform that action at this time.