You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

strophe.logger.js 757B

123456789101112131415161718192021222324252627282930
  1. /* global Strophe */
  2. import ConnectionPlugin from "./ConnectionPlugin";
  3. /**
  4. * Logs raw stanzas and makes them available for download as JSON
  5. */
  6. class StropheLogger extends ConnectionPlugin {
  7. constructor() {
  8. super();
  9. this.log = [];
  10. }
  11. init (connection) {
  12. super.init(connection);
  13. this.connection.rawInput = this.log_incoming.bind(this);
  14. this.connection.rawOutput = this.log_outgoing.bind(this);
  15. }
  16. log_incoming (stanza) {
  17. this.log.push([new Date().getTime(), 'incoming', stanza]);
  18. }
  19. log_outgoing (stanza) {
  20. this.log.push([new Date().getTime(), 'outgoing', stanza]);
  21. }
  22. }
  23. export default function () {
  24. Strophe.addConnectionPlugin('logger', new StropheLogger());
  25. }