-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(integrations): await adding of integration
- Loading branch information
Showing
1 changed file
with
38 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,103 @@ | ||
import { PORTS } from '@twir/grpc/constants/constants'; | ||
import * as Integrations from '@twir/grpc/integrations/integrations'; | ||
import { createServer } from 'nice-grpc'; | ||
import { PORTS } from '@twir/grpc/constants/constants' | ||
import * as Integrations from '@twir/grpc/integrations/integrations' | ||
import { createServer } from 'nice-grpc' | ||
|
||
import { getIntegrations, Services } from './libs/db.js'; | ||
import { Services, getIntegrations } from './libs/db.js' | ||
import { | ||
addIntegration as addDonatePayIntegration, | ||
removeIntegration as removeDonatePayIntegration, | ||
} from './store/donatePay.js'; | ||
} from './store/donatePay.js' | ||
import { | ||
addIntegration as addDonationAlertsIntegration, | ||
removeIntegration as removeDonationAlertsIntegration, | ||
} from './store/donationAlerts.js'; | ||
} from './store/donationAlerts.js' | ||
import { | ||
addIntegration as addStreamlabsIntegration, | ||
removeIntegration as removeStreamlabsIntegration, | ||
} from './store/streamlabs.js'; | ||
} from './store/streamlabs.js' | ||
|
||
import './pubsub.js'; | ||
import './pubsub.js' | ||
|
||
const integrations = await getIntegrations(); | ||
const integrations = await getIntegrations() | ||
|
||
for (const integration of integrations) { | ||
if (integration.integration.service === Services.DONATIONALERTS) { | ||
addDonationAlertsIntegration(integration); | ||
await addDonationAlertsIntegration(integration) | ||
} | ||
|
||
if (integration.integration.service === Services.STREAMLABS) { | ||
addStreamlabsIntegration(integration); | ||
await addStreamlabsIntegration(integration) | ||
} | ||
|
||
if (integration.integration.service === Services.DONATEPAY) { | ||
addDonatePayIntegration(integration); | ||
await addDonatePayIntegration(integration) | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @type {import('@twir/grpc/integrations/integrations').IntegrationsServiceImplementation} | ||
*/ | ||
* @type {import('@twir/grpc/integrations/integrations').IntegrationsServiceImplementation} | ||
*/ | ||
const integrationsServer = { | ||
async addIntegration(data) { | ||
const integration = await getIntegrations(data.id); | ||
const integration = await getIntegrations(data.id) | ||
|
||
if (!integration) { | ||
return {}; | ||
return {} | ||
} | ||
|
||
console.info(`Adding ${integration.id} connection`); | ||
console.info(`Adding ${integration.id} connection`) | ||
|
||
if (integration.integration.service === Services.DONATIONALERTS) { | ||
addDonationAlertsIntegration(integration); | ||
addDonationAlertsIntegration(integration) | ||
} | ||
if (integration.integration.service === Services.STREAMLABS) { | ||
addStreamlabsIntegration(integration); | ||
addStreamlabsIntegration(integration) | ||
} | ||
if (integration.integration.service === Services.DONATEPAY) { | ||
addDonatePayIntegration(integration); | ||
addDonatePayIntegration(integration) | ||
} | ||
|
||
return {}; | ||
return {} | ||
}, | ||
|
||
async removeIntegration(data) { | ||
const integration = await getIntegrations(data.id); | ||
const integration = await getIntegrations(data.id) | ||
|
||
if (!integration) { | ||
return {}; | ||
return {} | ||
} | ||
|
||
console.info(`Destroying ${integration.id} connection`); | ||
await removeIntegration(integration); | ||
return {}; | ||
console.info(`Destroying ${integration.id} connection`) | ||
await removeIntegration(integration) | ||
return {} | ||
}, | ||
}; | ||
} | ||
|
||
const server = createServer({ | ||
'grpc.keepalive_time_ms': 1 * 60 * 1000, | ||
}); | ||
}) | ||
|
||
server.add(Integrations.IntegrationsDefinition, integrationsServer); | ||
server.add(Integrations.IntegrationsDefinition, integrationsServer) | ||
|
||
await server.listen(`0.0.0.0:${PORTS.INTEGRATIONS_SERVER_PORT}`); | ||
console.info('Integrations started'); | ||
await server.listen(`0.0.0.0:${PORTS.INTEGRATIONS_SERVER_PORT}`) | ||
console.info('Integrations started') | ||
|
||
/** | ||
* @param {Integration} integration Options object for each OS, and global options. | ||
*/ | ||
* @param {Integration} integration Options object for each OS, and global options. | ||
*/ | ||
export async function removeIntegration(integration) { | ||
if (integration.integration.service === Services.STREAMLABS) { | ||
removeStreamlabsIntegration(integration.channelId); | ||
removeStreamlabsIntegration(integration.channelId) | ||
} | ||
|
||
if (integration.integration.service === Services.DONATIONALERTS) { | ||
removeDonationAlertsIntegration(integration.channelId); | ||
removeDonationAlertsIntegration(integration.channelId) | ||
} | ||
|
||
if (integration.integration.service === Services.DONATEPAY) { | ||
removeDonatePayIntegration(integration.channelId); | ||
removeDonatePayIntegration(integration.channelId) | ||
} | ||
} | ||
|
||
process.on('uncaughtException', console.error); | ||
process.on('unhandledRejection', console.error); | ||
process.on('uncaughtException', console.error) | ||
process.on('unhandledRejection', console.error) |