UNPKG

vertinho

Version:

Library to make conference apps and softphones through WebSockets with FreeSWITCH mod_verto.

126 lines (117 loc) 2.84 kB
/** * _ _ _ * | | (_) | | * __ _____ _ __| |_ _ _ __ | |__ ___ * \ \ / / _ \ '__| __| | '_ \| '_ \ / _ \ * \ V / __/ | | |_| | | | | | | | (_) | * \_/ \___|_| \__|_|_| |_|_| |_|\___/ * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * And see https://github.com/Mazuh/vertinho for the full license details. */ const integerToFourAlphanumerics = (integer) => { const digits = integer.toString(16); if (digits.length === 1) { return `000${digits}`; } if (digits.length === 2) { return `00${digits}`; } if (digits.length === 3) { return `00${digits}`; } return digits; }; export const generateGUID = () => { const bufferedRandoms = new Uint16Array(8); crypto.getRandomValues(bufferedRandoms); return [ integerToFourAlphanumerics(bufferedRandoms[0]), integerToFourAlphanumerics(bufferedRandoms[1]), '-', integerToFourAlphanumerics(bufferedRandoms[2]), '-', integerToFourAlphanumerics(bufferedRandoms[3]), '-', integerToFourAlphanumerics(bufferedRandoms[4]), '-', integerToFourAlphanumerics(bufferedRandoms[5]), integerToFourAlphanumerics(bufferedRandoms[6]), integerToFourAlphanumerics(bufferedRandoms[7]), ].join(''); }; export const ENUM = { state: { new: { name: 'new', val: 0 }, requesting: { name: 'requesting', val: 1 }, trying: { name: 'trying', val: 2 }, recovering: { name: 'recovering', val: 3 }, ringing: { name: 'ringing', val: 4 }, answering: { name: 'answering', val: 5 }, early: { name: 'early', val: 6 }, active: { name: 'active', val: 7 }, held: { name: 'held', val: 8 }, hangup: { name: 'hangup', val: 9 }, destroy: { name: 'destroy', val: 10 }, purge: { name: 'purge', val: 11 }, }, direction: { inbound: { name: 'inbound', val: 0 }, outbound: { name: 'outbound', val: 1 }, }, states: { new: { requesting: 1, recovering: 1, ringing: 1, destroy: 1, answering: 1, hangup: 1, }, requesting: { trying: 1, hangup: 1, active: 1, }, recovering: { answering: 1, hangup: 1, }, trying: { active: 1, early: 1, hangup: 1, }, ringing: { answering: 1, hangup: 1, }, answering: { active: 1, hangup: 1, }, active: { answering: 1, requesting: 1, hangup: 1, held: 1, }, held: { hangup: 1, active: 1, }, early: { hangup: 1, active: 1, }, hangup: { destroy: 1, }, destroy: {}, purge: { destroy: 1, }, }, };