{"version":3,"file":"ping.mjs","names":[],"sources":["../../src/operations/ping.ts"],"sourcesContent":["import type { SingleConnection } from \"~/client/connection\";\nimport { awaitResponse } from \"~/await/await-response\";\nimport { ConnectionError } from \"~/client/errors\";\nimport { PongMessage } from \"~/message/twitch-types/connection/pong\";\n\nexport class PingTimeoutError extends ConnectionError {}\n\nfunction randomPingIdentifier(): string {\n  const randomHexString = Math.random().toString(16).slice(2, 14);\n  return `dank-twitch-irc:manual:${randomHexString}`;\n}\n\nexport async function sendPing(\n  conn: SingleConnection,\n  pingIdentifier: string = randomPingIdentifier(),\n  timeout = 2000,\n): Promise<PongMessage> {\n  conn.sendRaw(`PING :${pingIdentifier}`);\n\n  return awaitResponse(conn, {\n    success: (message): message is PongMessage =>\n      message instanceof PongMessage && message.argument === pingIdentifier,\n    timeout,\n    errorType: (message, cause) => new PingTimeoutError(message, cause),\n    errorMessage: \"Server did not PONG back\",\n  });\n}\n"],"mappings":";;;;AAKA,IAAa,mBAAb,cAAsC,gBAAgB;AAEtD,SAAS,uBAA+B;AAEtC,QAAO,0BADiB,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,GAAG,GAAG;;AAIjE,eAAsB,SACpB,MACA,iBAAyB,sBAAsB,EAC/C,UAAU,KACY;AACtB,MAAK,QAAQ,SAAS,iBAAiB;AAEvC,QAAO,cAAc,MAAM;EACzB,UAAU,YACR,mBAAmB,eAAe,QAAQ,aAAa;EACzD;EACA,YAAY,SAAS,UAAU,IAAI,iBAAiB,SAAS,MAAM;EACnE,cAAc;EACf,CAAC"}