Merge pull request #4 from ragestudio/dev

0.63.0
This commit is contained in:
srgooglo 2025-04-09 23:22:20 +02:00 committed by GitHub
commit f4004cd111
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 97 additions and 43 deletions

View File

@ -1,6 +1,6 @@
{
"name": "comty.js",
"version": "0.62.1",
"version": "0.63.0",
"main": "./dist/index.js",
"description": "Official Comty API for JavaScript",
"homepage": "https://github.com/ragestudio/comty.js",
@ -18,7 +18,7 @@
"js-cookie": "^3.0.5",
"jsonwebtoken": "^9.0.0",
"jwt-decode": "^4.0.0",
"linebridge-client": "^1.0.0",
"linebridge-client": "^1.1.0",
"luxon": "^3.6.0",
"socket.io-client": "^4.8.1"
},

View File

@ -67,8 +67,6 @@ export function createClient({
if (sessionToken) {
config.headers["Authorization"] =
`${globalThis.isServerMode ? "Server" : "Bearer"} ${sessionToken}`
} else {
console.warn("Making a request with no session token")
}
}

View File

@ -0,0 +1,21 @@
import request from "../../request"
export default class EventsModel {
static async getFeatured() {
const { data } = await request({
method: "GET",
url: "/featured/events",
})
return data
}
static async data(id) {
const { data } = await request({
method: "GET",
url: `/events/${id}/data`,
})
return data
}
}

View File

@ -1,8 +1,10 @@
import axios from "axios"
import SessionService from "../session"
//import User from "comty.js/models/user"
import SessionModel from "../session"
import UserModel from "../user"
import { RTEngineClient } from "linebridge-client/src"
//import { RTEngineClient } from "../../../../linebridge/client/src"
async function injectUserData(list) {
async function injectUserDataOnList(list) {
if (!Array.isArray(list)) {
return list
}
@ -11,7 +13,21 @@ async function injectUserData(list) {
return item.user_id
})
//const users = await User.data(user_ids.join(","))
let users = await UserModel.data({ user_id: user_ids.join(",") })
if (!Array.isArray(users)) {
users = [users]
}
const userMap = new Map(users.map((user) => [user._id, user]))
list = list.map((item) => {
const user = userMap.get(item.user_id)
return {
...item,
user: user,
}
})
return list
}
@ -28,9 +44,9 @@ export default class Streaming {
},
})
if (SessionService.token) {
if (SessionModel.token) {
baseInstance.defaults.headers.common["Authorization"] =
`Bearer ${SessionService.token}`
`Bearer ${SessionModel.token}`
}
return baseInstance
@ -47,6 +63,19 @@ export default class Streaming {
}
}
static async getStream(stream_id) {
if (!stream_id) {
return null
}
const { data } = await Streaming.base({
method: "get",
url: `/streaming/${stream_id}`,
})
return data
}
static async getOwnProfiles() {
const { data } = await Streaming.base({
method: "get",
@ -69,14 +98,11 @@ export default class Streaming {
return data
}
static async getStream({ profile_id }) {
if (!profile_id) {
return null
}
static async createOrUpdateProfile(update) {
const { data } = await Streaming.base({
method: "get",
url: `/streaming/${profile_id}`,
method: "put",
url: `/streaming/profiles/self`,
data: update,
})
return data
@ -95,22 +121,7 @@ export default class Streaming {
return data
}
static async createOrUpdateStream(update) {
const { data } = await Streaming.base({
method: "put",
url: `/streaming/profiles/self`,
data: update,
})
return data
}
static async getConnectionStatus({ profile_id }) {
console.warn("getConnectionStatus() | Not implemented")
return false
}
static async getLivestreamsList({ limit, offset } = {}) {
static async list({ limit, offset } = {}) {
let { data } = await Streaming.base({
method: "get",
url: "/streaming/list",
@ -120,17 +131,41 @@ export default class Streaming {
},
})
data = await injectUserData(data)
data = await injectUserDataOnList(data)
return data
}
static async getLivestreamData(livestream_id) {
const { data } = await Streaming.base({
method: "get",
url: `/streaming/${livestream_id}`,
static async createStreamWebsocket(stream_id, params = {}) {
if (!stream_id) {
console.error("stream_id is required")
return null
}
const client = new RTEngineClient({
...params,
url: Streaming.apiHostname,
token: SessionModel.token,
})
return data
client._destroy = client.destroy
client.destroy = () => {
client.emit("stream:leave", stream_id)
if (typeof client._destroy === "function") {
client._destroy()
}
}
client.requestState = async () => {
return await client.call("stream:state", stream_id)
}
client.on("connected", () => {
client.emit("stream:join", stream_id)
})
return client
}
}

View File

@ -98,10 +98,10 @@ class WebsocketManager {
return null
}
if (
socket.connected === true &&
typeof socket.disconnect === "function"
) {
const isConnected =
socket.connected === true || socket.state?.connected === true
if (isConnected && typeof socket.disconnect === "function") {
await socket.disconnect()
}