Skip to content

Instantly share code, notes, and snippets.

View leaysgur's full-sized avatar
🏠
Active Weekdays 09-17 JST

Yuji Sugiura leaysgur

🏠
Active Weekdays 09-17 JST
View GitHub Profile
@leaysgur
leaysgur / util.js
Created December 12, 2019 01:10
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"
// 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.
@leaysgur
leaysgur / i16f32.js
Created November 29, 2019 06:09
Float32Array <-> Int16Array
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) {
@leaysgur
leaysgur / server.js
Created August 14, 2019 08:17
verify websocket upgrade
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) {
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),
@leaysgur
leaysgur / layout.jsx
Created May 27, 2019 12:47
The component to fix child content aspect size in flex window
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;
@leaysgur
leaysgur / .eslintignore
Last active April 18, 2019 15:42
Use ESLint to lint TypeScript using React, React Hooks w/ Prettier
!.*
/node_modules
@leaysgur
leaysgur / rtc-proxy.js
Last active February 21, 2019 10:32
Proxy all method calls on RTCPeerConnection
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) {
@leaysgur
leaysgur / index.html
Last active February 5, 2019 12:28
Test RTCQuicTransport on Chrome M73↑ w/ Experimental Web Platform features flags
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test RTCQuicTransport</title>
<style>
p { font-size: 2rem; }
</style>
</head>
<body>
@leaysgur
leaysgur / init.md
Last active January 28, 2019 06:08
新しいmacに設定すること

システム設定

  • Dock
    • アイコン消す
    • 最小にして左に
    • ホバーでのみ表示
  • トラックパッド
    • スクロール方向
  • キーボード
    • キーストローク
  • Ctrl <-> CapsLock
@leaysgur
leaysgur / memo.md
Created November 30, 2018 01:52
Use .y4m file for fake stream in Chrome
open "/Applications/Google Chrome.app/" --args --use-fake-device-for-media-stream --use-file-for-fake-video-capture="/path/to/example.y4m"

ってすると、フラグ有効状態でChromeが立ち上がる。

getUserMedia()すると、ローカルストリームの代わりに指定した.y4mの動画が使われるので、おじさんを見ながら開発しなくていい。