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",
|
"name": "comty.js",
|
||||||
"version": "0.62.1",
|
"version": "0.63.0",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"description": "Official Comty API for JavaScript",
|
"description": "Official Comty API for JavaScript",
|
||||||
"homepage": "https://github.com/ragestudio/comty.js",
|
"homepage": "https://github.com/ragestudio/comty.js",
|
||||||
@ -18,7 +18,7 @@
|
|||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
"jsonwebtoken": "^9.0.0",
|
"jsonwebtoken": "^9.0.0",
|
||||||
"jwt-decode": "^4.0.0",
|
"jwt-decode": "^4.0.0",
|
||||||
"linebridge-client": "^1.0.0",
|
"linebridge-client": "^1.1.0",
|
||||||
"luxon": "^3.6.0",
|
"luxon": "^3.6.0",
|
||||||
"socket.io-client": "^4.8.1"
|
"socket.io-client": "^4.8.1"
|
||||||
},
|
},
|
||||||
|
@ -67,8 +67,6 @@ export function createClient({
|
|||||||
if (sessionToken) {
|
if (sessionToken) {
|
||||||
config.headers["Authorization"] =
|
config.headers["Authorization"] =
|
||||||
`${globalThis.isServerMode ? "Server" : "Bearer"} ${sessionToken}`
|
`${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 axios from "axios"
|
||||||
import SessionService from "../session"
|
import SessionModel from "../session"
|
||||||
//import User from "comty.js/models/user"
|
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)) {
|
if (!Array.isArray(list)) {
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
@ -11,7 +13,21 @@ async function injectUserData(list) {
|
|||||||
return item.user_id
|
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
|
return list
|
||||||
}
|
}
|
||||||
@ -28,9 +44,9 @@ export default class Streaming {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if (SessionService.token) {
|
if (SessionModel.token) {
|
||||||
baseInstance.defaults.headers.common["Authorization"] =
|
baseInstance.defaults.headers.common["Authorization"] =
|
||||||
`Bearer ${SessionService.token}`
|
`Bearer ${SessionModel.token}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseInstance
|
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() {
|
static async getOwnProfiles() {
|
||||||
const { data } = await Streaming.base({
|
const { data } = await Streaming.base({
|
||||||
method: "get",
|
method: "get",
|
||||||
@ -69,14 +98,11 @@ export default class Streaming {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getStream({ profile_id }) {
|
static async createOrUpdateProfile(update) {
|
||||||
if (!profile_id) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const { data } = await Streaming.base({
|
const { data } = await Streaming.base({
|
||||||
method: "get",
|
method: "put",
|
||||||
url: `/streaming/${profile_id}`,
|
url: `/streaming/profiles/self`,
|
||||||
|
data: update,
|
||||||
})
|
})
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -95,22 +121,7 @@ export default class Streaming {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
static async createOrUpdateStream(update) {
|
static async list({ limit, offset } = {}) {
|
||||||
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 } = {}) {
|
|
||||||
let { data } = await Streaming.base({
|
let { data } = await Streaming.base({
|
||||||
method: "get",
|
method: "get",
|
||||||
url: "/streaming/list",
|
url: "/streaming/list",
|
||||||
@ -120,17 +131,41 @@ export default class Streaming {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
data = await injectUserData(data)
|
data = await injectUserDataOnList(data)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getLivestreamData(livestream_id) {
|
static async createStreamWebsocket(stream_id, params = {}) {
|
||||||
const { data } = await Streaming.base({
|
if (!stream_id) {
|
||||||
method: "get",
|
console.error("stream_id is required")
|
||||||
url: `/streaming/${livestream_id}`,
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
const isConnected =
|
||||||
socket.connected === true &&
|
socket.connected === true || socket.state?.connected === true
|
||||||
typeof socket.disconnect === "function"
|
|
||||||
) {
|
if (isConnected && typeof socket.disconnect === "function") {
|
||||||
await socket.disconnect()
|
await socket.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user