Skip to content

Commit

Permalink
🔊 Add debug logs for subscription packets
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillaverde committed May 20, 2024
1 parent dd7bc8c commit dd910b0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
11 changes: 4 additions & 7 deletions src/tasks/publishDiscord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,23 @@ import humanizeDuration from "npm:humanize-duration";
import { StreamLiveTracker } from "../types/streamTrackers.ts";

const streamLiveTracker: StreamLiveTracker = {};
let subscribed = false;

export default function publishDiscord() {
mqttService.connect();
mqttService.on("reconnect", () => logger.info("Reconnected to MQTT Broker"));
mqttService.on("reconnect", () => logger.debug("Reconnected to MQTT Broker"));
mqttService.on("connect", () => {
if (subscribed) return;
mqttService.subscribe(mqttConfig.MQTT_TOPIC, { qos: 2 }, (err) => {
if (err) {
logger.error(err.toString());
} else {
subscribed = true;
logger.info(`Subscribed to "${mqttConfig.MQTT_TOPIC}" MQTT Topic`);
logger.debug(`Subscribed to "${mqttConfig.MQTT_TOPIC}" MQTT Topic`);
}
});
});
mqttService.on("message", async (_topic, message) => {
mqttService.on("message", async (_topic, message, packet) => {
try {
const decodedMessage: PubSubMessage = JSON.parse(message.toString());
logger.debug(decodedMessage);
logger.debug(decodedMessage, packet);
if (!discordConfig[decodedMessage.type].enable) return;
if (decodedMessage.type === "twitch") {
sendEmbedMessage(decodedMessage);
Expand Down
11 changes: 4 additions & 7 deletions src/tasks/publishMastodon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@ import mqttConfig from "../config/mqtt.config.ts";
import { StreamTimeTracker } from "../types/streamTrackers.ts";

const streamTimeTracker: StreamTimeTracker = {};
let subscribed = false;

export default function publishMastodon() {
mqttService.connect();
mqttService.on("reconnect", () => logger.info("Reconnected to MQTT Broker"));
mqttService.on("reconnect", () => logger.debug("Reconnected to MQTT Broker"));
mqttService.on("connect", () => {
if (subscribed) return;
mqttService.subscribe(mqttConfig.MQTT_TOPIC, { qos: 2 }, (err) => {
if (err) {
logger.error(err.toString());
} else {
subscribed = true;
logger.info(`Subscribed to "${mqttConfig.MQTT_TOPIC}" MQTT Topic`);
logger.debug(`Subscribed to "${mqttConfig.MQTT_TOPIC}" MQTT Topic`);
}
});
});
mqttService.on("message", async (_topic, message) => {
mqttService.on("message", async (_topic, message, packet) => {
try {
const decodedMessage: PubSubMessage = JSON.parse(message.toString());
logger.debug(decodedMessage);
logger.debug(decodedMessage, packet);
if (!mastodonConfig[decodedMessage.type].enable) return;
if (decodedMessage.type === "twitch" && decodedMessage.stream) {
const streamId = decodedMessage.stream.id;
Expand Down
11 changes: 4 additions & 7 deletions src/tasks/publishTwitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@ import mqttConfig from "../config/mqtt.config.ts";
import { StreamTimeTracker } from "../types/streamTrackers.ts";

const streamTimeTracker: StreamTimeTracker = {};
let subscribed = false;

export default function publishTwitter() {
mqttService.connect();
mqttService.on("reconnect", () => logger.info("Reconnected to MQTT Broker"));
mqttService.on("reconnect", () => logger.debug("Reconnected to MQTT Broker"));
mqttService.on("connect", () => {
if (subscribed) return;
mqttService.subscribe(mqttConfig.MQTT_TOPIC, { qos: 2 }, (err) => {
if (err) {
logger.error(err.toString());
} else {
subscribed = true;
logger.info(`Subscribed to "${mqttConfig.MQTT_TOPIC}" MQTT Topic`);
logger.debug(`Subscribed to "${mqttConfig.MQTT_TOPIC}" MQTT Topic`);
}
});
});
mqttService.on("message", async (_topic, message) => {
mqttService.on("message", async (_topic, message, packet) => {
try {
const decodedMessage: PubSubMessage = JSON.parse(message.toString());
logger.debug(decodedMessage);
logger.debug(decodedMessage, packet);
if (!twitterConfig[decodedMessage.type].enable) return;
if (decodedMessage.type === "twitch" && decodedMessage.stream) {
const streamId = decodedMessage.stream.id;
Expand Down

0 comments on commit dd910b0

Please sign in to comment.