diff --git a/components/rumble/package.json b/components/rumble/package.json index 2dc2712634bea..fb436fbcf15a6 100644 --- a/components/rumble/package.json +++ b/components/rumble/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/rumble", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Rumble Components", "main": "rumble.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/components/rumble/rumble.app.mjs b/components/rumble/rumble.app.mjs index 7612196fcb0ad..c275dd02ce3f6 100644 --- a/components/rumble/rumble.app.mjs +++ b/components/rumble/rumble.app.mjs @@ -1,11 +1,33 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "rumble", propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://rumble.com/-livestream-api"; + }, + _makeRequest({ + $ = this, + path, + params = {}, + ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + params: { + ...params, + key: this.$auth.live_streaming_api_key, + }, + ...opts, + }); + }, + getData(opts = {}) { + return this._makeRequest({ + path: "/get-data", + ...opts, + }); }, }, }; diff --git a/components/rumble/sources/new-live-stream/new-live-stream.mjs b/components/rumble/sources/new-live-stream/new-live-stream.mjs new file mode 100644 index 0000000000000..5d1042203b1a8 --- /dev/null +++ b/components/rumble/sources/new-live-stream/new-live-stream.mjs @@ -0,0 +1,55 @@ +import rumble from "../../rumble.app.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import sampleEmit from "./test-event.mjs"; + +export default { + key: "rumble-new-live-stream", + name: "New Live Stream", + description: "Emit new event when a livestream becomes live in Rumble. [See the documentation](https://rumblefaq.groovehq.com/help/how-to-use-rumble-s-live-stream-api)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + rumble, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + methods: { + _getLastTs() { + return this.db.get("lastTs") || 0; + }, + _setLastTs(lastTs) { + this.db.set("lastTs", lastTs); + }, + generateMeta(livestream) { + return { + id: livestream.id, + summary: `${livestream.title} is live`, + ts: Date.parse(livestream.created_on), + }; + }, + }, + async run() { + const lastTs = this._getLastTs(); + let maxTs = lastTs; + + const { livestreams } = await this.rumble.getData(); + + for (const livestream of livestreams) { + const ts = Date.parse(livestream.created_on); + if (livestream?.is_live && ts > lastTs) { + const meta = this.generateMeta(livestream); + this.$emit(livestream, meta); + maxTs = Math.max(ts, maxTs); + } + } + + this._setLastTs(maxTs); + }, + sampleEmit, +}; diff --git a/components/rumble/sources/new-live-stream/test-event.mjs b/components/rumble/sources/new-live-stream/test-event.mjs new file mode 100644 index 0000000000000..a2c9d0b0b1c45 --- /dev/null +++ b/components/rumble/sources/new-live-stream/test-event.mjs @@ -0,0 +1,25 @@ +export default { + "id": "6pw8hx", + "title": "Livestream", + "created_on": "2025-04-14T17:07:27+00:00", + "is_live": true, + "visibility": "unlisted", + "categories": { + "primary": { + "slug": "technology", + "title": "Technology" + }, + "secondary": null + }, + "server_url": "", + "stream_key": "", + "likes": 0, + "dislikes": 0, + "watching_now": 0, + "chat": { + "latest_message": null, + "recent_messages": [], + "latest_rant": null, + "recent_rants": [] + } +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ddf106d676e64..ab21bba23aabc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11038,7 +11038,11 @@ importers: components/ruly: {} - components/rumble: {} + components/rumble: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/runpod: {}