![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
opentok-text-chat
Advanced tools
The OpenTok Text Chat Accelerator Pack provides functionality you can add to your OpenTok applications that enables users to exchange text messages between mobile or browser-based devices.
This section shows you how to use the accelerator pack.
$ npm install --save opentok-text-chat
If using browserify or webpack:
const textChat = require('opentok-text-chat');
Otherwise, include the accelerator pack in your html:
<script src="../your/path/to/opentok-text-chat.js"></script>
. . . and it will be available in global scope as TextChatAccPack
Click here for a list of all OpenTok accelerator packs.
The TextChatAccPack
class in text-chat-acc-pack.js is the backbone of the text chat communication features for the app.
This class sets up the text chat UI views and events, and provides functions for sending, receiving, and rendering individual chat messages.
The following options
fields are used in the TextChatAccPack
constructor:
Feature | Field |
---|---|
Set the session. | session |
Set the chat container. | textChatContainer |
Sets the position of the element that displays the information for the character count within the UI. | controlsContainer |
Set the maximum chat text length. | limitCharacterMessage |
Set the sender alias and the sender ID of the outgoing messages. | sender |
Set the text chat container to automatically be displayed. | alwaysOpen |
If you're using a bundler like webpack or Browserify, you can install the the text chat component with npm, and import into your application:
const TextChatAccPack = require('opentok-text-chat');
const textChat = new TextChatAccPack(options);
Otherwise, the package will need to be in global
scope to be initialized:
var _options = {
textChat: {
sender: {
alias: 'David',
},
limitCharacterMessage: 160,
controlsContainer: '#feedControls',
textChatContainer: '#chatContainer',
alwaysOpen: true
}
};
var textChatOptions = {
accPack: _this,
session: _session,
sender: _options.textChat.sender,
limitCharacterMessage: _options.textChat.limitCharacterMessage,
controlsContainer: _options.textChat.controlsContainer,
textChatContainer: _options.textChat.textChatContainer,
alwaysOpen: _options.textChat.alwaysOpen
};
_components.textChat = new TextChatAccPack(textChatOptions);
The TextChat
component defines the following methods:
Method | Description |
---|---|
showTextChat() | Show the text chat view. |
hideTextChat() | Hide the text chat view. |
isDisplayed() | Determines if the text chat accelerator pack is displayed. |
isEnabled() | Determines if the text chat accelerator pack is enabled. |
For example, this line determines whether the text chat accelerator pack is displayed:
var displayed = _textChat.isDisplayed();
The TextChat
component emits the following events:
Method | Description |
---|---|
messageReceived | A new message has been received. |
messageSent | A new message has been sent. |
errorSendingMessage | An error occurred when sending a message. |
The following code shows how to subscribe to these events:
_accPack.registerEventListener('messageReceived', function() {
. . .
});
_accPack.registerEventListener('messageSent', function() {
. . .
});
_accPack.registerEventListener('errorSendingMessage', function() {
. . .
});
FAQs
OpenTok text chat accelerator pack
The npm package opentok-text-chat receives a total of 510 weekly downloads. As such, opentok-text-chat popularity was classified as not popular.
We found that opentok-text-chat demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.