cirandas.net

ref: master

public/javascripts/vendor/strophejs-1.1.3/examples/attach/templates/attacher/index.html


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
  <head>
    <title>Strophe Attach Example</title>
    <script language='javascript'
	    type='text/javascript'
	    src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script>
    <script language='javascript'
	    type='text/javascript'
	    src='http://code.stanziq.com/svn/strophe/trunk/strophejs/b64.js'></script>
    <script language='javascript'
	    type='text/javascript'
	    src='http://code.stanziq.com/svn/strophe/trunk/strophejs/md5.js'></script>
    <script language='javascript'
	    type='text/javascript'
	    src='http://code.stanziq.com/svn/strophe/trunk/strophejs/sha1.js'></script>
    <script language='javascript'
	    type='text/javascript'
	    src='http://code.stanziq.com/svn/strophe/trunk/strophejs/strophe.js'></script>
    <script language='javascript'
	    type='text/javascript'>
      <!--
	  var ATTACH_SID = "{{ sid }}";
	  var ATTACH_RID = "{{ rid }}";
	  var ATTACH_JID = "{{ jid }}";
	  var BOSH_SERVICE = '/xmpp-httpbind';
	  var connection = null;
	  var startTime = null;

          function log(msg)
	  {
	      $('#log').append('<div></div>').append(
	          document.createTextNode(msg));
	  }

	  function onConnect(status) 
	  {
	      if (status == Strophe.Status.DISCONNECTED)
	          log('Disconnected.');
	  }

          function onResult(iq) {
	      var elapsed = (new Date()) - startTime;
	      log('Response from jabber.org took ' + elapsed + 'ms.');
          }
	  
	  $(document).ready(function () {
	      // create the connection and attach it
	      connection = new Strophe.Connection(BOSH_SERVICE);
	      connection.rawInput = function (data) { 
	          log('RECV: ' + data); 
	      };
	      connection.rawOutput = function (data) { 
	          log('SENT: ' + data); 
	      };
	      // uncomment for extra debugging
	      // Strophe.log = function (lvl, msg) { log(msg); };
	      connection.attach(ATTACH_JID, ATTACH_SID, ATTACH_RID,
	                        onConnect);

              // set up handler
	      connection.addHandler(onResult, null, 'iq', 
	                            'result', 'disco-1', null);

              log('Strophe is attached.');
				
	      // send disco#info to jabber.org
	      var iq = $iq({to: 'jabber.org',
	                    type: 'get',
			    id: 'disco-1'})
                  .c('query', {xmlns: Strophe.NS.DISCO_INFO})
		  .tree()

              startTime = new Date();
              connection.send(iq);
          });
      // -->
    </script>
  </head>
  <body>
    <h1>Strophe Attach Example</h1>
    <p>This example shows how to attach to an existing BOSH session with
    Strophe.</p>
    <h2>Log</h2>
    <div id='log'>
    </div>
  </body>
</html>