-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from SWM-FIRE/dev
release v1.1.0
- Loading branch information
Showing
67 changed files
with
1,466 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { io } from 'socket.io-client'; | ||
import { API } from '../config'; | ||
import youtubeSearch from '../interface/youtubeSearch.interface'; | ||
|
||
const youtubeSocket = { | ||
socket: io(`${API.YOUTUBE_PLAYLIST as string}`, { | ||
transports: ['websocket', 'polling'], | ||
query: { token: localStorage.getItem('access_token') }, | ||
}), | ||
}; | ||
|
||
const generateYoutubeSocket = () => { | ||
youtubeSocket.socket = io(`${API.YOUTUBE_PLAYLIST as string}`, { | ||
transports: ['websocket', 'polling'], | ||
query: { token: localStorage.getItem('access_token') }, | ||
}); | ||
}; | ||
|
||
const initSocketConnection = () => { | ||
if (!youtubeSocket.socket) generateYoutubeSocket(); | ||
youtubeSocket.socket?.connect(); | ||
}; | ||
|
||
const checkSocket = () => { | ||
if (!youtubeSocket.socket || !youtubeSocket.socket.connected) { | ||
initSocketConnection(); | ||
} | ||
}; | ||
|
||
const disconnectSocket = () => { | ||
youtubeSocket.socket?.off('connect'); | ||
youtubeSocket.socket?.off('playlist:join'); | ||
youtubeSocket.socket?.off('playlist:joined'); | ||
youtubeSocket.socket?.off('playlist:sync'); | ||
youtubeSocket.socket?.disconnect(); | ||
}; | ||
|
||
const connectedYoutube = () => { | ||
youtubeSocket.socket?.on('connect', () => { | ||
console.log(`[youtube connect] connected! ${youtubeSocket.socket?.id}`); | ||
}); | ||
}; | ||
|
||
const joinYoutube = (roomId: string) => { | ||
checkSocket(); | ||
youtubeSocket.socket?.emit('playlist:join', { | ||
room: roomId, | ||
playlistName: 'playlistItem', | ||
}); | ||
console.log( | ||
`[emit join] waiting for join ${roomId}! ${youtubeSocket.socket?.id}`, | ||
); | ||
}; | ||
|
||
// const joinedYoutube = () => { | ||
// youtubeSocket.socket?.on('playlist:joined', (roomId: string) => { | ||
// console.log(`[on join] joined ${roomId}! ${youtubeSocket.socket?.id}`); | ||
// }); | ||
// }; | ||
|
||
const selectVideo = (roomId: string, video: youtubeSearch) => { | ||
checkSocket(); | ||
youtubeSocket.socket?.emit('playlist:sync', { | ||
room: roomId, | ||
playlistName: 'playlistItem', | ||
type: 'sync', | ||
playlist: [{ video }], | ||
}); | ||
console.log( | ||
`[emit select] select ${video.id.videoId}! ${youtubeSocket.socket?.id}`, | ||
); | ||
}; | ||
|
||
const addVideo = (addFunc) => { | ||
checkSocket(); | ||
youtubeSocket.socket?.on('playlist:sync', (data) => addFunc(data)); | ||
console.log(`[on add] add video! ${youtubeSocket.socket?.id}`); | ||
}; | ||
|
||
const leaveYoutube = (roomId: string) => { | ||
checkSocket(); | ||
youtubeSocket.socket?.emit('playlist:leave', { | ||
room: roomId, | ||
playlistName: 'playlistItem', | ||
}); | ||
console.log(`[emit leave] leave ${roomId}! ${youtubeSocket.socket?.id}`); | ||
}; | ||
|
||
export { | ||
youtubeSocket, | ||
initSocketConnection, | ||
// generateYoutubeSocket, | ||
disconnectSocket, | ||
connectedYoutube, | ||
joinYoutube, | ||
selectVideo, | ||
addVideo, | ||
leaveYoutube, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { awsRequest } from './awsLambdaAxios'; | ||
export { authorizationRequest, unAuthorizationRequest } from './backendAxios'; | ||
export { youtubeAxios } from './youtubeAxios'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import axios from 'axios'; | ||
import { API } from '../../config'; | ||
|
||
const youtubeAxios = axios.create({ | ||
baseURL: API.YOUTUBE, | ||
}); | ||
|
||
// add youtube key in params | ||
youtubeAxios.interceptors.request.use((config) => { | ||
return Object.assign(config, { | ||
params: { | ||
...config.params, | ||
key: process.env.REACT_APP_YOUTUBE_KEY, | ||
}, | ||
}); | ||
}); | ||
|
||
youtubeAxios.interceptors.response.use( | ||
(response) => { | ||
return response; | ||
}, | ||
(error) => { | ||
console.warn('[Axios] ', error); | ||
return Promise.reject(error); | ||
}, | ||
); | ||
|
||
export { youtubeAxios }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.