diff --git a/src/models/spectrum/index.js b/src/models/spectrum/index.js index 2f0ac5d..c387093 100644 --- a/src/models/spectrum/index.js +++ b/src/models/spectrum/index.js @@ -1,96 +1,136 @@ import axios from "axios" import SessionService from "../session" +//import User from "comty.js/models/user" + +async function injectUserData(list) { + if (!Array.isArray(list)) { + return list + } + + const user_ids = list.map((item) => { + return item.user_id + }) + + //const users = await User.data(user_ids.join(",")) + + return list +} export default class Streaming { - static apiHostname = process.env.NODE_ENV === "production" ? "https://live.ragestudio.net" : "https://fr01.ragestudio.net:8035" + static apiHostname = "https://live.ragestudio.net" - static get base() { - const baseInstance = axios.create({ - baseURL: Streaming.apiHostname, - headers: { - "Accept": "application/json", - "ngrok-skip-browser-warning": "any" - } - }) + static get base() { + const baseInstance = axios.create({ + baseURL: Streaming.apiHostname, + headers: { + Accept: "application/json", + "ngrok-skip-browser-warning": "any", + }, + }) - if (SessionService.token) { - baseInstance.defaults.headers.common["Authorization"] = `Bearer ${SessionService.token}` - } + if (SessionService.token) { + baseInstance.defaults.headers.common["Authorization"] = + `Bearer ${SessionService.token}` + } - return baseInstance - } + return baseInstance + } - static async serverInfo() { - const { data } = await Streaming.base({ - method: "get", - }) + static async serverInfo() { + const { data } = await Streaming.base({ + method: "get", + }) - return { - ...data, - hostname: Streaming.apiHostname - } - } + return { + ...data, + hostname: Streaming.apiHostname, + } + } - static async getOwnProfiles() { - const { data } = await Streaming.base({ - method: "get", - url: "/streaming/profiles/self", - }) + static async getOwnProfiles() { + const { data } = await Streaming.base({ + method: "get", + url: "/streaming/profiles/self", + }) - return data - } + return data + } - static async getProfile({ profile_id }) { - if (!profile_id) { - return null - } + static async getProfile({ profile_id }) { + if (!profile_id) { + return null + } - const { data } = await Streaming.base({ - method: "get", - url: `/streaming/profiles/${profile_id}`, - }) + const { data } = await Streaming.base({ + method: "get", + url: `/streaming/profiles/${profile_id}`, + }) - return data - } + return data + } - static async getStream({ profile_id }) { - if (!profile_id) { - return null - } + static async getStream({ profile_id }) { + if (!profile_id) { + return null + } - const { data } = await Streaming.base({ - method: "get", - url: `/streaming/${profile_id}`, - }) + const { data } = await Streaming.base({ + method: "get", + url: `/streaming/${profile_id}`, + }) - return data - } + return data + } - static async deleteProfile({ profile_id }) { - if (!profile_id) { - return null - } + static async deleteProfile({ profile_id }) { + if (!profile_id) { + return null + } - const { data } = await Streaming.base({ - method: "delete", - url: `/streaming/profiles/${profile_id}`, - }) + const { data } = await Streaming.base({ + method: "delete", + url: `/streaming/profiles/${profile_id}`, + }) - return data - } + return data + } - static async createOrUpdateStream(update) { - const { data } = await Streaming.base({ - method: "put", - url: `/streaming/profiles/self`, - data: update, - }) + static async createOrUpdateStream(update) { + const { data } = await Streaming.base({ + method: "put", + url: `/streaming/profiles/self`, + data: update, + }) - return data - } + return data + } - static async getConnectionStatus({ profile_id }) { - console.warn("getConnectionStatus() | Not implemented") - return false - } -} \ No newline at end of file + static async getConnectionStatus({ profile_id }) { + console.warn("getConnectionStatus() | Not implemented") + return false + } + + static async getLivestreamsList({ limit, offset } = {}) { + let { data } = await Streaming.base({ + method: "get", + url: "/streaming/list", + params: { + limit, + offset, + }, + }) + + data = await injectUserData(data) + + return data + } + + static async getLivestreamData(livestream_id) { + const { data } = await Streaming.base({ + method: "get", + url: `/streaming/${livestream_id}`, + }) + + return data + } +}