Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(copyText) use a helper library

Saúl Ibarra Corretgé5c46b032513c
diff --git a/package-lock.json b/package-lock.json
index c50bebfb50..8dc835a545 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -5858,6 +5858,11 @@
"resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz",
"integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk="
},
+ "clipboard-copy": {
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/clipboard-copy/-/clipboard-copy-4.0.1.tgz",
+ "integrity": "sha512-wOlqdqziE/NNTUJsfSgXmBMIrYmfd5V0HCGsR8uAKHcg+h9NENWINcfRjtWGU77wDHC8B8ijV4hMTGYbrKovng=="
+ },
"cliui": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz",
diff --git a/package.json b/package.json
index 5a2b53ed68..ac25660637 100644
--- a/package.json
+++ b/package.json
@@ -41,6 +41,7 @@
"amplitude-js": "7.3.3",
"base64-js": "1.3.1",
"bc-css-flags": "3.0.0",
+ "clipboard-copy": "4.0.1",
"dropbox": "4.0.9",
"focus-visible": "5.1.0",
"i18n-iso-countries": "3.7.8",
diff --git a/react/features/base/util/helpers.js b/react/features/base/util/helpers.js
index 9ed6e56f8a..aedb88ef3c 100644
--- a/react/features/base/util/helpers.js
+++ b/react/features/base/util/helpers.js
@@ -1,5 +1,7 @@
// @flow
+import clipboardCopy from 'clipboard-copy';
+
/**
* A helper function that behaves similar to Object.assign, but only reassigns a
* property in target if it's defined in source.
@@ -33,31 +35,11 @@ export function assignIfDefined(target: Object, source: Object) {
*/
export async function copyText(textToCopy: string) {
try {
- await navigator.clipboard.writeText(textToCopy);
+ await clipboardCopy(textToCopy);
return true;
- } catch (clipboardAPIError) { // The Clipboard API is not supported.
- let fakeTextArea = document.createElement('textarea');
-
- // $FlowFixMe
- fakeTextArea = document.body.appendChild(fakeTextArea);
- fakeTextArea.value = textToCopy;
- fakeTextArea.focus();
- fakeTextArea.select();
-
- let result;
-
- try {
- result = document.execCommand('copy');
- } catch (error) {
- result = false;
- }
-
- // $FlowFixMe
- document.body.removeChild(fakeTextArea);
-
-
- return result;
+ } catch (e) {
+ return false;
}
}