Bläddra i källkod

fix(copyText): in iframe for chrome<85

master
Hristo Terezov 4 år sedan
förälder
incheckning
a2e2d31dfd

+ 5
- 2
react/features/base/buttons/CopyButton.js Visa fil

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

+ 9
- 12
react/features/base/premeeting/components/web/CopyMeetingUrl.js Visa fil

7
 import { Icon, IconCopy, IconCheck } from '../../../icons';
7
 import { Icon, IconCopy, IconCheck } from '../../../icons';
8
 import { connect } from '../../../redux';
8
 import { connect } from '../../../redux';
9
 import { copyText, getDecodedURI } from '../../../util';
9
 import { copyText, getDecodedURI } from '../../../util';
10
-import logger from '../../logger';
11
 
10
 
12
 type Props = {
11
 type Props = {
13
 
12
 
75
      *
74
      *
76
      * @returns {void}
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
         if (success) {
80
         if (success) {
82
             this._showLinkCopied();
81
             this._showLinkCopied();
152
      * @private
151
      * @private
153
      * @returns {void}
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 Visa fil

29
  * Returns true if the action succeeds.
29
  * Returns true if the action succeeds.
30
  *
30
  *
31
  * @param {string} textToCopy - Text to be copied.
31
  * @param {string} textToCopy - Text to be copied.
32
- * @returns {boolean}
32
+ * @returns {Promise<boolean>}
33
  */
33
  */
34
 export async function copyText(textToCopy: string) {
34
 export async function copyText(textToCopy: string) {
35
-    let result;
36
-
37
     try {
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 Visa fil

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

Laddar…
Avbryt
Spara