Quellcode durchsuchen

add logger

master
Philipp Hancke vor 11 Jahren
Ursprung
Commit
795b1cc4ec
2 geänderte Dateien mit 24 neuen und 0 gelöschten Zeilen
  1. 23
    0
      estos_log.js
  2. 1
    0
      index.html

+ 23
- 0
estos_log.js Datei anzeigen

@@ -0,0 +1,23 @@
1
+Strophe.addConnectionPlugin('logger', {
2
+    // logs raw stanzas and makes them available for download as JSON
3
+    connection: null,
4
+    log: [],
5
+    init: function (conn) {
6
+        this.connection = conn;
7
+        this.connection.rawInput = this.log_incoming.bind(this);;
8
+        this.connection.rawOutput = this.log_outgoing.bind(this);;
9
+    },
10
+    log_incoming: function (stanza) {
11
+        this.log.push([new Date().getTime(), 'incoming', stanza]);
12
+    },
13
+    log_outgoing: function (stanza) {
14
+        this.log.push([new Date().getTime(), 'outgoing', stanza]);
15
+    },
16
+    // <a onclick="connection.logger.dump(event.target);">my download button</a>
17
+    dump: function (what, filename){
18
+        what.download = filename || 'xmpplog.json';
19
+        what.href = 'data:application/json;charset=utf-8,\n';
20
+        what.href += encodeURIComponent(JSON.stringify(this.log, null, '  '));
21
+        return true;
22
+    }
23
+});

+ 1
- 0
index.html Datei anzeigen

@@ -5,6 +5,7 @@
5 5
     <script src="libs/strophejingle.bundle.js"></script><!-- strophe.jingle bundle -->
6 6
     <script src="libs/colibri.js"></script><!-- colibri focus implementation -->
7 7
     <script src="muc.js"></script><!-- simple MUC library -->
8
+    <script src="estos_log.js"></script><!-- simple stanza logger -->
8 9
     <script src="app.js"></script><!-- application logic -->
9 10
     <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
10 11
     <link rel="stylesheet" type="text/css" media="screen" href="css/main.css" />

Laden…
Abbrechen
Speichern