From 5ea492c1b08c1da87b7222190ff69582e5c486dc Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 5 Mar 2018 10:41:44 -0300 Subject: [PATCH 01/16] hotfix for ios --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2882058f2f8..845b8b1d1d9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -147,6 +147,7 @@ jobs: name: Install NPM modules command: | rm -rf node_modules + npm install --save react-native@0.51 npm install # npm install react-native From 751013fd33daa129c7f2b8ac42e4b86c3faace32 Mon Sep 17 00:00:00 2001 From: Karan Bedi Date: Tue, 6 Mar 2018 01:33:58 +0530 Subject: [PATCH 02/16] [NEW] Add module react-native-audio --- android/app/build.gradle | 2 + android/app/src/main/AndroidManifest.xml | 1 + .../com/rocketchatrn/MainApplication.java | 2 + android/settings.gradle | 4 + ios/RocketChatRN.xcodeproj/project.pbxproj | 75 ++++++++++++++++++- ios/RocketChatRN/Info.plist | 2 + package.json | 1 + 7 files changed, 86 insertions(+), 1 deletion(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index e6c65008c3f..6cfb7cbac17 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -144,6 +144,8 @@ android { } dependencies { + compile project(':react-native-audio') + compile project(':react-native-audio') compile project(":reactnativekeyboardinput") compile project(':react-native-splash-screen') compile project(':react-native-video') diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 494507756a4..0137ae6669b 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -7,6 +7,7 @@ + diff --git a/android/app/src/main/java/com/rocketchatrn/MainApplication.java b/android/app/src/main/java/com/rocketchatrn/MainApplication.java index 986de10f374..051a8fdc722 100644 --- a/android/app/src/main/java/com/rocketchatrn/MainApplication.java +++ b/android/app/src/main/java/com/rocketchatrn/MainApplication.java @@ -17,6 +17,7 @@ import com.brentvatne.react.ReactVideoPackage; import com.remobile.toast.RCTToastPackage; import com.wix.reactnativekeyboardinput.KeyboardInputPackage; +import com.rnim.rn.audio.ReactNativeAudioPackage; import java.util.Arrays; import java.util.List; @@ -44,6 +45,7 @@ protected List getPackages() { new ReactVideoPackage(), new SplashScreenReactPackage(), new RCTToastPackage(), + new ReactNativeAudioPackage(), new KeyboardInputPackage(MainApplication.this), new RocketChatNativePackage() ); diff --git a/android/settings.gradle b/android/settings.gradle index 236de741bca..3385624bdba 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,4 +1,8 @@ rootProject.name = 'RocketChatRN' +include ':react-native-audio' +project(':react-native-audio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-audio/android') +include ':react-native-audio' +project(':react-native-audio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-audio/android') include ':reactnativekeyboardinput' project(':reactnativekeyboardinput').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-keyboard-input/lib/android') include ':react-native-splash-screen' diff --git a/ios/RocketChatRN.xcodeproj/project.pbxproj b/ios/RocketChatRN.xcodeproj/project.pbxproj index 58e3e6371cf..3b7d702e738 100644 --- a/ios/RocketChatRN.xcodeproj/project.pbxproj +++ b/ios/RocketChatRN.xcodeproj/project.pbxproj @@ -5,7 +5,6 @@ }; objectVersion = 46; objects = { - /* Begin PBXBuildFile section */ 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; }; 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; }; @@ -47,6 +46,7 @@ 5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */; }; 647660C6B6A340C7BD4D1099 /* EvilIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = A18EFC3B0CFE40E0918A8F0C /* EvilIcons.ttf */; }; 70A8D9B456894EFFAF027CAB /* FontAwesome.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 7A30DA4B2D474348824CD05B /* FontAwesome.ttf */; }; + 74815BBCB91147C08C8F7B3D /* libRNAudio.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1142E3442BA94B19BCF52814 /* libRNAudio.a */; }; 77C35F50C01C43668188886C /* libRNVectorIcons.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A0EEFAF8AB14F5B9E796CDD /* libRNVectorIcons.a */; }; 7A430E4F20238C46008F55BC /* libRCTCustomInputController.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A430E1E20238C02008F55BC /* libRCTCustomInputController.a */; }; 832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; }; @@ -334,6 +334,27 @@ remoteGlobalIDString = 58B5119B1A9E6C1200147676; remoteInfo = RCTText; }; + A9A6C934204DD556006B7D9D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = EBF21BDC1FC498900052F4D5; + remoteInfo = jsinspector; + }; + A9A6C936204DD556006B7D9D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = EBF21BFA1FC4989A0052F4D5; + remoteInfo = "jsinspector-tvOS"; + }; + A9A6C944204DD557006B7D9D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C21010507E5B4B37BA0E4C9D /* RNAudio.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 42F559BA1CFC90C400DC3F84; + remoteInfo = RNAudio; + }; B810DF90203B10490010C331 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 4019A5E1911B4C61944FBCEC /* SafariViewManager.xcodeproj */; @@ -431,6 +452,7 @@ 00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 00E356F21AD99517003FC87E /* RocketChatRNTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RocketChatRNTests.m; sourceTree = ""; }; 06BB44DD4855498082A744AD /* libz.tbd */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; + 1142E3442BA94B19BCF52814 /* libRNAudio.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNAudio.a; sourceTree = ""; }; 139105B61AF99BAD00B5F7CC /* RCTSettings.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTSettings.xcodeproj; path = "../node_modules/react-native/Libraries/Settings/RCTSettings.xcodeproj"; sourceTree = ""; }; 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTWebSocket.xcodeproj; path = "../node_modules/react-native/Libraries/WebSocket/RCTWebSocket.xcodeproj"; sourceTree = ""; }; 13B07F961A680F5B00A75B9A /* RocketChatRN.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RocketChatRN.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -474,6 +496,7 @@ B8971BAC202A091D0000D245 /* KeyboardTrackingView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = KeyboardTrackingView.xcodeproj; path = "../node_modules/react-native-keyboard-tracking-view/lib/KeyboardTrackingView.xcodeproj"; sourceTree = ""; }; B8C682611FD84CEF003A12C8 /* icomoon.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = icomoon.ttf; path = ../resources/fonts/icomoon.ttf; sourceTree = ""; }; BAAE4B947F5D44959F0A9D5A /* libRNZeroconf.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNZeroconf.a; sourceTree = ""; }; + C21010507E5B4B37BA0E4C9D /* RNAudio.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNAudio.xcodeproj; path = "../node_modules/react-native-audio/ios/RNAudio.xcodeproj"; sourceTree = ""; }; C23AEF1D9EBE4A38A1A6B97B /* RNSVG.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNSVG.xcodeproj; path = "../node_modules/react-native-svg/ios/RNSVG.xcodeproj"; sourceTree = ""; }; DA50CE47374C4C35BE6D9D58 /* libRNSVG.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNSVG.a; sourceTree = ""; }; DC6EE17B5550465E98C70FF0 /* Entypo.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Entypo.ttf; path = "../node_modules/react-native-vector-icons/Fonts/Entypo.ttf"; sourceTree = ""; }; @@ -520,6 +543,7 @@ 8ECBD927DDAC4987B98E102E /* libRCTVideo.a in Frameworks */, 0F026E58B8A6427D9A204D89 /* libSplashScreen.a in Frameworks */, 2C800DF680F8451599E80AF1 /* libSafariViewManager.a in Frameworks */, + 74815BBCB91147C08C8F7B3D /* libRNAudio.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -653,6 +677,8 @@ 3DAD3EAB1DF850E9000B6D8A /* libcxxreact.a */, 3DAD3EAD1DF850E9000B6D8A /* libjschelpers.a */, 3DAD3EAF1DF850E9000B6D8A /* libjschelpers.a */, + A9A6C935204DD556006B7D9D /* libjsinspector.a */, + A9A6C937204DD556006B7D9D /* libjsinspector-tvOS.a */, 607D610D1F325B7E00F639C4 /* libthird-party.a */, 607D610F1F325B7E00F639C4 /* libthird-party.a */, 607D61111F325B7E00F639C4 /* libdouble-conversion.a */, @@ -756,6 +782,7 @@ AD0379F2BCE84C968538CDAF /* RCTVideo.xcodeproj */, 30FCE1B6376C423E94C9FBB0 /* SplashScreen.xcodeproj */, 4019A5E1911B4C61944FBCEC /* SafariViewManager.xcodeproj */, + C21010507E5B4B37BA0E4C9D /* RNAudio.xcodeproj */, ); name = Libraries; sourceTree = ""; @@ -795,6 +822,14 @@ name = Products; sourceTree = ""; }; + A9A6C941204DD556006B7D9D /* Products */ = { + isa = PBXGroup; + children = ( + A9A6C945204DD557006B7D9D /* libRNAudio.a */, + ); + name = Products; + sourceTree = ""; + }; AF5E16F0398347E6A80C8CBE /* Resources */ = { isa = PBXGroup; children = ( @@ -850,6 +885,7 @@ 20CE3E407E0D4D9E8C9885F2 /* libRCTVideo.a */, B2607FA180F14E6584301101 /* libSplashScreen.a */, 1D3BB00B9ABF44EA9BD71318 /* libSafariViewManager.a */, + 1142E3442BA94B19BCF52814 /* libRNAudio.a */, ); name = "Recovered References"; sourceTree = ""; @@ -1075,6 +1111,10 @@ ProductGroup = 607D60ED1F325B7D00F639C4 /* Products */; ProjectRef = 5A8684E7C27E426C9206E980 /* RealmReact.xcodeproj */; }, + { + ProductGroup = A9A6C941204DD556006B7D9D /* Products */; + ProjectRef = C21010507E5B4B37BA0E4C9D /* RNAudio.xcodeproj */; + }, { ProductGroup = B8E79A881F3CCC6C005B464F /* Products */; ProjectRef = 4CD38E4891ED4601B7481448 /* RNFetchBlob.xcodeproj */; @@ -1367,6 +1407,27 @@ remoteRef = 832341B41AAA6A8300B99B32 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + A9A6C935204DD556006B7D9D /* libjsinspector.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libjsinspector.a; + remoteRef = A9A6C934204DD556006B7D9D /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + A9A6C937204DD556006B7D9D /* libjsinspector-tvOS.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = "libjsinspector-tvOS.a"; + remoteRef = A9A6C936204DD556006B7D9D /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + A9A6C945204DD557006B7D9D /* libRNAudio.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libRNAudio.a; + remoteRef = A9A6C944204DD557006B7D9D /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; B810DF91203B10490010C331 /* libSafariViewManager.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; @@ -1618,6 +1679,7 @@ "$(SRCROOT)/../node_modules/react-native-video/ios", "$(SRCROOT)/../node_modules/react-native-splash-screen/ios", "$(SRCROOT)/../node_modules/react-native-safari-view", + "$(SRCROOT)/../node_modules/react-native-audio/ios", ); INFOPLIST_FILE = RocketChatRNTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -1630,6 +1692,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1659,6 +1722,7 @@ "$(SRCROOT)/../node_modules/react-native-video/ios", "$(SRCROOT)/../node_modules/react-native-splash-screen/ios", "$(SRCROOT)/../node_modules/react-native-safari-view", + "$(SRCROOT)/../node_modules/react-native-audio/ios", ); INFOPLIST_FILE = RocketChatRNTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -1671,6 +1735,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1705,6 +1770,7 @@ "$(SRCROOT)/../node_modules/react-native-video/ios", "$(SRCROOT)/../node_modules/react-native-splash-screen/ios", "$(SRCROOT)/../node_modules/react-native-safari-view", + "$(SRCROOT)/../node_modules/react-native-audio/ios", ); INFOPLIST_FILE = RocketChatRN/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -1744,6 +1810,7 @@ "$(SRCROOT)/../node_modules/react-native-video/ios", "$(SRCROOT)/../node_modules/react-native-splash-screen/ios", "$(SRCROOT)/../node_modules/react-native-safari-view", + "$(SRCROOT)/../node_modules/react-native-audio/ios", ); INFOPLIST_FILE = RocketChatRN/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -1786,6 +1853,7 @@ "$(SRCROOT)/../node_modules/react-native-video/ios", "$(SRCROOT)/../node_modules/react-native-splash-screen/ios", "$(SRCROOT)/../node_modules/react-native-safari-view", + "$(SRCROOT)/../node_modules/react-native-audio/ios", ); INFOPLIST_FILE = "RocketChatRN-tvOS/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -1797,6 +1865,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1836,6 +1905,7 @@ "$(SRCROOT)/../node_modules/react-native-video/ios", "$(SRCROOT)/../node_modules/react-native-splash-screen/ios", "$(SRCROOT)/../node_modules/react-native-safari-view", + "$(SRCROOT)/../node_modules/react-native-audio/ios", ); INFOPLIST_FILE = "RocketChatRN-tvOS/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -1847,6 +1917,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1882,6 +1953,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.RocketChatRN-tvOSTests"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1913,6 +1985,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); PRODUCT_BUNDLE_IDENTIFIER = "com.facebook.REACT.RocketChatRN-tvOSTests"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/ios/RocketChatRN/Info.plist b/ios/RocketChatRN/Info.plist index e17929b79b0..0fca665fc9c 100644 --- a/ios/RocketChatRN/Info.plist +++ b/ios/RocketChatRN/Info.plist @@ -22,6 +22,8 @@ ???? CFBundleVersion 100 + NSMicrophoneUsageDescription + This app uses the microphone to record audio message. ITSAppUsesNonExemptEncryption LSRequiresIPhoneOS diff --git a/package.json b/package.json index 056227823c5..cd66732e2a1 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "react-native-action-button": "^2.8.3", "react-native-actionsheet": "^2.3.0", "react-native-animatable": "^1.2.4", + "react-native-audio": "^4.0.0", "react-native-easy-markdown": "git+https://github.com/diegolmello/react-native-easy-markdown.git", "react-native-fetch-blob": "^0.10.8", "react-native-image-picker": "^0.26.7", From 188006c22702ab6558d783ed3c8604ce1c69765c Mon Sep 17 00:00:00 2001 From: kb0304 Date: Tue, 6 Mar 2018 13:07:33 +0530 Subject: [PATCH 03/16] [FIX] Uncomment version in android gradle properties, commit package-lock --- android/gradle.properties | 2 +- package-lock.json | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/android/gradle.properties b/android/gradle.properties index 55422fd77de..d94d120206e 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -17,4 +17,4 @@ # org.gradle.parallel=true android.useDeprecatedNdk=true -# VERSIONCODE=999999999 +VERSIONCODE=999999999 diff --git a/package-lock.json b/package-lock.json index 82fa1c15e5d..8dbeb5339d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9073,11 +9073,6 @@ "jsdom": "11.6.2" } }, - "js-base64": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.4.3.tgz", - "integrity": "sha512-H7ErYLM34CvDMto3GbD6xD0JLUGYXR3QTcH6B/tr4Hi/QpSThnCsIp+Sy5FRTw3B0d6py4HcNkW7nO/wdtGWEw==" - }, "jest-environment-node": { "version": "22.3.0", "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-22.3.0.tgz", @@ -13461,6 +13456,11 @@ "prop-types": "15.6.0" } }, + "react-native-audio": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/react-native-audio/-/react-native-audio-4.0.0.tgz", + "integrity": "sha512-wJWiXgJk8vFfZPSP4wC9NaCquv2wYOb+K76oPytYxJlRGplKrtD9JY0bIkXp7jbIIDubj3yebb5f8xpYhirIpg==" + }, "react-native-compat": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/react-native-compat/-/react-native-compat-1.0.0.tgz", From 2a45056f0942a4011d334ea6de3a3ed7df770c83 Mon Sep 17 00:00:00 2001 From: kb0304 Date: Tue, 6 Mar 2018 15:32:06 +0530 Subject: [PATCH 04/16] [WIP] Audio message basic UI --- app/containers/MessageBox/index.js | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index d9811895b5d..1d814e8c378 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -139,6 +139,30 @@ export default class MessageBox extends React.PureComponent { onPress={() => this.submit(this.state.text)} />); } else { + if(!this.state.recording){ + icons.push( this.recordAudioMessage()} + />); + }else{ + icons.push( this.cancelAudioMessage()} + />); + icons.push( this.sendAudioMessage()} + />); + } icons.push( { + this.setState({ recording: true }); + } + + sendAudioMessage = () => { + this.setState({ + recording: false + }); + } + + cancelAudioMessage = () => { + this.setState({ + recording: false + }); + } + addFile = () => { const options = { maxHeight: 1960, From 657aa253b681e59af711c81fd0997d4f7b5d48bf Mon Sep 17 00:00:00 2001 From: kb0304 Date: Tue, 6 Mar 2018 18:59:14 +0530 Subject: [PATCH 05/16] [NEW] Record audio message --- app/containers/MessageBox/index.js | 71 +++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 5 deletions(-) diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index 1d814e8c378..91fe6328d41 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -1,6 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { View, TextInput, SafeAreaView, FlatList, Text, TouchableOpacity } from 'react-native'; +import { View, TextInput, SafeAreaView, FlatList, + Text, TouchableOpacity, Platform, PermissionsAndroid } from 'react-native'; import Icon from 'react-native-vector-icons/MaterialIcons'; import ImagePicker from 'react-native-image-picker'; import { connect } from 'react-redux'; @@ -16,6 +17,8 @@ import Avatar from '../Avatar'; import CustomEmoji from '../EmojiPicker/CustomEmoji'; import { emojis } from '../../emojis'; import './EmojiKeyboard'; +import { AudioRecorder, AudioUtils } from 'react-native-audio'; + const MENTIONS_TRACKING_TYPE_USERS = '@'; const MENTIONS_TRACKING_TYPE_EMOJIS = ':'; @@ -57,7 +60,9 @@ export default class MessageBox extends React.PureComponent { mentions: [], showMentionsContainer: false, showEmojiKeyboard: false, - trackingType: '' + trackingType: '', + currentTime: 0.0, + recording: false, }; this.users = []; this.rooms = []; @@ -160,7 +165,7 @@ export default class MessageBox extends React.PureComponent { name='check' accessibilityLabel='Finish recording' accessibilityTraits='button' - onPress={() => this.sendAudioMessage()} + onPress={() => this.finishAudioMessage()} />); } icons.push( { + console.log('Permission result:', result); + return (result === true || result === PermissionsAndroid.RESULTS.GRANTED); + }); + } + + _finishRecording(didSucceed, filePath) { + this.setState({ finished: didSucceed }); + console.log(`Finished recording of duration ${this.state.currentTime} seconds at path: ${filePath}`); + } + + recordAudioMessage = () => { - this.setState({ recording: true }); + this._checkAudioPermission().then( (hasPermission) => { + this.setState({ + recording: true, + audioPath: AudioUtils.DocumentDirectoryPath + '/' + Date.now() + '.aac', + hasPermission: hasPermission + }); + AudioRecorder.prepareRecordingAtPath(this.state.audioPath, { + SampleRate: 22050, + Channels: 1, + AudioQuality: "Low", + AudioEncoding: "aac" + }); + AudioRecorder.onProgress = (data) => { + this.setState({currentTime: Math.floor(data.currentTime)}); + } + AudioRecorder.onFinished = (data) => { + if (Platform.OS === 'ios') { + this._finishRecording(data.status === "OK", data.audioFileURL); + } + }; + AudioRecorder.startRecording(); + }); } - sendAudioMessage = () => { + async finishAudioMessage() { this.setState({ recording: false }); + try { + const filePath = await AudioRecorder.stopRecording(); + if (Platform.OS === 'android') { + this._finishRecording(true, filePath); + } + } catch(err){ + console.error(err); + } } cancelAudioMessage = () => { From e4ce3ef36d531ec36fc1c3a9e971b062a987076a Mon Sep 17 00:00:00 2001 From: kb0304 Date: Wed, 7 Mar 2018 01:10:14 +0530 Subject: [PATCH 06/16] [NEW] [WIP] Audio Message - fileMessage itegration --- app/containers/MessageBox/index.js | 60 ++++++++++++++++++++++++++---- app/containers/message/Audio.js | 2 +- app/lib/rocketchat.js | 17 +++++++-- 3 files changed, 67 insertions(+), 12 deletions(-) diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index 91fe6328d41..60ba6218a5b 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -63,6 +63,7 @@ export default class MessageBox extends React.PureComponent { trackingType: '', currentTime: 0.0, recording: false, + recordingCanceled: false }; this.users = []; this.rooms = []; @@ -160,6 +161,9 @@ export default class MessageBox extends React.PureComponent { accessibilityTraits='button' onPress={() => this.cancelAudioMessage()} />); + icons.push( + {this.state.currentTime} + ); icons.push( { - console.log('Permission result:', result); return (result === true || result === PermissionsAndroid.RESULTS.GRANTED); }); } @@ -204,52 +207,93 @@ export default class MessageBox extends React.PureComponent { _finishRecording(didSucceed, filePath) { this.setState({ finished: didSucceed }); console.log(`Finished recording of duration ${this.state.currentTime} seconds at path: ${filePath}`); + + const path = filePath.startsWith('file://') ? filePath.split('file://')[1] : filePath; + const fileInfo = { + type: 'audio/aac', + store: 'Uploads', + path: path + }; + + try{ + RocketChat.sendFileMessage(this.props.rid, fileInfo);//response.data); + }catch(e){ + console.error(e); + } } recordAudioMessage = () => { this._checkAudioPermission().then( (hasPermission) => { + if (!hasPermission) { + // permission denied + return; + } + this.setState({ - recording: true, - audioPath: AudioUtils.DocumentDirectoryPath + '/' + Date.now() + '.aac', - hasPermission: hasPermission + recordingCanceled: false }); - AudioRecorder.prepareRecordingAtPath(this.state.audioPath, { + + const audioPath = AudioUtils.CachesDirectoryPath + '/' + Date.now() + '.aac'; + + AudioRecorder.prepareRecordingAtPath(audioPath, { SampleRate: 22050, Channels: 1, AudioQuality: "Low", AudioEncoding: "aac" }); + AudioRecorder.onProgress = (data) => { - this.setState({currentTime: Math.floor(data.currentTime)}); + this.setState({ + currentTime: Math.floor(data.currentTime) + }); + } + AudioRecorder.onFinished = (data) => { - if (Platform.OS === 'ios') { + if (!this.state.recordingCanceled && Platform.OS === 'ios') { this._finishRecording(data.status === "OK", data.audioFileURL); } + }; + AudioRecorder.startRecording(); + + this.setState({ + recording: true, + }); + }); + } async finishAudioMessage() { this.setState({ recording: false }); + try { const filePath = await AudioRecorder.stopRecording(); if (Platform.OS === 'android') { this._finishRecording(true, filePath); } + } catch(err){ console.error(err); } + } - cancelAudioMessage = () => { + async cancelAudioMessage() { + this.setState({ + recordingCanceled: true + }); + + await AudioRecorder.stopRecording(); this.setState({ recording: false }); + } addFile = () => { diff --git a/app/containers/message/Audio.js b/app/containers/message/Audio.js index df17fa11c9e..a4fa67ed055 100644 --- a/app/containers/message/Audio.js +++ b/app/containers/message/Audio.js @@ -83,7 +83,7 @@ export default class Audio extends React.PureComponent { } onLoad(data) { - this.setState({ duration: data.duration }); + this.setState({ duration: data.duration>0?data.duration:0 }); } onProgress(data) { diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 8f97fef7387..f81ee1e9b7c 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -449,13 +449,23 @@ const RocketChat = { } */ _sendFileMessage(rid, data, msg = {}) { - return call('sendFileMessage', rid, null, data, msg); + try { + return call('sendFileMessage', rid, null, data, msg); + }catch(e){ + console.error(e); + } }, async sendFileMessage(rid, fileInfo, data) { - const placeholder = RocketChat.getMessage(rid, 'Sending an image'); + const placeholder = RocketChat.getMessage(rid, 'Sending a file'); try { - const result = await RocketChat._ufsCreate({ ...fileInfo, rid }); + if(!data){ + data = await RNFetchBlob.wrap(fileInfo.path); + let fileStat = await RNFetchBlob.fs.stat(fileInfo.path); + fileInfo.size = fileStat.size; + fileInfo.name = fileStat.filename; + } + const result = await RocketChat._ufsCreate({ ...fileInfo, rid }); await RNFetchBlob.fetch('POST', result.url, { 'Content-Type': 'application/octet-stream' }, data); @@ -470,6 +480,7 @@ const RocketChat = { url: completeRresult.path }); } catch (e) { + console.error(e); return e; } finally { database.write(() => { From 02722aa7fc07f9016d64c2eedf9309367b74da6f Mon Sep 17 00:00:00 2001 From: kb0304 Date: Wed, 7 Mar 2018 01:38:54 +0530 Subject: [PATCH 07/16] [FIX] Delete single object in Realm --- app/lib/realm.js | 3 +++ app/lib/rocketchat.js | 21 ++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/lib/realm.js b/app/lib/realm.js index ea1338bdaf7..7c4ef61f25c 100644 --- a/app/lib/realm.js +++ b/app/lib/realm.js @@ -258,6 +258,9 @@ class DB { deleteAll(...args) { return this.database.write(() => this.database.deleteAll(...args)); } + delete(...args) { + return this.database.delete(...args); + } write(...args) { return this.database.write(...args); } diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index f81ee1e9b7c..ec9deedd2da 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -449,11 +449,7 @@ const RocketChat = { } */ _sendFileMessage(rid, data, msg = {}) { - try { - return call('sendFileMessage', rid, null, data, msg); - }catch(e){ - console.error(e); - } + return call('sendFileMessage', rid, null, data, msg); }, async sendFileMessage(rid, fileInfo, data) { const placeholder = RocketChat.getMessage(rid, 'Sending a file'); @@ -472,7 +468,7 @@ const RocketChat = { const completeRresult = await RocketChat._ufsComplete(result.fileId, fileInfo.store, result.token); - return await RocketChat._sendFileMessage(completeRresult.rid, { + await RocketChat._sendFileMessage(completeRresult.rid, { _id: completeRresult._id, type: completeRresult.type, size: completeRresult.size, @@ -481,12 +477,15 @@ const RocketChat = { }); } catch (e) { console.error(e); - return e; } finally { - database.write(() => { - const msg = database.objects('messages').filtered('_id = $0', placeholder._id); - database.delete(msg); - }); + try{ + database.write(() => { + const msg = database.objects('messages').filtered('_id = $0', placeholder._id); + database.delete(msg); + }); + }catch(e){ + console.error(e); + } } }, async getRooms() { From 2c30e4a6f5870f9a0060f9c6088b7893f1b1ee71 Mon Sep 17 00:00:00 2001 From: kb0304 Date: Wed, 7 Mar 2018 02:01:11 +0530 Subject: [PATCH 08/16] [FIX] Audio message timer formatting --- app/containers/MessageBox/index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index 60ba6218a5b..8d56432bc3f 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -61,7 +61,7 @@ export default class MessageBox extends React.PureComponent { showMentionsContainer: false, showEmojiKeyboard: false, trackingType: '', - currentTime: 0.0, + currentTime: '00:00', recording: false, recordingCanceled: false }; @@ -161,7 +161,7 @@ export default class MessageBox extends React.PureComponent { accessibilityTraits='button' onPress={() => this.cancelAudioMessage()} />); - icons.push( + icons.push( {this.state.currentTime} ); icons.push( { this.setState({ - currentTime: Math.floor(data.currentTime) + currentTime: this._formatTime(Math.floor(data.currentTime)) }); } From 89a1007bece1e6979408214f33a4852c10d7dc96 Mon Sep 17 00:00:00 2001 From: kb0304 Date: Wed, 7 Mar 2018 02:24:01 +0530 Subject: [PATCH 09/16] [FIX] Remove duplicate dependency entry --- android/app/build.gradle | 1 - android/settings.gradle | 2 -- app/lib/rocketchat.js | 4 ++-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 6cfb7cbac17..fc2f40982e9 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -144,7 +144,6 @@ android { } dependencies { - compile project(':react-native-audio') compile project(':react-native-audio') compile project(":reactnativekeyboardinput") compile project(':react-native-splash-screen') diff --git a/android/settings.gradle b/android/settings.gradle index 3385624bdba..5c628bbf4b5 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,8 +1,6 @@ rootProject.name = 'RocketChatRN' include ':react-native-audio' project(':react-native-audio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-audio/android') -include ':react-native-audio' -project(':react-native-audio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-audio/android') include ':reactnativekeyboardinput' project(':reactnativekeyboardinput').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-keyboard-input/lib/android') include ':react-native-splash-screen' diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index ec9deedd2da..60299809f23 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -468,7 +468,7 @@ const RocketChat = { const completeRresult = await RocketChat._ufsComplete(result.fileId, fileInfo.store, result.token); - await RocketChat._sendFileMessage(completeRresult.rid, { + return await RocketChat._sendFileMessage(completeRresult.rid, { _id: completeRresult._id, type: completeRresult.type, size: completeRresult.size, @@ -476,7 +476,7 @@ const RocketChat = { url: completeRresult.path }); } catch (e) { - console.error(e); + return e; } finally { try{ database.write(() => { From c0b2417d265339b41f57da42cead51f0af4ea407 Mon Sep 17 00:00:00 2001 From: kb0304 Date: Wed, 7 Mar 2018 03:45:56 +0530 Subject: [PATCH 10/16] [FIX] Fix lint --- app/containers/MessageBox/index.js | 96 ++++++++++++++---------------- app/containers/message/Audio.js | 2 +- app/lib/rocketchat.js | 8 +-- 3 files changed, 49 insertions(+), 57 deletions(-) diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index 8d56432bc3f..d65cde70592 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -1,12 +1,12 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { View, TextInput, SafeAreaView, FlatList, - Text, TouchableOpacity, Platform, PermissionsAndroid } from 'react-native'; +import { View, TextInput, SafeAreaView, FlatList, Text, TouchableOpacity, Platform, PermissionsAndroid } from 'react-native'; import Icon from 'react-native-vector-icons/MaterialIcons'; import ImagePicker from 'react-native-image-picker'; import { connect } from 'react-redux'; import { emojify } from 'react-emojione'; import { KeyboardAccessoryView } from 'react-native-keyboard-input'; +import { AudioRecorder, AudioUtils } from 'react-native-audio'; import { userTyping, layoutAnimation } from '../../actions/room'; import RocketChat from '../../lib/rocketchat'; import { editRequest, editCancel, clearInput } from '../../actions/messages'; @@ -17,7 +17,6 @@ import Avatar from '../Avatar'; import CustomEmoji from '../EmojiPicker/CustomEmoji'; import { emojis } from '../../emojis'; import './EmojiKeyboard'; -import { AudioRecorder, AudioUtils } from 'react-native-audio'; const MENTIONS_TRACKING_TYPE_USERS = '@'; @@ -145,32 +144,30 @@ export default class MessageBox extends React.PureComponent { onPress={() => this.submit(this.state.text)} />); } else { - if(!this.state.recording){ + if (!this.state.recording) { icons.push( this.recordAudioMessage()} />); - }else{ + } else { icons.push( this.cancelAudioMessage()} - />); - icons.push( - {this.state.currentTime} - ); + style={[styles.actionButtons, { color: 'red' }]} + name='clear' + accessibilityLabel='Cancel recording' + accessibilityTraits='button' + onPress={() => this.cancelAudioMessage()} + />); + icons.push({this.state.currentTime}); icons.push( this.finishAudioMessage()} - />); + style={[styles.actionButtons, { color: 'green' }]} + name='check' + accessibilityLabel='Finish recording' + accessibilityTraits='button' + onPress={() => this.finishAudioMessage()} + />); } icons.push( { - return (result === true || result === PermissionsAndroid.RESULTS.GRANTED); + result = (result === true || result === PermissionsAndroid.RESULTS.GRANTED); + return result; }); } _finishRecording(didSucceed, filePath) { - this.setState({ finished: didSucceed }); - console.log(`Finished recording of duration ${this.state.currentTime} seconds at path: ${filePath}`); - + console.log(`Finished recording of duration ${ this.state.currentTime } seconds at path: ${ filePath }`); + const path = filePath.startsWith('file://') ? filePath.split('file://')[1] : filePath; const fileInfo = { type: 'audio/aac', store: 'Uploads', - path: path + path }; - try{ - RocketChat.sendFileMessage(this.props.rid, fileInfo);//response.data); - }catch(e){ + try { + RocketChat.sendFileMessage(this.props.rid, fileInfo); + } catch (e) { console.error(e); } } recordAudioMessage = () => { - this._checkAudioPermission().then( (hasPermission) => { + this._checkAudioPermission().then((hasPermission) => { if (!hasPermission) { // permission denied return; @@ -242,37 +243,31 @@ export default class MessageBox extends React.PureComponent { recordingCanceled: false }); - const audioPath = AudioUtils.CachesDirectoryPath + '/' + Date.now() + '.aac'; + const audioPath = `${ AudioUtils.CachesDirectoryPath }/${ Date.now() }.aac`; AudioRecorder.prepareRecordingAtPath(audioPath, { SampleRate: 22050, Channels: 1, - AudioQuality: "Low", - AudioEncoding: "aac" + AudioQuality: 'Low', + AudioEncoding: 'aac' }); AudioRecorder.onProgress = (data) => { - this.setState({ - currentTime: this._formatTime(Math.floor(data.currentTime)) - }); - - } + this._formatTime(data.currentTime); + }; AudioRecorder.onFinished = (data) => { if (!this.state.recordingCanceled && Platform.OS === 'ios') { - this._finishRecording(data.status === "OK", data.audioFileURL); + this._finishRecording(data.status === 'OK', data.audioFileURL); } - }; AudioRecorder.startRecording(); this.setState({ - recording: true, + recording: true }); - }); - } async finishAudioMessage() { @@ -285,11 +280,9 @@ export default class MessageBox extends React.PureComponent { if (Platform.OS === 'android') { this._finishRecording(true, filePath); } - - } catch(err){ + } catch (err) { console.error(err); } - } async cancelAudioMessage() { @@ -301,7 +294,6 @@ export default class MessageBox extends React.PureComponent { this.setState({ recording: false }); - } addFile = () => { diff --git a/app/containers/message/Audio.js b/app/containers/message/Audio.js index a4fa67ed055..d9db162a2e7 100644 --- a/app/containers/message/Audio.js +++ b/app/containers/message/Audio.js @@ -83,7 +83,7 @@ export default class Audio extends React.PureComponent { } onLoad(data) { - this.setState({ duration: data.duration>0?data.duration:0 }); + this.setState({ duration: data.duration > 0 ? data.duration : 0 }); } onProgress(data) { diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 60299809f23..3b2f2c0f484 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -454,9 +454,9 @@ const RocketChat = { async sendFileMessage(rid, fileInfo, data) { const placeholder = RocketChat.getMessage(rid, 'Sending a file'); try { - if(!data){ + if (!data) { data = await RNFetchBlob.wrap(fileInfo.path); - let fileStat = await RNFetchBlob.fs.stat(fileInfo.path); + const fileStat = await RNFetchBlob.fs.stat(fileInfo.path); fileInfo.size = fileStat.size; fileInfo.name = fileStat.filename; } @@ -478,12 +478,12 @@ const RocketChat = { } catch (e) { return e; } finally { - try{ + try { database.write(() => { const msg = database.objects('messages').filtered('_id = $0', placeholder._id); database.delete(msg); }); - }catch(e){ + } catch (e) { console.error(e); } } From b3e45a36241459c79582218948ba6b87822af456 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Tue, 6 Mar 2018 20:04:40 -0300 Subject: [PATCH 11/16] improve audio code --- app/containers/MessageBox/Recording.js | 128 ++++++++++++++++ app/containers/MessageBox/index.js | 204 +++++-------------------- app/containers/message/Audio.js | 2 +- app/lib/rocketchat.js | 8 +- package-lock.json | 6 +- 5 files changed, 177 insertions(+), 171 deletions(-) create mode 100644 app/containers/MessageBox/Recording.js diff --git a/app/containers/MessageBox/Recording.js b/app/containers/MessageBox/Recording.js new file mode 100644 index 00000000000..fafe4a21fca --- /dev/null +++ b/app/containers/MessageBox/Recording.js @@ -0,0 +1,128 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { View, SafeAreaView, Platform, PermissionsAndroid, Text } from 'react-native'; +import { AudioRecorder, AudioUtils } from 'react-native-audio'; +import Icon from 'react-native-vector-icons/MaterialIcons'; +import styles from './styles'; + +export const _formatTime = function(seconds) { + let minutes = Math.floor(seconds / 60); + seconds %= 60; + if (minutes < 10) { minutes = `0${ minutes }`; } + if (seconds < 10) { seconds = `0${ seconds }`; } + return `${ minutes }:${ seconds }`; +}; + + +export default class extends React.PureComponent { + static propTypes = { + onFinish: PropTypes.func.isRequired + } + + static async permission() { + if (Platform.OS !== 'android') { + return true; + } + + const rationale = { + title: 'Microphone Permission', + message: 'Rocket Chat needs access to your microphone so you can send audio message.' + }; + + const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.RECORD_AUDIO, rationale); + return result === true || result === PermissionsAndroid.RESULTS.GRANTED; + } + + constructor() { + super(); + + + this.state = { + currentTime: '00:00', + recordingCanceled: false + }; + } + + componentDidMount() { + const audioPath = `${ AudioUtils.CachesDirectoryPath }/${ Date.now() }.aac`; + + AudioRecorder.prepareRecordingAtPath(audioPath, { + SampleRate: 22050, + Channels: 1, + AudioQuality: 'Low', + AudioEncoding: 'aac' + }); + + AudioRecorder.onProgress = (data) => { + this.setState({ + currentTime: _formatTime(Math.floor(data.currentTime)) + }); + }; + // + AudioRecorder.onFinished = (data) => { + if (!this.state.recordingCanceled && Platform.OS === 'ios') { + this._finishRecording(data.status === 'OK', data.audioFileURL); + } + }; + AudioRecorder.startRecording(); + } + + _finishRecording(didSucceed, filePath) { + if (!didSucceed) { + return this.props.onFinish && this.props.onFinish(didSucceed); + } + + const path = filePath.startsWith('file://') ? filePath.split('file://')[1] : filePath; + const fileInfo = { + type: 'audio/aac', + store: 'Uploads', + path + }; + return this.props.onFinish && this.props.onFinish(fileInfo); + } + + finishAudioMessage = async() => { + try { + const filePath = await AudioRecorder.stopRecording(); + if (Platform.OS === 'android') { + this._finishRecording(true, filePath); + } + } catch (err) { + this._finishRecording(false); + console.error(err); + } + } + + cancelAudioMessage = async() => { + await AudioRecorder.stopRecording(); + return this._finishRecording(false); + } + + render() { + return ( + + + + {this.state.currentTime} + + + ); + } +} diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index bf137ea3ee0..ec2bfcf143d 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -1,7 +1,9 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { View, TextInput, SafeAreaView, FlatList, - Text, TouchableOpacity, Platform, PermissionsAndroid } from 'react-native'; +import { + View, TextInput, SafeAreaView, FlatList, + Text, TouchableOpacity +} from 'react-native'; import Icon from 'react-native-vector-icons/MaterialIcons'; import ImagePicker from 'react-native-image-picker'; import { connect } from 'react-redux'; @@ -16,8 +18,8 @@ import database from '../../lib/realm'; import Avatar from '../Avatar'; import CustomEmoji from '../EmojiPicker/CustomEmoji'; import { emojis } from '../../emojis'; +import Recording from './Recording'; import './EmojiKeyboard'; -import { AudioRecorder, AudioUtils } from 'react-native-audio'; const MENTIONS_TRACKING_TYPE_USERS = '@'; @@ -60,10 +62,7 @@ export default class MessageBox extends React.PureComponent { mentions: [], showMentionsContainer: false, showEmojiKeyboard: false, - trackingType: '', - currentTime: '00:00', - recording: false, - recordingCanceled: false + recording: false }; this.users = []; this.rooms = []; @@ -144,166 +143,26 @@ export default class MessageBox extends React.PureComponent { accessibilityTraits='button' onPress={() => this.submit(this.state.text)} />); - } else { - if(!this.state.recording){ - icons.push( this.recordAudioMessage()} - />); - }else{ - icons.push( this.cancelAudioMessage()} - />); - icons.push( - {this.state.currentTime} - ); - icons.push( this.finishAudioMessage()} - />); - } - icons.push( this.addFile()} - />); + return icons; } + icons.push( this.recordAudioMessage()} + />); + icons.push( this.addFile()} + />); return icons; } - _formatTime(seconds) { - let minutes = Math.floor(seconds/60); - seconds = seconds % 60; - if (minutes < 10) { minutes = `0${ minutes }`; } - if (seconds < 10) { seconds = `0${ seconds }`; } - return `${ minutes }:${ seconds }`; - } - - _checkAudioPermission() { - if (this.state.hasPermission) { - return Promise.resolve(true); - } - - if (Platform.OS !== 'android') { - return Promise.resolve(true); - } - - const rationale = { - 'title': 'Microphone Permission', - 'message': 'Rocket Chat needs access to your microphone so you can send audio message.' - }; - - return PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.RECORD_AUDIO, rationale) - .then((result) => { - return (result === true || result === PermissionsAndroid.RESULTS.GRANTED); - }); - } - - _finishRecording(didSucceed, filePath) { - this.setState({ finished: didSucceed }); - console.log(`Finished recording of duration ${this.state.currentTime} seconds at path: ${filePath}`); - - const path = filePath.startsWith('file://') ? filePath.split('file://')[1] : filePath; - const fileInfo = { - type: 'audio/aac', - store: 'Uploads', - path: path - }; - - try{ - RocketChat.sendFileMessage(this.props.rid, fileInfo);//response.data); - }catch(e){ - console.error(e); - } - } - - - recordAudioMessage = () => { - this._checkAudioPermission().then( (hasPermission) => { - if (!hasPermission) { - // permission denied - return; - } - - this.setState({ - recordingCanceled: false - }); - - const audioPath = AudioUtils.CachesDirectoryPath + '/' + Date.now() + '.aac'; - - AudioRecorder.prepareRecordingAtPath(audioPath, { - SampleRate: 22050, - Channels: 1, - AudioQuality: "Low", - AudioEncoding: "aac" - }); - - AudioRecorder.onProgress = (data) => { - this.setState({ - currentTime: this._formatTime(Math.floor(data.currentTime)) - }); - - } - - AudioRecorder.onFinished = (data) => { - if (!this.state.recordingCanceled && Platform.OS === 'ios') { - this._finishRecording(data.status === "OK", data.audioFileURL); - } - - }; - - AudioRecorder.startRecording(); - - this.setState({ - recording: true, - }); - - }); - - } - - async finishAudioMessage() { - this.setState({ - recording: false - }); - - try { - const filePath = await AudioRecorder.stopRecording(); - if (Platform.OS === 'android') { - this._finishRecording(true, filePath); - } - - } catch(err){ - console.error(err); - } - - } - - async cancelAudioMessage() { - this.setState({ - recordingCanceled: true - }); - - await AudioRecorder.stopRecording(); - this.setState({ - recording: false - }); - - } - addFile = () => { const options = { maxHeight: 1960, @@ -341,9 +200,25 @@ export default class MessageBox extends React.PureComponent { showEmojiKeyboard: true }); } + + async recordAudioMessage() { + const recording = await Recording.permission(); + this.setState({ recording }); + } + + finishAudioMessage = async(fileInfo) => { + if (fileInfo) { + RocketChat.sendFileMessage(this.props.rid, fileInfo); + } + this.setState({ + recording: false + }); + } + closeEmoji() { this.setState({ showEmojiKeyboard: false }); } + submit(message) { this.setState({ text: '' }); this.closeEmoji(); @@ -599,6 +474,9 @@ export default class MessageBox extends React.PureComponent { ); renderContent() { + if (this.state.recording) { + return (); + } return ( [ this.renderMentions(), diff --git a/app/containers/message/Audio.js b/app/containers/message/Audio.js index a4fa67ed055..d9db162a2e7 100644 --- a/app/containers/message/Audio.js +++ b/app/containers/message/Audio.js @@ -83,7 +83,7 @@ export default class Audio extends React.PureComponent { } onLoad(data) { - this.setState({ duration: data.duration>0?data.duration:0 }); + this.setState({ duration: data.duration > 0 ? data.duration : 0 }); } onProgress(data) { diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index c8cb104d3cc..9d8890f8b3a 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -521,9 +521,9 @@ const RocketChat = { async sendFileMessage(rid, fileInfo, data) { const placeholder = RocketChat.getMessage(rid, 'Sending a file'); try { - if(!data){ + if (!data) { data = await RNFetchBlob.wrap(fileInfo.path); - let fileStat = await RNFetchBlob.fs.stat(fileInfo.path); + const fileStat = await RNFetchBlob.fs.stat(fileInfo.path); fileInfo.size = fileStat.size; fileInfo.name = fileStat.filename; } @@ -545,12 +545,12 @@ const RocketChat = { } catch (e) { return e; } finally { - try{ + try { database.write(() => { const msg = database.objects('messages').filtered('_id = $0', placeholder._id); database.delete(msg); }); - }catch(e){ + } catch (e) { console.error(e); } } diff --git a/package-lock.json b/package-lock.json index 504708167c0..20ddb63e9ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13880,9 +13880,9 @@ } }, "react-navigation": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/react-navigation/-/react-navigation-1.2.1.tgz", - "integrity": "sha512-3TblYWMqu8nvihXHP5x0nxktLuAz1uLiGZaAX3YobX8aGIWxPdSrPS9PGAoSkSalMG3BtGEwUKYqH2RSY1pi3A==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/react-navigation/-/react-navigation-1.4.0.tgz", + "integrity": "sha512-jm9dYLARRq7T7AQ4MKNsl+ZAFnHwl+UIl7be4grBnPycJJrjXVmpng/GqTjeRfNHjzKhXO/mXWKuAoOW1SiO4A==", "requires": { "clamp": "1.0.1", "hoist-non-react-statics": "2.5.0", From 73fb94e79c4f3ac0467bf628a01cf84d7c10d974 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Tue, 6 Mar 2018 20:16:53 -0300 Subject: [PATCH 12/16] fix lint --- app/containers/MessageBox/Recording.js | 2 +- app/containers/MessageBox/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/containers/MessageBox/Recording.js b/app/containers/MessageBox/Recording.js index fafe4a21fca..4d32c860241 100644 --- a/app/containers/MessageBox/Recording.js +++ b/app/containers/MessageBox/Recording.js @@ -104,7 +104,7 @@ export default class extends React.PureComponent { key='messagebox' style={styles.textBox} > - + Date: Tue, 6 Mar 2018 20:32:26 -0300 Subject: [PATCH 13/16] removed version code --- android/gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/gradle.properties b/android/gradle.properties index d94d120206e..55422fd77de 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -17,4 +17,4 @@ # org.gradle.parallel=true android.useDeprecatedNdk=true -VERSIONCODE=999999999 +# VERSIONCODE=999999999 From d5abd537aa718b97f816af5b7ae7b8d774e883e3 Mon Sep 17 00:00:00 2001 From: kb0304 Date: Wed, 7 Mar 2018 05:16:59 +0530 Subject: [PATCH 14/16] [FIX] Cancel recording state fix --- app/containers/MessageBox/Recording.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/containers/MessageBox/Recording.js b/app/containers/MessageBox/Recording.js index fafe4a21fca..214ca69d314 100644 --- a/app/containers/MessageBox/Recording.js +++ b/app/containers/MessageBox/Recording.js @@ -94,6 +94,7 @@ export default class extends React.PureComponent { } cancelAudioMessage = async() => { + this.setState({ recordingCanceled: true }); await AudioRecorder.stopRecording(); return this._finishRecording(false); } From 1b9893a466674d1c86b5f8c114d3aa2d4b30e0f4 Mon Sep 17 00:00:00 2001 From: kb0304 Date: Wed, 7 Mar 2018 05:37:43 +0530 Subject: [PATCH 15/16] Fix rerender due to recordingCanceled --- app/containers/MessageBox/Recording.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/containers/MessageBox/Recording.js b/app/containers/MessageBox/Recording.js index 022a4babc7d..b510a8fac50 100644 --- a/app/containers/MessageBox/Recording.js +++ b/app/containers/MessageBox/Recording.js @@ -13,7 +13,6 @@ export const _formatTime = function(seconds) { return `${ minutes }:${ seconds }`; }; - export default class extends React.PureComponent { static propTypes = { onFinish: PropTypes.func.isRequired @@ -36,10 +35,9 @@ export default class extends React.PureComponent { constructor() { super(); - + this.recordingCanceled = false; this.state = { - currentTime: '00:00', - recordingCanceled: false + currentTime: '00:00' }; } @@ -60,13 +58,15 @@ export default class extends React.PureComponent { }; // AudioRecorder.onFinished = (data) => { - if (!this.state.recordingCanceled && Platform.OS === 'ios') { + if (!this.recordingCanceled && Platform.OS === 'ios') { this._finishRecording(data.status === 'OK', data.audioFileURL); } }; AudioRecorder.startRecording(); } + recordingCanceled; + _finishRecording(didSucceed, filePath) { if (!didSucceed) { return this.props.onFinish && this.props.onFinish(didSucceed); @@ -94,7 +94,7 @@ export default class extends React.PureComponent { } cancelAudioMessage = async() => { - this.setState({ recordingCanceled: true }); + this.recordingCanceled = true; await AudioRecorder.stopRecording(); return this._finishRecording(false); } From a6fed26cd1f1c3a5f97139d467dfb17edcd84bbe Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Tue, 6 Mar 2018 21:11:31 -0300 Subject: [PATCH 16/16] Update Recording.js --- app/containers/MessageBox/Recording.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/containers/MessageBox/Recording.js b/app/containers/MessageBox/Recording.js index b510a8fac50..10e32b89832 100644 --- a/app/containers/MessageBox/Recording.js +++ b/app/containers/MessageBox/Recording.js @@ -65,8 +65,6 @@ export default class extends React.PureComponent { AudioRecorder.startRecording(); } - recordingCanceled; - _finishRecording(didSucceed, filePath) { if (!didSucceed) { return this.props.onFinish && this.props.onFinish(didSucceed);