
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
iscomposing
Advanced tools
JavaScript implementation of "Indication of Message Composition for Instant Messaging" (RFC 3994)
JavaScript implementation of "Indication of Message Composition for Instant Messaging" (RFC 3994).
Useful to add the common "is typing" feature into your existing chat.
$ npm install iscomposing --save
And then:
var iscomposing = require('iscomposing');
Take the browserified version of the library at dist/iscomposing.js
. It exposes the global window.iscomposing
module.
<script type='text/javascript' src='js/iscomposing.js'></script>
NOTE: The iscomposing.js library uses the mimemessage library within the API it provides.
iscomposing
APIThe top-level module exported by the library is an object exporting both the Composer
and the Receiver
classes described below.
var composer = new iscomposing.Composer();
var receiver = new iscomposing.Receiver();
iscomposing.Composer
Class APIA Composer
instance manages the composing status of the local peer.
var composer = new iscomposing.Composer(options)
options
is an optional object with the following fields:
format
(String): Whether to use XML payload for "status" messages (as the RFC 3994 defines) or custom JSON payloads. Valid values are "xml" (default value) and "json".refreshInterval
(Number): Interval for sending "active status" messages (in seconds). Default value is 120. Minimum value is 30.idleTimeout
(Number): Timeout for sending "idle status" message if the apps stops composing its message (in seconds). Default value is 15. Minimum value is 5.var composer = new iscomposing.Composer({
format: 'json',
refreshInterval: 60
});
composer.composing(statusContentType)
Tell the composer that a message is being composed.
statusContentType
(String): Optional string indicating the type of message being composed. Default value is "text".// When the user types into the chat text input:
composer.composing();
The app should call this method whenever the user types into the text input of the chat.
composer.sent()
Tell the composer that the composed message was sent.
// When the user uses clicks on "Send" button:
myChat.send({
contentType: 'text/plain',
body: text
});
composer.sent();
The app should call this method whenever a message (other than a "status" message) is sent to the remote peer.
composer.idle()
Tell the composer that the user is no longer typing or composing a message.
// When the chat text input looses the focus:
composer.idle();
The app should call this method whenever the user was writting into the chat text input and clicked elsewhere before sending the ongoing text, or also when he suddenly deletes all the text previously written in the chat input.
composer.close()
Tell the composer that our chat side is closed. No more events will be fired unless the app reactivates it by calling any API method again.
// When the chat window is closed.
composer.close();
The app should call this method when, for example, the chat window is closed or the chat itself ends.
The Composer
class inherits from the Node EventEmitter class.
composer.on('active', callback(mimeMessage))
Emitted whenever the app should send an "active status" message to the remote peer. The given callback
function is called with two arguments:
mimeMessage
(mimemessage.Entity): Instance of mimemessage.Entity
to be sent to the peer.composer.on('active', function (mimeMessage) {
myChat.send(mimeMessage);
});
composer.on('idle', callback(mimeMessage))
Emitted whenever the app should send an "idle status" message to the remote peer. The given callback
function is called with two arguments:
mimeMessage
(mimemessage.Entity): Instance of mimemessage.Entity
to be sent to the peer.composer.on('idle', function (mimeMessage) {
myChat.send(mimeMessage);
});
iscomposing.Receiver
Class APIA Receiver
instance manages the composing status of the remote peer.
var receiver = new iscomposing.Receiver(options)
options
is an optional object with the following fields:
format
(String): Whether to expect XML payload for "status" messages (as the RFC 3994 defines) or custom JSON payloads. Valid values are "xml" (default value) and "json".var receiver = new iscomposing.Receiver({
format: 'json'
});
receiver.received()
Tell the receiver that a message (other than a "status" message) has been received.
// When a chat message (msg) is received from the remote peer.
myChat.on('message', function (mimeMessage) {
if (mimeMessage.contentType().type === 'text') {
receiver.received();
}
});
The app should call this method for each chat/audio/video message received from the remote peer (other than "status" message).
receiver.process(statusMessage)
Tell the receiver that a "status" message has been received. The receiver will process the given raw status message and fire the corresponding event (if needed).
statusMessage
(String or mimemessage.Entity): The received RFC 3994 status raw message or a mimemessage.Entity
instance holding it.// When a message (msg) is received from the remote peer.
myChat.on('message', function (mimeMessage) {
if (mimeMessage.contentType().fulltype === 'application/im-iscomposing+xml') {
indicator.process(mimeMessage);
}
});
The app should call this method for each "status" message received from the remote peer.
receiver.close()
Closes the receiver by emitting an "idle" event (if the current remote status was "idle").
// When the chat window is closed.
receiver.close();
The app should call this method when, for example, the chat window is closed or the chat itself ends.
receiver.on('active', callback(statusContentType))
Emitted when the remote peer is composing a message. The given callback
function is called with a single argument:
statusContentType
(String): The type of message being composed ("text", "audio", "video", etc).receiver.on('active', function (statusContentType) {
showRemoteIsComposing(statusContentType);
});
receiver.on('idle', callback(statusContentType))
Emitted when the remote peer is in idle state (rather than composing a new message). The given callback
function is called with a single argument:
statusContentType
(String): The type of message that was previously being composed ("text", "audio", "video", etc).receiver.on('idle', function (statusContentType) {
hideRemoteIsComposing();
});
The library includes the Node debug module. In order to enable debugging:
In Node set the DEBUG=iscomposing*
environment variable before running the application, or set it at the top of the script:
process.env.DEBUG = 'iscomposing*';
In the browser run iscomposing.debug.enable('iscomposing*');
and reload the page. Note that the debugging settings are stored into the browser LocalStorage. To disable it run iscomposing.debug.disable('iscomposing*');
.
Iñaki Baz Castillo at eFace2Face, inc.
MIT :)
FAQs
JavaScript implementation of "Indication of Message Composition for Instant Messaging" (RFC 3994)
The npm package iscomposing receives a total of 0 weekly downloads. As such, iscomposing popularity was classified as not popular.
We found that iscomposing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.