UNPKG

help-fem

Version:

A Browserify/Node.js client module for the Help.com team's FEM.

29 lines (23 loc) 633 B
'use strict'; var uuid = require('uuid'); module.exports = Message; // type should be one of heartbeat, heartbeat-reply, // open, close, client session event, client chat event, // server session event, server chat event function Message(type, msg, inre) { if (!(this instanceof Message)) { return new Message(type, msg, inre); } this.type = type; this.msg = msg; this.msg.meta.id = this.msg.meta.id || uuid.v4(); if (inre && inre.meta) { this.msg.meta.replyTo = inre.meta.id; } } Message.prototype.toJSON = function toJSON() { return JSON.stringify({ event: this.type, message: this.msg }); }