mirror of https://github.com/jitsi/jitsi-meet
feat(billing-counter) Removed iframe billing-counter callbacks (#9537)
* Removed iframe billing-counter callbacks * Moved remaining items to jaas * Fixed import path * Removed billingCounter condition * Use getvpaasTenant in middleware * Removed billingId * Path fix * Removed jwt from isVpaasMeeting * Fix isVpaaspull/9581/head jitsi-meet_6093
parent
4c3aae1e28
commit
4276f82c03
@ -1,4 +0,0 @@ |
||||
/** |
||||
* Action used to store the flag signaling the endpoint has been counted. |
||||
*/ |
||||
export const SET_ENDPOINT_COUNTED = 'SET_ENDPOINT_COUNTED'; |
@ -1,42 +0,0 @@ |
||||
// @flow
|
||||
|
||||
import { SET_ENDPOINT_COUNTED } from './actionTypes'; |
||||
import { extractVpaasTenantFromPath, getBillingId, sendCountRequest } from './functions'; |
||||
|
||||
/** |
||||
* Sends a billing count request when needed. |
||||
* |
||||
* @returns {Function} |
||||
*/ |
||||
export function countEndpoint() { |
||||
return function(dispatch: Function, getState: Function) { |
||||
const state = getState(); |
||||
const baseUrl = state['features/base/config'].billingCounterUrl; |
||||
const jwt = state['features/base/jwt'].jwt; |
||||
const tenant = extractVpaasTenantFromPath(state['features/base/connection'].locationURL.pathname); |
||||
const shouldSendRequest = Boolean(baseUrl && jwt && tenant); |
||||
|
||||
if (shouldSendRequest) { |
||||
const billingId = getBillingId(); |
||||
|
||||
sendCountRequest({ |
||||
baseUrl, |
||||
billingId, |
||||
jwt, |
||||
tenant |
||||
}); |
||||
dispatch(setEndpointCounted()); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* Action used to mark the endpoint as counted. |
||||
* |
||||
* @returns {Object} |
||||
*/ |
||||
function setEndpointCounted() { |
||||
return { |
||||
type: SET_ENDPOINT_COUNTED |
||||
}; |
||||
} |
@ -1,9 +0,0 @@ |
||||
/** |
||||
* The key for the billing id stored in localStorage. |
||||
*/ |
||||
export const BILLING_ID = 'jitsiMeetId'; |
||||
|
||||
/** |
||||
* The prefix for the vpaas tenant. |
||||
*/ |
||||
export const VPAAS_TENANT_PREFIX = 'vpaas-magic-cookie-'; |
@ -1,112 +0,0 @@ |
||||
// @flow
|
||||
|
||||
import { jitsiLocalStorage } from '@jitsi/js-utils'; |
||||
import uuid from 'uuid'; |
||||
|
||||
import { BILLING_ID, VPAAS_TENANT_PREFIX } from './constants'; |
||||
import logger from './logger'; |
||||
|
||||
/** |
||||
* Returns the full vpaas tenant if available, given a path. |
||||
* |
||||
* @param {string} path - The meeting url path. |
||||
* @returns {string} |
||||
*/ |
||||
export function extractVpaasTenantFromPath(path: string) { |
||||
const [ , tenant ] = path.split('/'); |
||||
|
||||
if (tenant.startsWith(VPAAS_TENANT_PREFIX)) { |
||||
return tenant; |
||||
} |
||||
|
||||
return ''; |
||||
} |
||||
|
||||
/** |
||||
* Returns the vpaas tenant. |
||||
* |
||||
* @param {Object} state - The global state. |
||||
* @returns {string} |
||||
*/ |
||||
export function getVpaasTenant(state: Object) { |
||||
return extractVpaasTenantFromPath(state['features/base/connection'].locationURL.pathname); |
||||
} |
||||
|
||||
/** |
||||
* Returns true if the current meeting is a vpaas one. |
||||
* |
||||
* @param {Object} state - The state of the app. |
||||
* @returns {boolean} |
||||
*/ |
||||
export function isVpaasMeeting(state: Object) { |
||||
const { billingCounterUrl } = state['features/base/config']; |
||||
|
||||
return Boolean( |
||||
billingCounterUrl |
||||
&& extractVpaasTenantFromPath( |
||||
state['features/base/connection'].locationURL.pathname) |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* Sends a billing counter request. |
||||
* |
||||
* @param {Object} reqData - The request info. |
||||
* @param {string} reqData.baseUrl - The base url for the request. |
||||
* @param {string} billingId - The unique id of the client. |
||||
* @param {string} jwt - The JWT token. |
||||
* @param {string} tenat - The client tenant. |
||||
* @returns {void} |
||||
*/ |
||||
export async function sendCountRequest({ baseUrl, billingId, jwt, tenant }: { |
||||
baseUrl: string, |
||||
billingId: string, |
||||
jwt: string, |
||||
tenant: string |
||||
}) { |
||||
const fullUrl = `${baseUrl}/${encodeURIComponent(tenant)}/${billingId}`; |
||||
const headers = { |
||||
'Authorization': `Bearer ${jwt}` |
||||
}; |
||||
|
||||
try { |
||||
const res = await fetch(fullUrl, { |
||||
method: 'GET', |
||||
headers |
||||
}); |
||||
|
||||
if (!res.ok) { |
||||
logger.error('Status error:', res.status); |
||||
} |
||||
} catch (err) { |
||||
logger.error('Could not send request', err); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns the stored billing id (or generates a new one if none is present). |
||||
* |
||||
* @returns {string} |
||||
*/ |
||||
export function getBillingId() { |
||||
let billingId = jitsiLocalStorage.getItem(BILLING_ID); |
||||
|
||||
if (!billingId) { |
||||
billingId = uuid.v4(); |
||||
jitsiLocalStorage.setItem(BILLING_ID, billingId); |
||||
} |
||||
|
||||
return billingId; |
||||
} |
||||
|
||||
/** |
||||
* Returns the billing id for vpaas meetings. |
||||
* |
||||
* @param {Object} state - The state of the app. |
||||
* @returns {string | undefined} |
||||
*/ |
||||
export function getVpaasBillingId(state: Object) { |
||||
if (isVpaasMeeting(state)) { |
||||
return getBillingId(); |
||||
} |
||||
} |
@ -1,5 +0,0 @@ |
||||
// @flow
|
||||
|
||||
import { getLogger } from '../base/logging/functions'; |
||||
|
||||
export default getLogger('features/billing-counter'); |
@ -1,29 +0,0 @@ |
||||
import { ReducerRegistry } from '../base/redux'; |
||||
|
||||
import { |
||||
SET_ENDPOINT_COUNTED |
||||
} from './actionTypes'; |
||||
|
||||
const DEFAULT_STATE = { |
||||
endpointCounted: false |
||||
}; |
||||
|
||||
/** |
||||
* Listen for actions that mutate the billing-counter state |
||||
*/ |
||||
ReducerRegistry.register( |
||||
'features/billing-counter', (state = DEFAULT_STATE, action) => { |
||||
switch (action.type) { |
||||
|
||||
case SET_ENDPOINT_COUNTED: { |
||||
return { |
||||
...state, |
||||
endpointCounted: true |
||||
}; |
||||
} |
||||
|
||||
default: |
||||
return state; |
||||
} |
||||
}, |
||||
); |
Loading…
Reference in new issue