Skip to content

Commit

Permalink
Merge pull request #3 from ikhbaldwiyan/feat/premium-live
Browse files Browse the repository at this point in the history
add all cookies params to live route
  • Loading branch information
ikhbaldwiyan authored May 25, 2023
2 parents 19ea0f9 + 2c641d1 commit 6b43280
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
55 changes: 43 additions & 12 deletions controller/lives.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,36 @@ const fetchService = require("../utils/fetchService");
const Lives = {
getStreamUrl: async (req, res) => {
try {
const roomId = req.params.roomId;
const { roomId, cookies } = req.params;
const url = `${LIVE}/streaming_url?room_id=${roomId}`;
const response = await fetchService(url, res);
const streamUrl = response.data.streaming_url_list;

res.send(streamUrl);
const response = await fetchService(url, res, {
headers: {
Cookie: cookies,
},
});
const streamUrl = response.data.streaming_url_list;
res.send(
streamUrl ?? {
message: "Room not live",
is_live: false,
}
);
} catch (error) {
return error;
}
},

getComments: async (req, res) => {
try {
const roomId = req.params.roomId;
const { roomId, cookies } = req.params;
const url = `${LIVE}/comment_log?room_id=${roomId}`;
const response = await fetchService(url, res);

const response = await fetchService(url, res, {
headers: {
Cookie: cookies,
},
});
const comments = response.data.comment_log;

res.send(comments);
Expand All @@ -30,13 +44,18 @@ const Lives = {

getTitle: async (req, res) => {
try {
const roomId = req.params.roomId;
const { roomId, cookies } = req.params;

const profileUrl = `${ROOM}/profile?room_id=${roomId}`;
const profileApi = await fetchService(profileUrl, res);
const profile = profileApi.data;

const titleUrl = `${LIVE}/telop?room_id=${roomId}`;
const titleApi = await fetchService(titleUrl, res);
const titleApi = await fetchService(titleUrl, res, {
headers: {
Cookie: cookies,
},
});
const title = titleApi.data.telop;

// Destrurct response profile and title
Expand Down Expand Up @@ -65,10 +84,16 @@ const Lives = {

getRank: async (req, res) => {
try {
const { roomId } = req.params;
const { roomId, cookies } = req.params;

const getRank = await fetchService(
`${LIVE}/stage_user_list?room_id=${roomId}`,
res
res,
{
headers: {
Cookie: cookies,
},
}
);
const totaGift = getRank.data.stage_user_list;

Expand All @@ -80,10 +105,16 @@ const Lives = {

getAllGift: async (req, res) => {
try {
const { roomId } = req.params;
const { roomId, cookies } = req.params;

const getAllGift = await fetchService(
`${LIVE}/gift_log?room_id=${roomId}`,
res
res,
{
headers: {
Cookie: cookies,
},
}
);
const totaGift = getAllGift.data.gift_log;

Expand Down
10 changes: 5 additions & 5 deletions routes/liveRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const express = require('express');
const Lives = require('../controller/lives');
const router = express.Router();

router.get('/:roomId', Lives.getStreamUrl)
router.get('/info/:roomId', Lives.getTitle)
router.get('/comments/:roomId', Lives.getComments)
router.get('/rank/:roomId', Lives.getRank)
router.get('/gift/:roomId', Lives.getAllGift)
router.get('/stream/:roomId/:cookies', Lives.getStreamUrl)
router.get('/info/:roomId/:cookies', Lives.getTitle)
router.get('/comments/:roomId/:cookies', Lives.getComments)
router.get('/rank/:roomId/:cookies', Lives.getRank)
router.get('/gift/:roomId/:cookies', Lives.getAllGift)

module.exports = router;

0 comments on commit 6b43280

Please sign in to comment.