UNPKG

@twurple/eventsub-http

Version:

Listen to events on Twitch via their EventSub API using a HTTP/WebHook server.

71 lines (70 loc) 1.98 kB
import { __decorate } from "tslib"; import { Enumerable } from '@d-fischer/shared-utils'; import { rtfm } from '@twurple/common'; import * as https from 'https'; import { checkHostName } from '../checks.js'; import { ConnectionAdapter } from './ConnectionAdapter.js'; /** * A WebHook connection adapter that enables a direct connection. * * Requires the server to be directly available to the internet. * * @hideProtected * * @meta category adapters */ let DirectConnectionAdapter = class DirectConnectionAdapter extends ConnectionAdapter { _hostName; /** @internal */ _ssl; /** @internal */ _httpsServer; /** * Creates a new simple WebHook adapter. * * @expandParams * * @param options */ constructor(options) { super(); checkHostName(options.hostName); this._hostName = options.hostName; this._ssl = options.sslCert; } /** * Updates the SSL certificate, for example if the old one is expired. * * @expandParams * * @param ssl The new certificate data. */ updateSslCertificate(ssl) { this._ssl = ssl; this._httpsServer?.setSecureContext(ssl); } /** @protected */ createHttpServer() { return (this._httpsServer = https.createServer({ key: this._ssl.key, cert: this._ssl.cert, })); } /** @protected */ // eslint-disable-next-line @typescript-eslint/class-literal-property-style get listenUsingSsl() { return true; } /** @protected */ async getHostName() { return this._hostName; } }; __decorate([ Enumerable(false) ], DirectConnectionAdapter.prototype, "_ssl", void 0); __decorate([ Enumerable(false) ], DirectConnectionAdapter.prototype, "_httpsServer", void 0); DirectConnectionAdapter = __decorate([ rtfm('eventsub-http', 'DirectConnectionAdapter') ], DirectConnectionAdapter); export { DirectConnectionAdapter };