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

strophe.logger.ts 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. private log: any;
  11. /**
  12. *
  13. */
  14. constructor() {
  15. super();
  16. this.log = [];
  17. }
  18. /**
  19. *
  20. * @param connection
  21. */
  22. init(connection: Strophe.Connection): void {
  23. super.init(connection);
  24. connection.rawInput = this.logIncoming.bind(this);
  25. connection.rawOutput = this.logOutgoing.bind(this);
  26. }
  27. /**
  28. *
  29. * @param stanza
  30. */
  31. logIncoming(stanza: Element | Strophe.Builder): void {
  32. this.log.push([ new Date().getTime(), 'incoming', stanza ]);
  33. }
  34. /**
  35. *
  36. * @param stanza
  37. */
  38. logOutgoing(stanza: Element | Strophe.Builder): void {
  39. this.log.push([ new Date().getTime(), 'outgoing', stanza ]);
  40. }
  41. }
  42. /**
  43. *
  44. */
  45. export default function() {
  46. Strophe.addConnectionPlugin('logger', new StropheLogger());
  47. }