var erlpack ; try { erlpack = require ( "@yukikaze-bot/erlpack" ) ; } catch ( error ) { console . log ( "Missing @yukikaze-bot/erlpack, electron-based desktop clients designed for discord.com will not be able to connect!" ) ; } import { Payload , WebSocket } from "@fosscord/gateway" ; export async function Send ( socket , data ) { let buffer ; if ( socket . encoding === "etf" ) buffer = erlpack . pack ( data ) ; else if ( socket . encoding === "json" ) buffer = JSON . stringify ( data ) ; else return ; if ( socket . deflate ) { socket . deflate . write ( buffer ) ; socket . deflate . flush ( ) ; return ; } return new Promise ( ( res , rej ) => { if ( socket . readyState !== 1 ) { return rej ( "socket not open" ) ; } socket . send ( buffer , ( err ) => { if ( err ) return rej ( err ) ; return res ( null ) ; } ) ; } ) ; }