Skip to content

Instantly share code, notes, and snippets.

View matiaslopezd's full-sized avatar
🛰️
matiaslopezd[at]404.city

Matías López matiaslopezd

🛰️
matiaslopezd[at]404.city
View GitHub Profile
@matiaslopezd
matiaslopezd / example.js
Last active December 12, 2023 22:50
Snippet WebSocket
class MyCustomWebSocket extends WebSocket {
constructor(url) {
super(url);
}
}
const websocket = new MyCustomWebSocket('wss://websocket-test.videsk.workers.dev/');
@matiaslopezd
matiaslopezd / main.js
Created October 4, 2023 16:10
Add custom css to the widget
const style = document.createElement('style');
style.innerHTML = `
/* Add CSS */
`;
document.querySelector('.videsk-home-iframe iframe').contentDocument.head.appendChild(style):
@matiaslopezd
matiaslopezd / VideoFrame.js
Last active June 30, 2023 17:28
Diff script
import { VideoFrameEvents } from '@/utils/constants/events';
import { Customer } from '@/utils/constants/classes';
import LoadingBox from '@/components/commons/LoadingBox';
import ErrorCard from '@/components/commons/ErrorCard';
const VIDEO_FRAME_WRAPPER = 'video-frame-wrapper';
const VIDESK_COMPONENT = 'videsk-webrtc';
const VIDESK_TOKEN = process.env.VIDESK_TOKEN;
const VIDESK_SEGMENT= 'Videoatención Oficina';
@matiaslopezd
matiaslopezd / webrtc_quic.js
Created September 17, 2022 22:46 — forked from voluntas/webrtc_quic.js
RTCQuicTransport の動作サンプル
// Chrome Canary M74
// chrome://flags で Experimental Web Platform features を有効にすれば使えるようになる
// mDNS を有効にしていると上手く動かないかもしれないので要注意
// https://developers.google.com/web/updates/2019/01/rtcquictransport-api
// https://github.com/shampson/RTCQuicTransport-Origin-Trial-Documentation
const iceTransport1 = new RTCIceTransport;
const iceTransport2 = new RTCIceTransport;
@matiaslopezd
matiaslopezd / amplify.js
Last active December 1, 2023 09:12
Amplify audio/video source Javascript
function amplify(node, gain) {
const audioCtx = new AudioContext();
const source = audioCtx.createMediaElementSource(node);
// create a gain node
const gainNode = audioCtx.createGain();
gainNode.gain.value = gain;
source.connect(gainNode);
// connect the gain node to an output destination
@matiaslopezd
matiaslopezd / getSearchParams.js
Last active June 30, 2021 19:23
Set and get search params without reload
function getSearchParams() {
const { search } = window.location;
const params = new URLSearchParams(search);
const query = {};
params.forEach((value, key) => {
query[key] = value;
});
return query;
}
@matiaslopezd
matiaslopezd / script.js
Last active June 14, 2021 20:39
Read and set object by string path
Object.prototype.stringGet = function(string, object = this) {
string = string.replace(/\[(\w+)]/g, '.$1'); // convert indexes to properties
string = string.replace(/^\./, ''); // strip a leading dot
const array = string.split('.');
array.forEach((key) => {
if (key in object) object = object[key];
});
return object;
}
@matiaslopezd
matiaslopezd / put.js
Created June 14, 2021 20:29
Set deep data in object
/*!
* Add items to an object at a specific path
* (c) 2021 Chris Ferdinandi, MIT License, https://gomakethings.com
* @param {Object} obj The object
* @param {String|Array} path The path to assign the value to
* @param {*} val The value to assign
*/
Object.stringSet = (obj, path, val) => {
/**
@matiaslopezd
matiaslopezd / frontend.js
Last active June 14, 2021 19:30
Deep object access by string path
// This function can be used on frontend. For better performance use the "for" version
Object.byString = function(object, string) {
string = string.replace(/\[(\w+)]/g, '.$1'); // convert indexes to properties
string = string.replace(/^\./, ''); // strip a leading dot
const array = string.split('.');
array.forEach((key) => {
if (key in object) object = object[key];
});
return object;