Widget Events

You can subscribe the many events that the widget uses to keep you in the loop on what is going on on the client side while the consumer is using the widget. For example, when the widget was succesfull loaded or when a message came in or was send.

To bind an event, use window.web1on1.on(event name, handler function);. To unbind events, you can either call window.web1on1.off(event name, handler function) to remove one specific handler, call window.web1on1.off(event name) to remove all handlers for an event, or call window.web1on1.off() to unbind all handlers.

You can use all events described below to send GTM or Analytics data.

Widget Events

ready

// This event triggers when init completes successfully... Be sure to bind before calling init!
window.web1on1.on('ready', function(){
    console.log('the init has completed!');
});

window.web1on1.init(...).then(function() {
    // init also returns a promise, so you can alternatively specify a .then() callback
});

destroy

// This event triggers when the widget is destroyed.
window.web1on1.on('destroy', function(){
    console.log('the widget is destroyed!');
});

window.web1on1.destroy();

message:received

// This event triggers when the user receives a message
window.web1on1.on('message:received', function(message, data) {
    console.log(`The user received a message in conversation ${data.conversation._id}: `, message);
});

message:sent

// This event triggers when the user sends a message
window.web1on1.on('message:sent', function(message) {
    console.log('the user sent a message', message);
});

message

// This event triggers when a message was added to the conversation
window.web1on1.on('message', function(message) {
    console.log('a message was added to the conversation', message);
});

unreadCount

// This event triggers when the number of unread messages changes
window.web1on1.on('unreadCount', function(unreadCount) {
    console.log('the number of unread messages was updated', unreadCount);
});

widget:opened

// This event triggers when the widget is opened
window.web1on1.on('widget:opened', function() {
    console.log('Widget is opened!');
});

widget:closed

// This event triggers when the widget is closed
window.web1on1.on('widget:closed', function() {
    console.log('Widget is closed!');
});

log:debug

// This event triggers when the codes emits debug information
window.web1on1.on('log:debug', function(e) {
    console.log('Timestamp': e.timestamp); // (Float) Date.now() when it was emitted
    console.log('Message': e.message); // (String) Message being logged
    console.log('Data': e.data); // (Object) Extra details to be logged
});

connected

// This event triggers when an active connection has been established for the first time,
// or when the connection has been re-established after a `disconnect` event.
window.web1on1.on('connected', function(e) {
    console.log('Connected');
});

disconnected

// This event triggers when an active connection is lost
// While disconnected, the client will not be able to recieve messages
window.web1on1.on('disconnected', function(e) {
    console.log('Disonnected');
});

typing:start

// This event triggers when appMaker starts typing
window.web1on1.on('typing:start', function() {
    console.log('appMaker starts typing!');
});

typing:stop

// This event triggers when appMaker stops typing
window.web1on1.on('typing:stop', function() {
    console.log('appMaker stops typing!');
});