Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: testing onmount channel wrap #1230

Merged
merged 1 commit into from
May 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 81 additions & 79 deletions src/routes/channel/[channelId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,90 +50,92 @@
$: isLive = channel?.videoItems?.some((input: any) => input?.rtmps?.isConnected) ?? false

onMount(async () => {
clearInterval(platformPollingInterval)
platformPollingInterval = null
await loadChannel()
await handleWebsocket()
await loadMoreChannels()
$is_chat_drawer_destroy = false
setTimeout(() => {
$is_chat_drawer_open = true
}, 600)
if ($page.url.pathname.includes('/channel')) {
clearInterval(platformPollingInterval)
platformPollingInterval = null
await loadChannel()
await handleWebsocket()
await loadMoreChannels()
$is_chat_drawer_destroy = false
setTimeout(() => {
$is_chat_drawer_open = true
}, 600)

channel_message.subscribe(async (value: any) => {
if (!value || !channel || (channel && parseInt($page.params.channelId) !== channel._id))
return
var parsedMsg = JSON.parse(value)
switch (parsedMsg.eventName) {
case `channel-update-${$page.params.channelId}`:
console.log('channel-update', parsedMsg)
channel = {
...parsedMsg.channel,
socket: channel.socket,
videoItems: channel.videoItems,
isOnboarded: channel.isOnboarded
}
if (parsedMsg.roleUpdate) {
switch (parsedMsg.roleUpdate.roleEvent) {
case 'ban':
if (parsedMsg.roleUpdate.isEnabled) {
channel.videoItems = channel.videoItems.filter(
(video: any) => video._id !== parsedMsg.roleUpdate.userId
)
}
break
case 'guest':
if (parsedMsg.roleUpdate.isEnabled) {
channel.videoItems.push(parsedMsg.roleUpdate.user)
channel.videoItems = channel.videoItems
channel_message.subscribe(async (value: any) => {
if (!value || !channel || (channel && parseInt($page.params.channelId) !== channel._id))
return
var parsedMsg = JSON.parse(value)
switch (parsedMsg.eventName) {
case `channel-update-${$page.params.channelId}`:
console.log('channel-update', parsedMsg)
channel = {
...parsedMsg.channel,
socket: channel.socket,
videoItems: channel.videoItems,
isOnboarded: channel.isOnboarded
}
if (parsedMsg.roleUpdate) {
switch (parsedMsg.roleUpdate.roleEvent) {
case 'ban':
if (parsedMsg.roleUpdate.isEnabled) {
channel.videoItems = channel.videoItems.filter(
(video: any) => video._id !== parsedMsg.roleUpdate.userId
)
}
break
case 'guest':
if (parsedMsg.roleUpdate.isEnabled) {
channel.videoItems.push(parsedMsg.roleUpdate.user)
channel.videoItems = channel.videoItems
} else {
channel.videoItems = channel.videoItems.filter(
(video: any) => video._id !== parsedMsg.roleUpdate.userId
)
}
break
}
}
break
case `channel-subscribe-${$page.params.channelId}`:
userCount = parsedMsg.userCount
if (parsedMsg.quitUserId) {
channel.videoItems = channel.videoItems.filter(
(video: any) => video._id !== parsedMsg.quitUserId
)
console.log('channel.videoItems on quit : ', channel.videoItems)
} else {
const activeGuests = parsedMsg.activeGuests
if (activeGuests?.length) {
if (channel.videoItems?.length) {
// for users that are in the channel and new users join
// add new users but dont overwrite the existing ones streaming
channel.videoItems = activeGuests.map((guest: any) => {
const foundVideoItem = channel.videoItems.find(
(video: any) => guest._id === video._id
)
return foundVideoItem || guest
})
} else {
channel.videoItems = channel.videoItems.filter(
(video: any) => video._id !== parsedMsg.roleUpdate.userId
)
// for new users joining the channel
const liveInputs = await get(`live-inputs?channelId=${$page.params.channelId}`)
channel.videoItems = updateVideoItems([...activeGuests], liveInputs)
}
break
}
}
break
case `channel-subscribe-${$page.params.channelId}`:
userCount = parsedMsg.userCount
if (parsedMsg.quitUserId) {
channel.videoItems = channel.videoItems.filter(
(video: any) => video._id !== parsedMsg.quitUserId
)
console.log('channel.videoItems on quit : ', channel.videoItems)
} else {
const activeGuests = parsedMsg.activeGuests
if (activeGuests?.length) {
if (channel.videoItems?.length) {
// for users that are in the channel and new users join
// add new users but dont overwrite the existing ones streaming
channel.videoItems = activeGuests.map((guest: any) => {
const foundVideoItem = channel.videoItems.find(
(video: any) => guest._id === video._id
)
return foundVideoItem || guest
})
} else {
// for new users joining the channel
const liveInputs = await get(`live-inputs?channelId=${$page.params.channelId}`)
channel.videoItems = updateVideoItems([...activeGuests], liveInputs)
}
}
}
break
case `channel-streaming-action-${$page.params.channelId}`:
if (channel) {
channel.videoItems = updateVideoItems(channel.videoItems, [parsedMsg.data.video])
}
break
case `channel-get-sponsors-${$page.params.channelId}`:
if (channel) {
channel.sponsors = parsedMsg.sponsors
}
break
}
})
break
case `channel-streaming-action-${$page.params.channelId}`:
if (channel) {
channel.videoItems = updateVideoItems(channel.videoItems, [parsedMsg.data.video])
}
break
case `channel-get-sponsors-${$page.params.channelId}`:
if (channel) {
channel.sponsors = parsedMsg.sponsors
}
break
}
})
}
})

onDestroy(async () => {
Expand Down