mirror of
https://github.com/ragestudio/comty.js.git
synced 2025-06-09 02:24:18 +00:00
commit
f4004cd111
@ -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"
|
||||
},
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
21
src/models/events/index.js
Normal file
21
src/models/events/index.js
Normal 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
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user