您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

strophe.logger.js 753B

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. }