Giter Club home page Giter Club logo

react-native-twilio-chat's Introduction

React Native Twilio Chat

npm version

React Native wrapper for the Twilio Programmable Chat iOS and Android SDKs

Note - this project is currently in development for a beta release. If you are looking for the legacy package for the Twilio IP Messaging SDKs, see the original repository here.

Installation

npm install --save react-native-twilio-chat

iOS - CocoaPods

Install the Twilio Chat SDK and this package via CocoaPods. See the full Podfile example for more details.

pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'React', :subspecs => ['Core', /* any other subspecs you require */], :path => '../node_modules/react-native'
pod 'RCTTwilioChat', :path => '../node_modules/react-native-twilio-chat/ios'
  
source 'https://github.com/twilio/cocoapod-specs'
pod 'TwilioChatClient', '~> 0.17.1'
pod 'TwilioAccessManager', '~> 0.1.3'

Note: the underlying Twilio SDKs require a minimum deployment target of 8.1. If your project's target is less than this you will get a CocoaPods install error (Unable to satisfy the following requirements...).

Make sure that you add the $(inherited) value to Other Linker Flags and Framework Search Paths for your target's Build Settings. This is also assuming you have already loaded React via CocoaPods as well.

Android

In android/settings.gradle:

include ':RCTTwilioChat', ':app'
project(':RCTTwilioChat').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-twilio-chat/android')

In android/app/build.gradle:

...
dependencies {
    ...
    compile project(':RCTTwilioChat')
}

Register the module in MainApplication.java:

// import package
import com.bradbumbalough.RCTTwilioChat.RCTTwilioChatPackage;

...

// register package in getPackages()
@Override
protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new RCTTwilioChatPackage(),
        ... other packages
    );
}

Note: You might have to enable multidex in your build.gradle file and increase the heap size if you're getting errors while buliding. The minSdkVersion must also be at least 19, per the Twilio SDKs.

android {
    ....
    dexOptions {
        javaMaxHeapSize "2048M"
    }

    defaultConfig {
        ...
        minSdkVersion 19
        multiDexEnabled true
    }

Usage

/* Initialization */

import {
    AccessManager,
    Client,
    Constants
} from 'react-native-twilio-chat';

// create the access manager
const accessManager = new AccessManager(token);

// specify any handlers for events
accessManager.onTokenWillExpire = () => {
    getNewTokenFromServer()
    .then(accessManager.updateToken);
}

// create the client
const client = new Client(token);

// specify any global events
client.onError = ({error, userInfo}) => console.log(error);

// initialize the client
client.initialize();

// wait for sync to finish
client.onClientSynchronized = () => {
    client.getUserChannels()
    .then((channelPaginator) => console.log(channelPaginator.items));
}

/* Individual Channel */

// an instance of Channel is passed down in the app via props
let channel = this.props.channel

// specify channel specific events
channel.onMessageAdded = (message) => console.log(message.author + ": " + message.body);
channel.onTypingStarted = (member) => console.log(member.identity + " started typing...");
channel.onTypingEnded = (member) => console.log(member.identity + " stopped typing...");
channel.onMemberAdded = (member) => console.log(member.identity + " joined " + channel.friendlyName);

// sending a message
<TextInput 
  onChangeText={(body) => {
    this.setState({body});
    channel.typing();
  }}
  onSubmitEditing={() => { channel.sendMessage(this.state.body)} }
/>

Contributers ๐Ÿป

Thank you for your help in maintaining this project! Haven't contributed yet? Check out our Contributing guidelines....

TODO ๐Ÿ—’

  • Copy code from programable-chat branch on old package
  • Copy issues and PRs over
  • Update docs (wiki?)
  • Migration guide
  • Publish to npm
  • Update twilio-ip-messaging to reference twilio-chat
  • 1.0 release
  • Testing

License

This project is licensed under the MIT License.

react-native-twilio-chat's People

Contributors

baisang avatar benoist avatar bradbumbalough avatar bradbyte avatar jck2 avatar johnbuildsthings avatar kabangi avatar mattshen avatar maxwell2022 avatar mikeahirsch avatar n8stowell82 avatar svlaev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-twilio-chat's Issues

undefined is not an object

undefined is not an object(Evaluating TwilioChatClient.TCHChannelStatus).

react-native-cli: 2.0.1
react-native: 0.53.0

iOS setup failure

I'm currently developing a React Native app with the intent of integrating twilio chat in. My current blocker is the setup process as I'm unfamiliar with pods, having been a long time carthage user.

Precursor to the problem:

I followed instructions from here in order to setup the project.

I created a podfile in the iOS React Native project which looks like so:

  pod 'TwilioChatClient', '~> 0.17.1'
  pod 'TwilioAccessManager', '~> 0.1.3'

Following which, I ran pod install and got the them linked in the xcworkspace.

I added the library in my xcworkspace and linked it all up in the linking phase.

However, running react-native run-ios or using the xcode run button yields the following error from the build process - it comes from the Check Pods Manifest.lock step

diff: /Users/ashvala/Projects/testproj/node_modules/react-native-twilio-chat/ios/../../ios/Pods/../Podfile.lock: No such file or directory
diff: /Users/ashvala/Projects/testproj/node_modules/react-native-twilio-chat/ios/../../ios/Pods/Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

Any insights into what could be happening here?

Channel getMessagesCount causes app to crash

Hello,
In onSuccess calback for getMessagesCount method in RCTTwilioChatChannels.java, Long argument is being passed to promise.resolve, which, as far as I know, can't be done because react native doesn't implement conversion from Java Long to Javascript Number. The backtrace for the exception is as follows:

FATAL EXCEPTION: mqt_native_modules
Process: com.medcall, PID: 8210
java.lang.RuntimeException: Cannot convert argument of type class java.lang.Long
   at com.facebook.react.bridge.Arguments.fromJavaArgs(Arguments.java:57)
   at com.facebook.react.bridge.CallbackImpl.invoke(CallbackImpl.java:36)
   at com.facebook.react.bridge.PromiseImpl.resolve(PromiseImpl.java:32)
   at com.bradbumbalough.RCTTwilioChat.RCTTwilioChatChannels$16$1.onSuccess(RCTTwilioChatChannels.java:505)
   at com.bradbumbalough.RCTTwilioChat.RCTTwilioChatChannels$16$1.onSuccess(RCTTwilioChatChannels.java:495)
   at com.twilio.chat.internal.CallbackListenerForwarder$1.run(CallbackListenerForwarder.java:31)
   at android.os.Handler.handleCallback(Handler.java:751)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:154)
   at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:208)
   at java.lang.Thread.run(Thread.java:761)

I've found, that it is suggested to use either 64bit double, or 53bit int (source: facebook/react-native#9685)
Can anyone give suggestion how it should be implemented?

[Question] How do to integrate it to IOS without introducing cocoapods.

Am trying to build my react native app on ios that has this library fully working on android. The problem is I don't have prior experience with IOS and I can't figure out how to integrate this library without having to introduce cocoapods.

I do know though that majority of react native projects do not use cocoapods and am trying to follow that principle. I have followed this docs http://facebook.github.io/react-native/docs/linking-libraries-ios.html but I get stack of <TwilioChatClient/headerFile not found errors even though I have the twilio framework as part of the linked libraries.

I would appreciate pointers on how to proceed on this and eventually I want to send a PR on docs with setup instructions for the ios.

iOS TwilioChatClient/TCHUserInfo.h not found

I'm trying to get up and running with react-native-twilio-chat on IOS and getting an error when trying to build the project. Lexical or Preprocessor Issue: TwilioChatClient/TCHUserInfo.h not found

I am using react-native 0.44 and have setup the TwilioSDK manually (I am not using CocoaPods). I tried running react-native link react-native-twilio-chat and it said it linked the library successfully and there were no errors installing the SDK itself, it wasn't until I added react-native-twilio-chat that it threw an error on building.

Any suggestions on what the issue is would be very helpful.

NPM twilio-chat release 1.01

Hello,

Today I received an email from Carl Olivier (Director of Product, Realtime Data Services at Twilio).
They updated their JS SDK and now it supports React Native apps. Reference

I haven't tested it yet, just wanted to let you know.

getMessages doesn't resolve

Promise returned by channel.getMessages(10) not resolving.

I went inside the iOS code to set breakpoints and narrowed down to the fact that the callback for getLastMessagesWithCount doesn't seem to be called.

RN 44.2
react-native-twilio-chat 0.3.11

Below code does not get to console.log:

channel.initialize()
   .then(() => {
     channel.getMessages(10)
       .then((messages) => {
         console.log(messages);
       });
   });

[Android] int com.twilio.chat.ChatClient$SynchronizationStrategy.getValue() on null object reference

I am using RN0.42
I followed the installation steps for android. I am getting following error after client.initialize() where client is (client = new Client)[import {Client} from 'react-native-twilio-chat']
'attempt to call virtual method com.twilio.chat.ChatClient.$SynchronizationStrategy.getValue() on a null objetct reference'

I then followed the SDK installation steps from 'https://www.twilio.com/docs/api/chat/sdks' and added below lines in my app build.gradle file:

compile 'com.twilio:chat-android:0.12.2'
compile 'com.twilio:accessmanager-android:0.1.0'

After that the app crashes with message 'Unfortunately [AppName] has stopped working'

My build.gradle has:

    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    dexOptions {
        jumboMode = true
        javaMaxHeapSize "2048M"
     }
defaultConfig {
        minSdkVersion 19
        targetSdkVersion 22
        versionCode 22
        versionName "3.0.4"
        multiDexEnabled true
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
dependencies {
    //compile project(':react-native-twilio-chat')
    compile project(':RCTTwilioChat')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile 'com.twilio:chat-android:0.12.2'
    compile "com.twilio:accessmanager-android:0.1.0"
}

[Question] Anyone able to archive an ios app with this lib.

When I switch to the current lib release, archiving on xcode seems to generate an invalid bundle which can't be uploaded to appstore. If I switch to my fork it works fine.

Am still learning ios so I don't have enough information to what could be possibly be happening.
Help.

Thanks.

[ANDROID] create channel error

using @0.3.1
When using createChannel in android - without giving attributes property in options arg, it says - couldn't find key attributes in dynamic object.
when I add an empty attributes property ({}, or {a:1}) it throws with - Error occurred while attempting to createChannel
in IOS everything woks fine

Android websocket

Hi, I have an issue with the Android app. If I try to create a new Client, then I get a Client. But when I try to initialize my Client, then I get the current Client with his method. And then I get a problem with TNTwiliosockClient.

method does not override or implement a method from a supertype

~\node_modules\react-native-twilio-chat\android\src\main\java\com\bradbumbalough\RCTTwilioChat\RCTTwilioChatPackage.java:15: error: method does not override or implement a method from a supertype
@OverRide
^
Note: ~\node_modules\react-native-twilio-chat\android\src\main\java\com\bradbumbalough\RCTTwilioChat\RCTTwilioChatClient.java uses or overrides a deprecated API.

"react": "16.0.0-alpha.12",
"react-native": "0.46.4",

compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
applicationId "com.name"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}

Abandoned?

We're just about to implement a chat with GiftedChat and Firebase, and then we saw this, which looks awesome.

But it looks worrisome when the last commit was 6 months ago.

What's the status? :)

Cannot read property 'Constants' of undefined

I am getting "Cannot read property 'Constants' of undefined" from the Constants.js file in this application. It appears it cannot find the TwilioChatClient object. If I change line 22 to NativeModules.Constants, it does not err out my application.

react-native-cli: 2.0.1
react-native: 0.51.0

Upgrade to latest version of react native(0.47)

I am trying to upgrade to RN 0.47 version. After upgrade I am getting following error:

..\RCTTwilioChatPackage.java:15: error: method does not override or implement a method from a
supertype
@OverRide
^
Note: [Project location]\node_modules\react-native-twilio-chat\android\src\main\java\com\bradbumbaloug
h\RCTTwilioChat\RCTTwilioChatClient.java uses or overrides a deprecated API.

Problem with AccessManager

Attempt to read from field 'long com.twilio.accessmanager.Token.exp' on a null object reference. This is my error and I just started to use following the documentation, this only appears when I try to initialize AcessManager and I try to set a token in parameter.
I'm using latest version of RN, What can I do?

This is the code that I use.

image

This is the error.

image

Thank you!

Calling channel.getMessages results to an Null Exception error. I think this is related to null promise being passed to that method.

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.twilio.chat.Messages.getLastMessages(int, com.twilio.chat.CallbackListener)' on a null object reference at com.bradbumbalough.RCTTwilioChat.RCTTwilioChatMessages$5.onSuccess(RCTTwilioChatMessages.java:142) at com.bradbumbalough.RCTTwilioChat.RCTTwilioChatMessages$5.onSuccess(RCTTwilioChatMessages.java:134) at com.bradbumbalough.RCTTwilioChat.RCTTwilioChatMessages$1.onSuccess(RCTTwilioChatMessages.java:36) at com.bradbumbalough.RCTTwilioChat.RCTTwilioChatMessages$1.onSuccess(RCTTwilioChatMessages.java:33) at com.twilio.chat.internal.CallbackListenerForwarder$1.run(CallbackListenerForwarder.java:51) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196) at java.lang.Thread.run(Thread.java:818)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.