This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C-969] Add native audio-screen (#1873)
- Loading branch information
1 parent
3583795
commit 3d8dbf9
Showing
48 changed files
with
401 additions
and
278 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { AudiusBackend, AuthHeaders } from '../audius-backend' | ||
|
||
type HttpMethod = 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | ||
|
||
export type CognitoSignatureResponse = { signature: string } | ||
export type CognitoFlowResponse = { shareable_url: string } | ||
export type CognitoFlowExistsResponse = { exists: boolean } | ||
type AuthHeadersType = typeof AuthHeaders | ||
type MakeRequestConfig = { | ||
path: string | ||
method?: HttpMethod | ||
useAuth?: boolean | ||
} | ||
|
||
type CognitoConfig = { | ||
audiusBackend: AudiusBackend | ||
} | ||
|
||
export class Cognito { | ||
audiusBackend: AudiusBackend | ||
constructor(config: CognitoConfig) { | ||
this.audiusBackend = config.audiusBackend | ||
} | ||
|
||
_makeRequest = async <ResponseModel>( | ||
config: MakeRequestConfig | ||
): Promise<ResponseModel> => { | ||
const { path, method = 'GET', useAuth = true } = config | ||
const options: { | ||
method: HttpMethod | ||
headers?: { [key in AuthHeadersType[keyof AuthHeadersType]]: string } | ||
} = { method } | ||
if (useAuth) { | ||
const libs = await this.audiusBackend.getAudiusLibs() | ||
const account = libs.Account.getCurrentUser() | ||
if (!account) { | ||
throw new Error('Cognito Identity Request Failed: Missing current user') | ||
} | ||
const { data, signature } = await this.audiusBackend.signData() | ||
options.headers = { | ||
[AuthHeaders.Message]: data, | ||
[AuthHeaders.Signature]: signature | ||
} | ||
} | ||
const response = await fetch( | ||
`${this.audiusBackend.identityServiceUrl}${path}`, | ||
options | ||
) | ||
if (response.status >= 400 && response.status < 600) { | ||
throw new Error(`Cognito Identity Request Failed: ${response.statusText}`) | ||
} | ||
const json: ResponseModel = await response.json() | ||
return json | ||
} | ||
|
||
getCognitoSignature = () => | ||
this._makeRequest<CognitoSignatureResponse>({ path: '/cognito_signature' }) | ||
|
||
getCognitoFlow = () => | ||
this._makeRequest<CognitoFlowResponse>({ | ||
path: '/cognito_flow', | ||
method: 'POST' | ||
}) | ||
|
||
getCognitoExists = (handle: string) => | ||
this._makeRequest<CognitoFlowExistsResponse>({ | ||
path: `/cognito_recent_exists/${handle}`, | ||
method: 'GET', | ||
useAuth: false | ||
}) | ||
} |
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 @@ | ||
export * from './Cognito' |
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,5 @@ | ||
export * as musicConfettiSelectors from './selectors' | ||
export { | ||
default as musicConfettiReducer, | ||
actions as musicConfettiActions | ||
} from './slice' |
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,4 @@ | ||
import { CommonState } from '../commonStore' | ||
|
||
export const getIsVisible = (state: CommonState) => | ||
state.ui.musicConfetti.isVisible |
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
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
Oops, something went wrong.