v1.2.0-beta/fix file structure
This commit is contained in:
+111
@@ -0,0 +1,111 @@
|
||||
/*global chrome*/
|
||||
|
||||
const API_HOST = window.location.href.startsWith('http://localhost')
|
||||
? 'http://localhost:5001/watch-party-crx/us-central1/widgets'
|
||||
: // : 'http://localhost:5001/watch-party-crx/us-central1/widgets';
|
||||
'https://us-central1-watch-party-crx.cloudfunctions.net/widgets';
|
||||
|
||||
export const PLAYER_STATUS = {
|
||||
PLAYING: 'PLAYING',
|
||||
PAUSED: 'PAUSED',
|
||||
NOT_PLAYING: 'NOT_PLAYING',
|
||||
};
|
||||
|
||||
export const PLAYER_SOURCE = {
|
||||
NETFLIX: 'https://www.netflix.',
|
||||
AMAZON: 'https://www.amazon.',
|
||||
HULU: 'https://www.hulu.',
|
||||
DISNEY: 'https://www.disneyplus.',
|
||||
YOUTUBE: 'https://www.youtube.',
|
||||
HBONOW: 'https://play.hbonow.',
|
||||
LOCAL: 'http://localhost',
|
||||
};
|
||||
|
||||
export const getPlayerSource = () => {
|
||||
const HREF = window.location.href;
|
||||
if (HREF.startsWith(PLAYER_SOURCE.NETFLIX)) return PLAYER_SOURCE.NETFLIX;
|
||||
if (HREF.startsWith(PLAYER_SOURCE.HULU)) return PLAYER_SOURCE.HULU;
|
||||
if (HREF.startsWith(PLAYER_SOURCE.AMAZON)) return PLAYER_SOURCE.AMAZON;
|
||||
if (HREF.startsWith(PLAYER_SOURCE.DISNEY)) return PLAYER_SOURCE.DISNEY;
|
||||
if (HREF.startsWith(PLAYER_SOURCE.YOUTUBE)) return PLAYER_SOURCE.YOUTUBE;
|
||||
if (HREF.startsWith(PLAYER_SOURCE.HBONOW)) return PLAYER_SOURCE.HBONOW;
|
||||
if (HREF.startsWith(PLAYER_SOURCE.LOCAL)) return PLAYER_SOURCE.LOCAL;
|
||||
};
|
||||
|
||||
export const getUserUid = async () =>
|
||||
new Promise((resolve, reject) => {
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
type: 'GET_AUTH',
|
||||
},
|
||||
(response) => {
|
||||
const { uid } = response;
|
||||
window.localStorage.setItem('watchPartyUserUid', uid);
|
||||
resolve(uid);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
export const fetcher = async ({ endpoint, method, ...args }) => {
|
||||
const url = `${API_HOST}/${endpoint}`;
|
||||
return new Promise((resolve, reject) =>
|
||||
chrome.runtime.sendMessage(
|
||||
{
|
||||
type: 'API_CALL',
|
||||
url,
|
||||
method,
|
||||
...args,
|
||||
},
|
||||
(response) => {
|
||||
if (response.status > 299) reject(response);
|
||||
else resolve({ json: () => response });
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export const CreateRoomApi = async (data) => {
|
||||
return fetcher({
|
||||
endpoint: 'create',
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
};
|
||||
|
||||
export const JoinRoomApi = async (data) => {
|
||||
return fetcher({
|
||||
endpoint: 'join',
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
};
|
||||
|
||||
export const SendMessageApi = async (data) => {
|
||||
return fetcher({
|
||||
endpoint: 'message',
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
};
|
||||
|
||||
export const LeaveRoomApi = async (data) => {
|
||||
return fetcher({
|
||||
endpoint: `leave/${data.roomId}/users/${data.uid}`,
|
||||
method: 'DELETE',
|
||||
});
|
||||
};
|
||||
|
||||
export const DeleteRoomApi = async (data) => {
|
||||
return fetcher({
|
||||
endpoint: `delete/${data.roomId}`,
|
||||
method: 'DELETE',
|
||||
});
|
||||
};
|
||||
|
||||
export const UpdatePlayerApi = async (data) => {
|
||||
return fetcher({
|
||||
endpoint: 'updatePlayer',
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user