Skip to content

Commit

Permalink
feat: add onDisconnected for VoiceChat
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokang00010 committed Jun 13, 2024
1 parent 3d8bcfb commit fa5c045
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"electron-start": "YOIMIYA=development electron .",
"electron-start": "set YOIMIYA=development ; electron .",
"electron-build": "react-scripts build ; electron-builder"
},
"eslintConfig": {
Expand Down
4 changes: 2 additions & 2 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function createWindow() {

function createVoiceChatWindow(charName) {
voiceChatWindow = new BrowserWindow({
width: 320, height: 500, webPreferences: {
width: 425, height: 500, webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
Expand Down Expand Up @@ -92,7 +92,7 @@ ipcMain.on('resize-window-normal', function (event) {

// listen event on `resize-window-login`
ipcMain.on('resize-window-login', function (event) {
mainWindow.setSize(425, 500)
mainWindow.setSize(320, 500)
})

ipcMain.on('create-voice-chat-window', function (event, charName) {
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<script src='./node_modules/electron-cookies/dist/electron-cookies.js'></script>
<!-- <script src='./node_modules/electron-cookies/dist/electron-cookies.js'></script> -->
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand Down
18 changes: 15 additions & 3 deletions src/routes/VoiceChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import React from 'react';
import { usePrefersColorScheme } from 'use-prefers-color-scheme';

import {
ConnectionState,
LiveKitRoom,
useConnectionState,
useRoomContext,
VideoConference,
} from '@livekit/components-react';

Expand All @@ -26,6 +29,10 @@ function VoiceChat() {
const [messageOpen, setMessageOpen] = React.useState(false)
const [connect, setConnect] = React.useState(false)

// const liveKitRoom = useRoomContext()
// const livekitRoomState = null


React.useEffect(() => {
const p = new URLSearchParams(window.location.hash.substring(window.location.hash.indexOf('?')));
console.log('called')
Expand Down Expand Up @@ -64,7 +71,7 @@ function VoiceChat() {

React.useEffect(() => {
if (sessionName !== '' && !connect) {
Remote.rtVcTerminate(sessionName).then(data => {
/*Remote.rtVcTerminate(sessionName).then(data => {
if (data.data.status) {
setConnect(false)
} else {
Expand All @@ -78,7 +85,8 @@ function VoiceChat() {
setMessageContent(err.message)
setMessageType('error')
setMessageOpen(true)
})
})*/
window.close()
}
}, [connect])

Expand All @@ -88,7 +96,11 @@ function VoiceChat() {
publishDefaults: {
red: false,
},
}} serverUrl={`ws://${remoteUrl}`} token={accessToken} connect={connect}>
}} serverUrl={`ws://${remoteUrl}`} token={accessToken} connect={connect}
onDisconnected={() => {
setConnect(false)
}}
>
<VideoConference ></VideoConference>
</LiveKitRoom>
</mui.Box>
Expand Down

0 comments on commit fa5c045

Please sign in to comment.