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

strophe.logger.js 941B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Strophe } from 'strophe.js';
  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. /**
  8. *
  9. */
  10. constructor() {
  11. super();
  12. this.log = [];
  13. }
  14. /**
  15. *
  16. * @param connection
  17. */
  18. init(connection) {
  19. super.init(connection);
  20. this.connection.rawInput = this.logIncoming.bind(this);
  21. this.connection.rawOutput = this.logOutgoing.bind(this);
  22. }
  23. /**
  24. *
  25. * @param stanza
  26. */
  27. logIncoming(stanza) {
  28. this.log.push([ new Date().getTime(), 'incoming', stanza ]);
  29. }
  30. /**
  31. *
  32. * @param stanza
  33. */
  34. logOutgoing(stanza) {
  35. this.log.push([ new Date().getTime(), 'outgoing', stanza ]);
  36. }
  37. }
  38. /**
  39. *
  40. */
  41. export default function() {
  42. Strophe.addConnectionPlugin('logger', new StropheLogger());
  43. }