Selaa lähdekoodia

fix(copyText): in iframe for chrome<85

master
Hristo Terezov 4 vuotta sitten
vanhempi
commit
a2e2d31dfd

+ 5
- 2
react/features/base/buttons/CopyButton.js Näytä tiedosto

@@ -49,9 +49,12 @@ function CopyButton({ className, displayedText, textToCopy, textOnHover, textOnC
49 49
      *
50 50
      * @returns {void}
51 51
      */
52
-    function onClick() {
52
+    async function onClick() {
53 53
         setIsHovered(false);
54
-        if (copyText(textToCopy)) {
54
+
55
+        const isCopied = await copyText(textToCopy);
56
+
57
+        if (isCopied) {
55 58
             setIsClicked(true);
56 59
 
57 60
             setTimeout(() => {

+ 9
- 12
react/features/base/premeeting/components/web/CopyMeetingUrl.js Näytä tiedosto

@@ -7,7 +7,6 @@ import { translate } from '../../../i18n';
7 7
 import { Icon, IconCopy, IconCheck } from '../../../icons';
8 8
 import { connect } from '../../../redux';
9 9
 import { copyText, getDecodedURI } from '../../../util';
10
-import logger from '../../logger';
11 10
 
12 11
 type Props = {
13 12
 
@@ -75,8 +74,8 @@ class CopyMeetingUrl extends Component<Props, State> {
75 74
      *
76 75
      * @returns {void}
77 76
      */
78
-    _copyUrl() {
79
-        const success = copyText(this.props.url);
77
+    async _copyUrl() {
78
+        const success = await copyText(this.props.url);
80 79
 
81 80
         if (success) {
82 81
             this._showLinkCopied();
@@ -152,15 +151,13 @@ class CopyMeetingUrl extends Component<Props, State> {
152 151
      * @private
153 152
      * @returns {void}
154 153
      */
155
-    _copyUrlAutomatically() {
156
-        navigator.clipboard.writeText(this.props.url)
157
-            .then(() => {
158
-                this._showLinkCopied();
159
-                window.setTimeout(this._hideLinkCopied, COPY_TIMEOUT);
160
-            })
161
-            .catch(e => {
162
-                logger.error(e);
163
-            });
154
+    async _copyUrlAutomatically() {
155
+        const isCopied = await copyText(this.props.url);
156
+
157
+        if (isCopied) {
158
+            this._showLinkCopied();
159
+            window.setTimeout(this._hideLinkCopied, COPY_TIMEOUT);
160
+        }
164 161
     }
165 162
 
166 163
     /**

+ 26
- 8
react/features/base/util/helpers.js Näytä tiedosto

@@ -29,18 +29,36 @@ export function assignIfDefined(target: Object, source: Object) {
29 29
  * Returns true if the action succeeds.
30 30
  *
31 31
  * @param {string} textToCopy - Text to be copied.
32
- * @returns {boolean}
32
+ * @returns {Promise<boolean>}
33 33
  */
34 34
 export async function copyText(textToCopy: string) {
35
-    let result;
36
-
37 35
     try {
38
-        result = await navigator.clipboard.writeText(textToCopy);
39
-    } catch (err) {
40
-        result = false;
41
-    }
36
+        await navigator.clipboard.writeText(textToCopy);
37
+
38
+        return true;
39
+    } catch (clipboardAPIError) { // The Clipboard API is not supported.
40
+        let fakeTextArea = document.createElement('textarea');
41
+
42
+        // $FlowFixMe
43
+        fakeTextArea = document.body.appendChild(fakeTextArea);
44
+        fakeTextArea.value = textToCopy;
45
+        fakeTextArea.focus();
46
+        fakeTextArea.select();
47
+
48
+        let result;
42 49
 
43
-    return result;
50
+        try {
51
+            result = document.execCommand('copy');
52
+        } catch (error) {
53
+            result = false;
54
+        }
55
+
56
+        // $FlowFixMe
57
+        document.body.removeChild(fakeTextArea);
58
+
59
+
60
+        return result;
61
+    }
44 62
 }
45 63
 
46 64
 /**

+ 5
- 2
react/features/invite/components/add-people-dialog/web/LiveStreamSection.js Näytä tiedosto

@@ -34,9 +34,12 @@ function LiveStreamSection({ liveStreamViewURL, t }: Props) {
34 34
      *
35 35
      * @returns {void}
36 36
      */
37
-    function onClick() {
37
+    async function onClick() {
38 38
         setIsHovered(false);
39
-        if (copyText(liveStreamViewURL)) {
39
+
40
+        const isCopied = copyText(liveStreamViewURL);
41
+
42
+        if (isCopied) {
40 43
             setIsClicked(true);
41 44
 
42 45
             setTimeout(() => {

Loading…
Peruuta
Tallenna