Skip to content

Commit

Permalink
misc: verify discovery server
Browse files Browse the repository at this point in the history
  • Loading branch information
embbnux committed Dec 19, 2024
1 parent ecc13e3 commit bb4a741
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'setimmediate';
import './lib/TabFreezePrevention';
import './lib/patchGetUserMedia';
import './lib/patchOpenWindow';

import React from 'react';
import ReactDOM from 'react-dom';
Expand All @@ -21,7 +22,7 @@ const clientIdFromParams = pathParams.clientId || pathParams.appKey;
const clientSecretFromParams = pathParams.clientSecret || pathParams.appSecret;
const authProxy = pathParams.authProxy;
const enableDiscovery = !!pathParams.discovery;
const discoverAppServer = pathParams.discoverAppServer;

function getAppServer() {
if (
pathParams.appServer &&
Expand All @@ -38,9 +39,23 @@ const apiConfig = {
clientSecret: (clientIdFromParams ? clientSecretFromParams : defaultApiConfig.appSecret),
server: getAppServer(),
};

function getDiscoveryServer() {
const discoveryServer = pathParams.discoverAppServer || apiConfig.server;
if ([
'https://platform.ringcentral.com',
'https://platform.devtest.ringcentral.com',
'https://discovery.ringcentral.biz',
'https://discovery.ringcentral.com',
'https://platform.ringcentral.biz',
].indexOf(discoveryServer) > -1) {
return discoveryServer;
}
return defaultApiConfig.server;
}
if (enableDiscovery) {
apiConfig.enableDiscovery = enableDiscovery;
apiConfig.discoveryServer = discoverAppServer || apiConfig.server;
apiConfig.discoveryServer = getDiscoveryServer();
}
if (!authProxy && pathParams.appKey) {
console.warn('appKey is deprecated, please change to clientId. https://ringcentral.github.io/ringcentral-embeddable/docs/config/client-id/');
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Adapter/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import classnames from 'classnames';
import url from 'url';
import popWindow from '@ringcentral-integration/widgets/lib/popWindow';
import AdapterCore from '@ringcentral-integration/widgets/lib/AdapterCore';
import { isSafari } from '@ringcentral-integration/utils';

import popWindow from '../popWindow';
import parseUri from '../parseUri';
import messageTypes from './messageTypes';
import requestWithPostMessage from '../requestWithPostMessage';
Expand Down
15 changes: 15 additions & 0 deletions src/lib/patchOpenWindow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
try {
if (!window.__originalOpen) {
window.__originalOpen = window.open;
window.open = function(url, id, options) {
if (typeof url === 'string' && url.indexOf('javascript') > -1) {
throw new Error('Invalid open window uri');
}
return window.__originalOpen(url, id, options);
}
}
} catch (e) {
console.error(e);
}


35 changes: 35 additions & 0 deletions src/lib/popWindow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export function popWindow(url: string, id: string, w: number, h: number) {
if (url.indexOf('javascript') > 0) {
throw new Error('Invalid window open url');
}
// Fixes dual-screen position Most browsers Firefox
const dualScreenLeft =
window.screenLeft !== undefined
? window.screenLeft
: (window.screen as any).left;
const dualScreenTop =
window.screenTop !== undefined
? window.screenTop
: (window.screen as any).top;

const width = window.screen.width || window.outerWidth;
const height = window.screen.height || window.innerHeight;
const left = width / 2 - w / 2 + dualScreenLeft;
const top = height / 2 - h / 2 + dualScreenTop;

const newWindow = window.open(
url,
id,
`scrollbars=yes, width=${w}, height=${h}, top=${top}, left=${left}`,
);

// Puts focus on the newWindow
try {
newWindow?.focus();
} catch (error) {
/* ignore error */
}
return newWindow;
}

export default popWindow;

0 comments on commit bb4a741

Please sign in to comment.