OpenTok Accelerator TextChat


License

License

GroupId

GroupId

com.opentok.android
ArtifactId

ArtifactId

opentok-accelerator-textchat
Last Version

Last Version

1.0.11
Release Date

Release Date

Type

Type

aar
Description

Description

OpenTok Accelerator TextChat
OpenTok Accelerator TextChat
Project URL

Project URL

https://github.com/opentok/accelerator-textchat-android
Source Code Management

Source Code Management

https://github.com/opentok/accelerator-textchat-android

Download opentok-accelerator-textchat

How to add to project

<!-- https://jarcasting.com/artifacts/com.opentok.android/opentok-accelerator-textchat/ -->
<dependency>
    <groupId>com.opentok.android</groupId>
    <artifactId>opentok-accelerator-textchat</artifactId>
    <version>1.0.11</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.opentok.android/opentok-accelerator-textchat/
implementation 'com.opentok.android:opentok-accelerator-textchat:1.0.11'
// https://jarcasting.com/artifacts/com.opentok.android/opentok-accelerator-textchat/
implementation ("com.opentok.android:opentok-accelerator-textchat:1.0.11")
'com.opentok.android:opentok-accelerator-textchat:aar:1.0.11'
<dependency org="com.opentok.android" name="opentok-accelerator-textchat" rev="1.0.11">
  <artifact name="opentok-accelerator-textchat" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.opentok.android', module='opentok-accelerator-textchat', version='1.0.11')
)
libraryDependencies += "com.opentok.android" % "opentok-accelerator-textchat" % "1.0.11"
[com.opentok.android/opentok-accelerator-textchat "1.0.11"]

Dependencies

compile (4)

Group / Artifact Type Version
androidx.appcompat » appcompat jar 1.2.0
androidx.recyclerview » recyclerview jar 1.1.0
com.google.android.material » material jar 1.2.1
com.opentok.android : opentok-accelerator-core jar 1.0.23

Project Modules

There are no modules declared in this project.

This project is no longer maintained. Please use accelerator-core-android instead

Accelerator TextChat for Android

Build Status GitHub release license MIT

Tokbox is now known as Vonage

Quick start

This section shows you how to use the accelerator textchat.

Install

There are two options for installing the OpenTok Accelerator TextChat library:

NOTE: The Accelerator TextChat includes the OpenTok Accelerator Core for Android.

Using the repository

  1. Clone the OpenTok Accelerator TextChat repo.
  2. From the OpenTok Text Chat Sample app project, right-click the app name and select New > Module > Import Gradle Project.
  3. Navigate to the directory in which you cloned OpenTok Text Chat Accelerator Pack, select accelerator-textchat-android, and click Finish.
  4. Open the build.gradle file for the app and ensure the following line has been added to the dependencies section:
implementation project(':accelerator-textchat-android')

Using Maven

  1. Modify the build.gradle for your solution and add the following code snippet to the section labeled 'repositories’: maven { url "http://tokbox.bintray.com/maven" }
  2. Modify the build.gradle for your activity and add the following code snippet to the section labeled 'dependencies’: implementation 'com.opentok.android:opentok-accelerator-textchat:x.y.z'

Exploring the code

The TextChatFragment class is the backbone of the text chat communication feature.

This class, which inherits from the androidx.fragment.app.Fragment class, sets up the text chat UI views and events, sets up session listeners, and defines a listener interface to monitor the changes.

public class TextChatFragment extends Fragment implements SignalListener {
    . . .
}

The TextChatListener interface monitors state changes in the TextChatFragment, and defines the following methods:

public interface TextChatListener {
  void onNewSentMessage(ChatMessage message);
  void onNewReceivedMessage(ChatMessage message);
  void onTextChatError(String error);
  void onClose();
}

Initialization methods

The following TextChatFragment methods are used to initialize the app and provide basic information determining the behavior of the text chat functionality.

Feature Methods
Set the maximum chat text length. setMaxTextLength()
Set the sender alias of the outgoing messages. setSenderAlias()
Set the listener object to monitor state changes. setListener()

For example, the following private method instantiates a TextChatFragment object:

  OTAcceleratorSession mSession = new OTAcceleratorSession (context, apikey, sessionId);
  mSession.connect(token);

  //...

  private void initTextChatFragment() {
    mTextChatFragment = TextChatFragment.newInstance(mSession, apikey);
    getSupportFragmentManager().beginTransaction()
                .add(R.id.textchat_fragment_container, mTextChatFragment).commit();
    getSupportFragmentManager().executePendingTransactions();    
  }

This lines of code illustrates how to set the maximum message length to 1050 characters and set a new sender alias:

  try {
    mTextChatFragment.setSenderAlias("Tokboxer");
    mTextChatFragment.setMaxTextLength(140);
    mTextChatFragment.setListener(this);
  } catch (Exception e) {
    e.printStackTrace();
  }

Sending and receiving messages

By implementing the TextChatFragment.TextChatListener interface, the app can monitor both receiving and sending activity. For example, a message is successfully sent, or a message is sent with a code in the event of an error.

The method implementations shown below use the ChatMessage object to send and receive messages.

The onNewSentMessage() event is fired when a new individual ChatMessage is sent to other client connected to the OpenTok session. To send a ChatMessage, the TextChatFragment uses the OpenTok signaling API.

The onNewReceivedMessage() event is fired when a new ChatMessage is received from the other client.

    @Override
    public void onNewSentMessage(ChatMessage message) {
        Log.i(LOG_TAG, "New sent message");
    }

    @Override
    public void onNewReceivedMessage(ChatMessage message) {
        Log.i(LOG_TAG, "New received message");
    }

Multiparty sample app using the Accelerator TextChat with best-practices for Android.

screenshot

Development and Contributing

Interested in contributing? We ❤️ pull requests! See the Contribution guidelines.

Getting Help

We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either:

Further Reading

com.opentok.android

OpenTok

Versions

Version
1.0.11
1.0.10
1.0.9
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0