Skip to content

Commit

Permalink
chore(integrations): await adding of integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed May 10, 2024
1 parent 598072b commit 1a0d2b1
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions apps/integrations/src/index.js
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)

0 comments on commit 1a0d2b1

Please sign in to comment.