Wed, 10 Mar 2010 12:01:15 +0000
Add js/strophe/ directory containing Strophe
10
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | /* |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | This program is distributed under the terms of the MIT license. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | Please see the LICENSE file for details. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | Copyright 2006-2008, OGG, LLC |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | /** File: strophe.js |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | * A JavaScript library for XMPP BOSH. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | * This is the JavaScript version of the Strophe library. Since JavaScript |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | * has no facilities for persistent TCP connections, this library uses |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | * Bidirectional-streams Over Synchronous HTTP (BOSH) to emulate |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | * a persistent, stateful, two-way connection to an XMPP server. More |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | * information on BOSH can be found in XEP 124. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | /** PrivateFunction: Function.prototype.bind |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | * Bind a function to an instance. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | * This Function object extension method creates a bound method similar |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | * to those in Python. This means that the 'this' object will point |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | * to the instance you want. See |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | * <a href='http://benjamin.smedbergs.us/blog/2007-01-03/bound-functions-and-function-imports-in-javascript/'>Bound Functions and Function Imports in JavaScript</a> |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | * for a complete explanation. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | * This extension already exists in some browsers (namely, Firefox 3), but |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | * we provide it to support those that don't. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | * (Object) obj - The object that will become 'this' in the bound function. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | * The bound function. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 | if (!Function.prototype.bind) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | Function.prototype.bind = function (obj) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | var func = this; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | return function () { return func.apply(obj, arguments); }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 | /** PrivateFunction: Function.prototype.prependArg |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 | * Prepend an argument to a function. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 | * This Function object extension method returns a Function that will |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 | * invoke the original function with an argument prepended. This is useful |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 | * when some object has a callback that needs to get that same object as |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 | * an argument. The following fragment illustrates a simple case of this |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 | * > var obj = new Foo(this.someMethod);</code></blockquote> |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 | * Foo's constructor can now use func.prependArg(this) to ensure the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 | * passed in callback function gets the instance of Foo as an argument. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 | * Doing this without prependArg would mean not setting the callback |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 | * from the constructor. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 | * This is used inside Strophe for passing the Strophe.Request object to |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 | * the onreadystatechange handler of XMLHttpRequests. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 | * arg - The argument to pass as the first parameter to the function. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 | * A new Function which calls the original with the prepended argument. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 | if (!Function.prototype.prependArg) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 | Function.prototype.prependArg = function (arg) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 | var func = this; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 | return function () { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 | var newargs = [arg]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 | for (var i = 0; i < arguments.length; i++) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 | newargs.push(arguments[i]); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 | return func.apply(this, newargs); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 | /** PrivateFunction: Array.prototype.indexOf |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 | * Return the index of an object in an array. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 | * This function is not supplied by some JavaScript implementations, so |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 | * we provide it if it is missing. This code is from: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 | * http://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Array:indexOf |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 | * (Object) elt - The object to look for. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 | * (Integer) from - The index from which to start looking. (optional). |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 | * The index of elt in the array or -1 if not found. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 | if (!Array.prototype.indexOf) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 | Array.prototype.indexOf = function(elt /*, from*/) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 | var len = this.length; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 | var from = Number(arguments[1]) || 0; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 | from = (from < 0) ? Math.ceil(from) : Math.floor(from); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 | if (from < 0) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 | from += len; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 | for (; from < len; from++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 | if (from in this && this[from] === elt) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 | return from; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 | return -1; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 | /** Function: $build |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 | * Create a Strophe.Builder. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 | * This is an alias for 'new Strophe.Builder(name, attrs)'. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 | * (String) name - The root element name. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 | * (Object) attrs - The attributes for the root element in object notation. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 | * A new Strophe.Builder object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 | function $build(name, attrs) { return new Strophe.Builder(name, attrs); } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 | /** Function: $msg |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 | * Create a Strophe.Builder with a <message/> element as the root. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 | * Parmaeters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 | * (Object) attrs - The <message/> element attributes in object notation. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 | * A new Strophe.Builder object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 | function $msg(attrs) { return new Strophe.Builder("message", attrs); } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 | /** Function: $iq |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 | * Create a Strophe.Builder with an <iq/> element as the root. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 | * (Object) attrs - The <iq/> element attributes in object notation. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 | * A new Strophe.Builder object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 | function $iq(attrs) { return new Strophe.Builder("iq", attrs); } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 | /** Function: $pres |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 | * Create a Strophe.Builder with a <presence/> element as the root. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 | * (Object) attrs - The <presence/> element attributes in object notation. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 | * A new Strophe.Builder object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 | function $pres(attrs) { return new Strophe.Builder("presence", attrs); } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 | /** Class: Strophe |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 | * An object container for all Strophe library functions. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 | * This class is just a container for all the objects and constants |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 | * used in the library. It is not meant to be instantiated, but to |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 | * provide a namespace for library objects, constants, and functions. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 | Strophe = { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 | /** Constants: XMPP Namespace Constants |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 | * Common namespace constants from the XMPP RFCs and XEPs. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 | * NS.HTTPBIND - HTTP BIND namespace from XEP 124. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 | * NS.BOSH - BOSH namespace from XEP 206. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 | * NS.CLIENT - Main XMPP client namespace. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 | * NS.AUTH - Legacy authentication namespace. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 | * NS.ROSTER - Roster operations namespace. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 | * NS.PROFILE - Profile namespace. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 | * NS.DISCO_INFO - Service discovery info namespace from XEP 30. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 | * NS.DISCO_ITEMS - Service discovery items namespace from XEP 30. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 | * NS.MUC - Multi-User Chat namespace from XEP 45. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 | * NS.SASL - XMPP SASL namespace from RFC 3920. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 | * NS.STREAM - XMPP Streams namespace from RFC 3920. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 | * NS.BIND - XMPP Binding namespace from RFC 3920. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 | * NS.SESSION - XMPP Session namespace from RFC 3920. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 | NS: { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 | HTTPBIND: "http://jabber.org/protocol/httpbind", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 | BOSH: "urn:xmpp:xbosh", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 | CLIENT: "jabber:client", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 | AUTH: "jabber:iq:auth", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 | ROSTER: "jabber:iq:roster", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 | PROFILE: "jabber:iq:profile", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 | DISCO_INFO: "http://jabber.org/protocol/disco#info", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 | DISCO_ITEMS: "http://jabber.org/protocol/disco#items", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 | MUC: "http://jabber.org/protocol/muc", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 | SASL: "urn:ietf:params:xml:ns:xmpp-sasl", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 | STREAM: "http://etherx.jabber.org/streams", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 | BIND: "urn:ietf:params:xml:ns:xmpp-bind", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 | SESSION: "urn:ietf:params:xml:ns:xmpp-session", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 | VERSION: "jabber:iq:version", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 | STANZAS: "urn:ietf:params:xml:ns:xmpp-stanzas" |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 | /** Function: addNamespace |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 | * This function is used to extend the current namespaces in |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 | * Strophe.NS. It takes a key and a value with the key being the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 | * name of the new namespace, with its actual value. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 | * For example: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 | * Strophe.addNamespace('PUBSUB', "http://jabber.org/protocol/pubsub"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 | * (String) name - The name under which the namespace will be |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 | * referenced under Strophe.NS |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 | * (String) value - The actual namespace. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 | addNamespace: function (name, value) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 | Strophe.NS[name] = value; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 | /** Constants: Connection Status Constants |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 | * Connection status constants for use by the connection handler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 | * callback. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 | * Status.ERROR - An error has occurred |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 | * Status.CONNECTING - The connection is currently being made |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 | * Status.CONNFAIL - The connection attempt failed |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 | * Status.AUTHENTICATING - The connection is authenticating |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 | * Status.AUTHFAIL - The authentication attempt failed |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 | * Status.CONNECTED - The connection has succeeded |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 | * Status.DISCONNECTED - The connection has been terminated |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
230 | * Status.DISCONNECTING - The connection is currently being terminated |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 | Status: { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 | ERROR: 0, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 | CONNECTING: 1, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 | CONNFAIL: 2, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 | AUTHENTICATING: 3, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 | AUTHFAIL: 4, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 | CONNECTED: 5, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 | DISCONNECTED: 6, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 | DISCONNECTING: 7 |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
242 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
243 | /** Constants: Log Level Constants |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
244 | * Logging level indicators. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
245 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
246 | * LogLevel.DEBUG - Debug output |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 | * LogLevel.INFO - Informational output |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
248 | * LogLevel.WARN - Warnings |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
249 | * LogLevel.ERROR - Errors |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
250 | * LogLevel.FATAL - Fatal errors |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
251 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
252 | LogLevel: { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
253 | DEBUG: 0, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
254 | INFO: 1, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
255 | WARN: 2, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
256 | ERROR: 3, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
257 | FATAL: 4 |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
258 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
259 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
260 | /** PrivateConstants: DOM Element Type Constants |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
261 | * DOM element types. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
262 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
263 | * ElementType.NORMAL - Normal element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
264 | * ElementType.TEXT - Text data element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
265 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
266 | ElementType: { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
267 | NORMAL: 1, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
268 | TEXT: 3 |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
269 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
270 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
271 | /** PrivateConstants: Timeout Values |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
272 | * Timeout values for error states. These values are in seconds. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
273 | * These should not be changed unless you know exactly what you are |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
274 | * doing. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
275 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
276 | * TIMEOUT - Time to wait for a request to return. This defaults to |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
277 | * 70 seconds. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
278 | * SECONDARY_TIMEOUT - Time to wait for immediate request return. This |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
279 | * defaults to 7 seconds. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
280 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
281 | TIMEOUT: 70, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
282 | SECONDARY_TIMEOUT: 7, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
283 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
284 | /** Function: forEachChild |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
285 | * Map a function over some or all child elements of a given element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
286 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
287 | * This is a small convenience function for mapping a function over |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
288 | * some or all of the children of an element. If elemName is null, all |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
289 | * children will be passed to the function, otherwise only children |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
290 | * whose tag names match elemName will be passed. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
291 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
292 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
293 | * (XMLElement) elem - The element to operate on. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
294 | * (String) elemName - The child element tag name filter. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
295 | * (Function) func - The function to apply to each child. This |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
296 | * function should take a single argument, a DOM element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
297 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
298 | forEachChild: function (elem, elemName, func) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
299 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
300 | var i, childNode; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
301 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
302 | for (i = 0; i < elem.childNodes.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
303 | childNode = elem.childNodes[i]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
304 | if (childNode.nodeType == Strophe.ElementType.NORMAL && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
305 | (!elemName || this.isTagEqual(childNode, elemName))) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
306 | func(childNode); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
307 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
308 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
309 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
310 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
311 | /** Function: isTagEqual |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
312 | * Compare an element's tag name with a string. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
313 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
314 | * This function is case insensitive. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
315 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
316 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
317 | * (XMLElement) el - A DOM element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
318 | * (String) name - The element name. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
319 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
320 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
321 | * true if the element's tag name matches _el_, and false |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
322 | * otherwise. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
323 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
324 | isTagEqual: function (el, name) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
325 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
326 | return el.tagName.toLowerCase() == name.toLowerCase(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
327 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
328 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
329 | /** Function: xmlElement |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
330 | * Create an XML DOM element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
331 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
332 | * This function creates an XML DOM element correctly across all |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
333 | * implementations. Specifically the Microsoft implementation of |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
334 | * document.createElement makes DOM elements with 43+ default attributes |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
335 | * unless elements are created with the ActiveX object Microsoft.XMLDOM. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
336 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
337 | * Most DOMs force element names to lowercase, so we use the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
338 | * _realname attribute on the created element to store the case |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
339 | * sensitive name. This is required to generate proper XML for |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
340 | * things like vCard avatars (XEP 153). This attribute is stripped |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
341 | * out before being sent over the wire or serialized, but you may |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
342 | * notice it during debugging. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
343 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
344 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
345 | * (String) name - The name for the element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
346 | * (Array) attrs - An optional array of key/value pairs to use as |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
347 | * element attributes in the following format [['key1', 'value1'], |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
348 | * ['key2', 'value2']] |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
349 | * (String) text - The text child data for the element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
350 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
351 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
352 | * A new XML DOM element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
353 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
354 | xmlElement: function (name) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
355 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
356 | // FIXME: this should also support attrs argument in object notation |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
357 | if (!name) { return null; } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
358 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
359 | var node = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
360 | if (window.ActiveXObject) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
361 | node = new ActiveXObject("Microsoft.XMLDOM").createElement(name); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
362 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
363 | node = document.createElement(name); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
364 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
365 | // use node._realname to store the case-sensitive version of the tag |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
366 | // name, since some browsers will force tagnames to all lowercase. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
367 | // this is needed for the <vCard/> tag in XMPP specifically. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
368 | if (node.tagName != name) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
369 | node.setAttribute("_realname", name); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
370 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
371 | // FIXME: this should throw errors if args are the wrong type or |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
372 | // there are more than two optional args |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
373 | var a, i; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
374 | for (a = 1; a < arguments.length; a++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
375 | if (!arguments[a]) { continue; } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
376 | if (typeof(arguments[a]) == "string" || |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
377 | typeof(arguments[a]) == "number") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
378 | node.appendChild(Strophe.xmlTextNode(arguments[a])); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
379 | } else if (typeof(arguments[a]) == "object" && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
380 | typeof(arguments[a]['sort']) == "function") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
381 | for (i = 0; i < arguments[a].length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
382 | if (typeof(arguments[a][i]) == "object" && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
383 | typeof(arguments[a][i]['sort']) == "function") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
384 | node.setAttribute(arguments[a][i][0], |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
385 | arguments[a][i][1]); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
386 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
387 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
388 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
389 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
390 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
391 | return node; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
392 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
393 | /* Function: xmlescape |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
394 | * Excapes invalid xml characters. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
395 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
396 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
397 | * (String) text - text to escape. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
398 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
399 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
400 | * Escaped text. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
401 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
402 | xmlescape: function(text) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
403 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
404 | text = text.replace(/\&/g, "&"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
405 | text = text.replace(/</g, "<"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
406 | text = text.replace(/>/g, ">"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
407 | return text; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
408 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
409 | /** Function: xmlTextNode |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
410 | * Creates an XML DOM text node. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
411 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
412 | * Provides a cross implementation version of document.createTextNode. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
413 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
414 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
415 | * (String) text - The content of the text node. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
416 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
417 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
418 | * A new XML DOM text node. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
419 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
420 | xmlTextNode: function (text) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
421 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
422 | //ensure text is escaped |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
423 | text = Strophe.xmlescape(text); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
424 | if (window.ActiveXObject) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
425 | return new ActiveXObject("Microsoft.XMLDOM").createTextNode(text); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
426 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
427 | return document.createTextNode(text); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
428 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
429 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
430 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
431 | /** Function: getText |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
432 | * Get the concatenation of all text children of an element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
433 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
434 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
435 | * (XMLElement) elem - A DOM element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
436 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
437 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
438 | * A String with the concatenated text of all text element children. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
439 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
440 | getText: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
441 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
442 | if (!elem) return null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
443 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
444 | var str = ""; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
445 | if (elem.childNodes.length === 0 && elem.nodeType == |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
446 | Strophe.ElementType.TEXT) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
447 | str += elem.nodeValue; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
448 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
449 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
450 | for (var i = 0; i < elem.childNodes.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
451 | if (elem.childNodes[i].nodeType == Strophe.ElementType.TEXT) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
452 | str += elem.childNodes[i].nodeValue; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
453 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
454 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
455 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
456 | return str; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
457 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
458 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
459 | /** Function: copyElement |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
460 | * Copy an XML DOM element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
461 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
462 | * This function copies a DOM element and all its descendants and returns |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
463 | * the new copy. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
464 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
465 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
466 | * (XMLElement) elem - A DOM element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
467 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
468 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
469 | * A new, copied DOM element tree. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
470 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
471 | copyElement: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
472 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
473 | var i, el; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
474 | if (elem.nodeType == Strophe.ElementType.NORMAL) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
475 | el = Strophe.xmlElement(elem.tagName); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
476 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
477 | for (i = 0; i < elem.attributes.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
478 | el.setAttribute(elem.attributes[i].nodeName.toLowerCase(), |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
479 | elem.attributes[i].value); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
480 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
481 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
482 | for (i = 0; i < elem.childNodes.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
483 | el.appendChild(Strophe.copyElement(elem.childNodes[i])); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
484 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
485 | } else if (elem.nodeType == Strophe.ElementType.TEXT) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
486 | el = Strophe.xmlTextNode(elem.nodeValue); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
487 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
488 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
489 | return el; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
490 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
491 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
492 | /** Function: escapeJid |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
493 | * Escape a JID. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
494 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
495 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
496 | * (String) jid - A JID. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
497 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
498 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
499 | * An escaped JID String. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
500 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
501 | escapeJid: function (jid) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
502 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
503 | var user = jid.split("@"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
504 | if (user.length == 1) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
505 | // no user so nothing to escape |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
506 | return jid; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
507 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
508 | var host = user.splice(user.length - 1, 1)[0]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
509 | user = user.join("@") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
510 | .replace(/^\s+|\s+$/g, '') |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
511 | .replace(/\\/g, "\\5c") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
512 | .replace(/ /g, "\\20") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
513 | .replace(/\"/g, "\\22") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
514 | .replace(/\&/g, "\\26") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
515 | .replace(/\'/g, "\\27") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
516 | .replace(/\//g, "\\2f") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
517 | .replace(/:/g, "\\3a") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
518 | .replace(/</g, "\\3c") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
519 | .replace(/>/g, "\\3e") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
520 | .replace(/@/g, "\\40"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
521 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
522 | return [user, host].join("@"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
523 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
524 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
525 | /** Function: unescapeJid |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
526 | * Unescape a JID. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
527 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
528 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
529 | * (String) jid - A JID. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
530 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
531 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
532 | * An unescaped JID String. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
533 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
534 | unescapeJid: function (jid) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
535 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
536 | return jid.replace(/\\20/g, " ") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
537 | .replace(/\\22/g, '"') |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
538 | .replace(/\\26/g, "&") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
539 | .replace(/\\27/g, "'") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
540 | .replace(/\\2f/g, "/") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
541 | .replace(/\\3a/g, ":") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
542 | .replace(/\\3c/g, "<") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
543 | .replace(/\\3e/g, ">") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
544 | .replace(/\\40/g, "@") |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
545 | .replace(/\\5c/g, "\\"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
546 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
547 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
548 | /** Function: getNodeFromJid |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
549 | * Get the node portion of a JID String. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
550 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
551 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
552 | * (String) jid - A JID. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
553 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
554 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
555 | * A String containing the node. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
556 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
557 | getNodeFromJid: function (jid) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
558 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
559 | if (jid.indexOf("@") < 0) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
560 | return null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
561 | return Strophe.escapeJid(jid).split("@")[0]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
562 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
563 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
564 | /** Function: getDomainFromJid |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
565 | * Get the domain portion of a JID String. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
566 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
567 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
568 | * (String) jid - A JID. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
569 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
570 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
571 | * A String containing the domain. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
572 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
573 | getDomainFromJid: function (jid) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
574 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
575 | var bare = Strophe.escapeJid(Strophe.getBareJidFromJid(jid)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
576 | if (bare.indexOf("@") < 0) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
577 | return bare; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
578 | else |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
579 | return bare.split("@")[1]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
580 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
581 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
582 | /** Function: getResourceFromJid |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
583 | * Get the resource portion of a JID String. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
584 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
585 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
586 | * (String) jid - A JID. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
587 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
588 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
589 | * A String containing the resource. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
590 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
591 | getResourceFromJid: function (jid) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
592 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
593 | var j = Strophe.escapeJid(jid); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
594 | var s = j.indexOf("/"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
595 | if (s < 0) return null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
596 | return j.substr(s+1); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
597 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
598 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
599 | /** Function: getBareJidFromJid |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
600 | * Get the bare JID from a JID String. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
601 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
602 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
603 | * (String) jid - A JID. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
604 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
605 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
606 | * A String containing the bare JID. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
607 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
608 | getBareJidFromJid: function (jid) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
609 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
610 | return this.escapeJid(jid).split("/")[0]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
611 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
612 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
613 | /** Function: log |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
614 | * User overrideable logging function. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
615 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
616 | * This function is called whenever the Strophe library calls any |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
617 | * of the logging functions. The default implementation of this |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
618 | * function does nothing. If client code wishes to handle the logging |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
619 | * messages, it should override this with |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
620 | * > Strophe.log = function (level, msg) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
621 | * > (user code here) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
622 | * > }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
623 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
624 | * Please note that data sent and received over the wire is logged |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
625 | * via Strophe.Connection.rawInput() and Strophe.Connection.rawOutput(). |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
626 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
627 | * The different levels and their meanings are |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
628 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
629 | * DEBUG - Messages useful for debugging purposes. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
630 | * INFO - Informational messages. This is mostly information like |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
631 | * 'disconnect was called' or 'SASL auth succeeded'. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
632 | * WARN - Warnings about potential problems. This is mostly used |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
633 | * to report transient connection errors like request timeouts. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
634 | * ERROR - Some error occurred. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
635 | * FATAL - A non-recoverable fatal error occurred. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
636 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
637 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
638 | * (Integer) level - The log level of the log message. This will |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
639 | * be one of the values in Strophe.LogLevel. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
640 | * (String) msg - The log message. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
641 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
642 | log: function (level, msg) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
643 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
644 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
645 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
646 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
647 | /** Function: debug |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
648 | * Log a message at the Strophe.LogLevel.DEBUG level. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
649 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
650 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
651 | * (String) msg - The log message. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
652 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
653 | debug: function(msg) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
654 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
655 | this.log(this.LogLevel.DEBUG, msg); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
656 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
657 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
658 | /** Function: info |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
659 | * Log a message at the Strophe.LogLevel.INFO level. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
660 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
661 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
662 | * (String) msg - The log message. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
663 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
664 | info: function (msg) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
665 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
666 | this.log(this.LogLevel.INFO, msg); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
667 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
668 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
669 | /** Function: warn |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
670 | * Log a message at the Strophe.LogLevel.WARN level. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
671 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
672 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
673 | * (String) msg - The log message. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
674 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
675 | warn: function (msg) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
676 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
677 | this.log(this.LogLevel.WARN, msg); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
678 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
679 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
680 | /** Function: error |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
681 | * Log a message at the Strophe.LogLevel.ERROR level. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
682 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
683 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
684 | * (String) msg - The log message. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
685 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
686 | error: function (msg) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
687 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
688 | this.log(this.LogLevel.ERROR, msg); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
689 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
690 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
691 | /** Function: fatal |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
692 | * Log a message at the Strophe.LogLevel.FATAL level. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
693 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
694 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
695 | * (String) msg - The log message. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
696 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
697 | fatal: function (msg) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
698 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
699 | this.log(this.LogLevel.FATAL, msg); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
700 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
701 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
702 | /** Function: serialize |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
703 | * Render a DOM element and all descendants to a String. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
704 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
705 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
706 | * (XMLElement) elem - A DOM element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
707 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
708 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
709 | * The serialized element tree as a String. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
710 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
711 | serialize: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
712 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
713 | var result; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
714 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
715 | if (!elem) return null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
716 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
717 | if (typeof(elem["tree"]) === "function") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
718 | elem = elem.tree(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
719 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
720 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
721 | var nodeName = elem.nodeName; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
722 | var i, child; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
723 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
724 | if (elem.getAttribute("_realname")) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
725 | nodeName = elem.getAttribute("_realname"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
726 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
727 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
728 | result = "<" + nodeName; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
729 | for (i = 0; i < elem.attributes.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
730 | if(elem.attributes[i].nodeName != "_realname") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
731 | result += " " + elem.attributes[i].nodeName.toLowerCase() + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
732 | "='" + elem.attributes[i].value |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
733 | .replace("'", "'").replace("&", "&") + "'"; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
734 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
735 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
736 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
737 | if (elem.childNodes.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
738 | result += ">"; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
739 | for (i = 0; i < elem.childNodes.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
740 | child = elem.childNodes[i]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
741 | if (child.nodeType == Strophe.ElementType.NORMAL) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
742 | // normal element, so recurse |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
743 | result += Strophe.serialize(child); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
744 | } else if (child.nodeType == Strophe.ElementType.TEXT) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
745 | // text element |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
746 | result += child.nodeValue; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
747 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
748 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
749 | result += "</" + nodeName + ">"; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
750 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
751 | result += "/>"; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
752 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
753 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
754 | return result; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
755 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
756 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
757 | /** PrivateVariable: _requestId |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
758 | * _Private_ variable that keeps track of the request ids for |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
759 | * connections. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
760 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
761 | _requestId: 0, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
762 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
763 | /** PrivateVariable: Strophe.connectionPlugins |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
764 | * _Private_ variable Used to store plugin names that need |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
765 | * initialization on Strophe.Connection construction. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
766 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
767 | _connectionPlugins: {}, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
768 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
769 | /** Function: addConnectionPlugin |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
770 | * Extends the Strophe.Connection object with the given plugin. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
771 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
772 | * Paramaters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
773 | * (String) name - The name of the extension. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
774 | * (Object) ptype - The plugin's prototype. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
775 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
776 | addConnectionPlugin: function (name, ptype) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
777 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
778 | Strophe._connectionPlugins[name] = ptype; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
779 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
780 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
781 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
782 | /** Class: Strophe.Builder |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
783 | * XML DOM builder. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
784 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
785 | * This object provides an interface similar to JQuery but for building |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
786 | * DOM element easily and rapidly. All the functions except for toString() |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
787 | * and tree() return the object, so calls can be chained. Here's an |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
788 | * example using the $iq() builder helper. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
789 | * > $iq({to: 'you': from: 'me': type: 'get', id: '1'}) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
790 | * > .c('query', {xmlns: 'strophe:example'}) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
791 | * > .c('example') |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
792 | * > .toString() |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
793 | * The above generates this XML fragment |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
794 | * > <iq to='you' from='me' type='get' id='1'> |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
795 | * > <query xmlns='strophe:example'> |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
796 | * > <example/> |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
797 | * > </query> |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
798 | * > </iq> |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
799 | * The corresponding DOM manipulations to get a similar fragment would be |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
800 | * a lot more tedious and probably involve several helper variables. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
801 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
802 | * Since adding children makes new operations operate on the child, up() |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
803 | * is provided to traverse up the tree. To add two children, do |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
804 | * > builder.c('child1', ...).up().c('child2', ...) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
805 | * The next operation on the Builder will be relative to the second child. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
806 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
807 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
808 | /** Constructor: Strophe.Builder |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
809 | * Create a Strophe.Builder object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
810 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
811 | * The attributes should be passed in object notation. For example |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
812 | * > var b = new Builder('message', {to: 'you', from: 'me'}); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
813 | * or |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
814 | * > var b = new Builder('messsage', {'xml:lang': 'en'}); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
815 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
816 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
817 | * (String) name - The name of the root element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
818 | * (Object) attrs - The attributes for the root element in object notation. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
819 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
820 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
821 | * A new Strophe.Builder. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
822 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
823 | Strophe.Builder = function (name, attrs) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
824 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
825 | // Set correct namespace for jabber:client elements |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
826 | if (name == "presence" || name == "message" || name == "iq") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
827 | if (attrs && !attrs.xmlns) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
828 | attrs.xmlns = Strophe.NS.CLIENT; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
829 | else if (!attrs) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
830 | attrs = {xmlns: Strophe.NS.CLIENT}; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
831 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
832 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
833 | // Holds the tree being built. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
834 | this.nodeTree = this._makeNode(name, attrs); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
835 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
836 | // Points to the current operation node. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
837 | this.node = this.nodeTree; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
838 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
839 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
840 | Strophe.Builder.prototype = { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
841 | /** Function: tree |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
842 | * Return the DOM tree. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
843 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
844 | * This function returns the current DOM tree as an element object. This |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
845 | * is suitable for passing to functions like Strophe.Connection.send(). |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
846 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
847 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
848 | * The DOM tree as a element object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
849 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
850 | tree: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
851 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
852 | return this.nodeTree; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
853 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
854 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
855 | /** Function: toString |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
856 | * Serialize the DOM tree to a String. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
857 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
858 | * This function returns a string serialization of the current DOM |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
859 | * tree. It is often used internally to pass data to a |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
860 | * Strophe.Request object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
861 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
862 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
863 | * The serialized DOM tree in a String. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
864 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
865 | toString: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
866 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
867 | return Strophe.serialize(this.nodeTree); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
868 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
869 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
870 | /** Function: up |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
871 | * Make the current parent element the new current element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
872 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
873 | * This function is often used after c() to traverse back up the tree. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
874 | * For example, to add two children to the same element |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
875 | * > builder.c('child1', {}).up().c('child2', {}); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
876 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
877 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
878 | * The Stophe.Builder object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
879 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
880 | up: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
881 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
882 | this.node = this.node.parentNode; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
883 | return this; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
884 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
885 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
886 | /** Function: attrs |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
887 | * Add or modify attributes of the current element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
888 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
889 | * The attributes should be passed in object notation. This function |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
890 | * does not move the current element pointer. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
891 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
892 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
893 | * (Object) moreattrs - The attributes to add/modify in object notation. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
894 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
895 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
896 | * The Strophe.Builder object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
897 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
898 | attrs: function (moreattrs) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
899 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
900 | for (var k in moreattrs) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
901 | this.node.setAttribute(k, moreattrs[k]); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
902 | return this; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
903 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
904 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
905 | /** Function: c |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
906 | * Add a child to the current element and make it the new current |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
907 | * element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
908 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
909 | * This function moves the current element pointer to the child. If you |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
910 | * need to add another child, it is necessary to use up() to go back |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
911 | * to the parent in the tree. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
912 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
913 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
914 | * (String) name - The name of the child. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
915 | * (Object) attrs - The attributes of the child in object notation. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
916 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
917 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
918 | * The Strophe.Builder object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
919 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
920 | c: function (name, attrs) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
921 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
922 | var child = this._makeNode(name, attrs); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
923 | this.node.appendChild(child); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
924 | this.node = child; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
925 | return this; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
926 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
927 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
928 | /** Function: cnode |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
929 | * Add a child to the current element and make it the new current |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
930 | * element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
931 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
932 | * This function is the same as c() except that instead of using a |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
933 | * name and an attributes object to create the child it uses an |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
934 | * existing DOM element object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
935 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
936 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
937 | * (XMLElement) elem - A DOM element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
938 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
939 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
940 | * The Strophe.Builder object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
941 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
942 | cnode: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
943 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
944 | this.node.appendChild(elem); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
945 | this.node = elem; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
946 | return this; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
947 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
948 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
949 | /** Function: t |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
950 | * Add a child text element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
951 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
952 | * This *does not* make the child the new current element since there |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
953 | * are no children of text elements. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
954 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
955 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
956 | * (String) text - The text data to append to the current element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
957 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
958 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
959 | * The Strophe.Builder object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
960 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
961 | t: function (text) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
962 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
963 | var child = Strophe.xmlTextNode(text); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
964 | this.node.appendChild(child); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
965 | return this; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
966 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
967 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
968 | /** PrivateFunction: _makeNode |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
969 | * _Private_ helper function to create a DOM element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
970 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
971 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
972 | * (String) name - The name of the new element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
973 | * (Object) attrs - The attributes for the new element in object |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
974 | * notation. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
975 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
976 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
977 | * A new DOM element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
978 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
979 | _makeNode: function (name, attrs) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
980 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
981 | var node = Strophe.xmlElement(name); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
982 | for (var k in attrs) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
983 | node.setAttribute(k, attrs[k]); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
984 | return node; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
985 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
986 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
987 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
988 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
989 | /** PrivateClass: Strophe.Handler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
990 | * _Private_ helper class for managing stanza handlers. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
991 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
992 | * A Strophe.Handler encapsulates a user provided callback function to be |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
993 | * executed when matching stanzas are received by the connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
994 | * Handlers can be either one-off or persistant depending on their |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
995 | * return value. Returning true will cause a Handler to remain active, and |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
996 | * returning false will remove the Handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
997 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
998 | * Users will not use Strophe.Handler objects directly, but instead they |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
999 | * will use Strophe.Connection.addHandler() and |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1000 | * Strophe.Connection.deleteHandler(). |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1001 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1002 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1003 | /** PrivateConstructor: Strophe.Handler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1004 | * Create and initialize a new Strophe.Handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1005 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1006 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1007 | * (Function) handler - A function to be executed when the handler is run. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1008 | * (String) ns - The namespace to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1009 | * (String) name - The element name to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1010 | * (String) type - The element type to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1011 | * (String) id - The element id attribute to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1012 | * (String) from - The element from attribute to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1013 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1014 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1015 | * A new Strophe.Handler object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1016 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1017 | Strophe.Handler = function (handler, ns, name, type, id, from) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1018 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1019 | this.handler = handler; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1020 | this.ns = ns; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1021 | this.name = name; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1022 | this.type = type; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1023 | this.id = id; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1024 | this.from = from; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1025 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1026 | // whether the handler is a user handler or a system handler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1027 | this.user = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1028 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1029 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1030 | Strophe.Handler.prototype = { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1031 | /** PrivateFunction: isMatch |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1032 | * Tests if a stanza matches the Strophe.Handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1033 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1034 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1035 | * (XMLElement) elem - The XML element to test. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1036 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1037 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1038 | * true if the stanza matches and false otherwise. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1039 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1040 | isMatch: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1041 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1042 | var nsMatch, i; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1043 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1044 | nsMatch = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1045 | if (!this.ns) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1046 | nsMatch = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1047 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1048 | var self = this; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1049 | Strophe.forEachChild(elem, null, function (elem) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1050 | if (elem.getAttribute("xmlns") == self.ns) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1051 | nsMatch = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1052 | }); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1053 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1054 | nsMatch = nsMatch || elem.getAttribute("xmlns") == this.ns; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1055 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1056 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1057 | if (nsMatch && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1058 | (!this.name || Strophe.isTagEqual(elem, this.name)) && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1059 | (!this.type || elem.getAttribute("type") == this.type) && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1060 | (!this.id || elem.getAttribute("id") == this.id) && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1061 | (!this.from || elem.getAttribute("from") == this.from)) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1062 | return true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1063 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1064 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1065 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1066 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1067 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1068 | /** PrivateFunction: run |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1069 | * Run the callback on a matching stanza. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1070 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1071 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1072 | * (XMLElement) elem - The DOM element that triggered the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1073 | * Strophe.Handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1074 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1075 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1076 | * A boolean indicating if the handler should remain active. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1077 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1078 | run: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1079 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1080 | var result = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1081 | try { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1082 | result = this.handler(elem); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1083 | } catch (e) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1084 | if (e.sourceURL) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1085 | Strophe.fatal("error: " + this.handler + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1086 | " " + e.sourceURL + ":" + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1087 | e.line + " - " + e.name + ": " + e.message); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1088 | } else if (e.fileName) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1089 | if (typeof(console) != "undefined") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1090 | console.trace(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1091 | console.error(this.handler, " - error - ", e, e.message); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1092 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1093 | Strophe.fatal("error: " + this.handler + " " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1094 | e.fileName + ":" + e.lineNumber + " - " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1095 | e.name + ": " + e.message); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1096 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1097 | Strophe.fatal("error: " + this.handler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1098 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1099 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1100 | throw e; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1101 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1102 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1103 | return result; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1104 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1105 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1106 | /** PrivateFunction: toString |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1107 | * Get a String representation of the Strophe.Handler object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1108 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1109 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1110 | * A String. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1111 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1112 | toString: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1113 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1114 | return "{Handler: " + this.handler + "(" + this.name + "," + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1115 | this.id + "," + this.ns + ")}"; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1116 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1117 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1118 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1119 | /** PrivateClass: Strophe.TimedHandler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1120 | * _Private_ helper class for managing timed handlers. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1121 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1122 | * A Strophe.TimedHandler encapsulates a user provided callback that |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1123 | * should be called after a certain period of time or at regular |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1124 | * intervals. The return value of the callback determines whether the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1125 | * Strophe.TimedHandler will continue to fire. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1126 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1127 | * Users will not use Strophe.TimedHandler objects directly, but instead |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1128 | * they will use Strophe.Connection.addTimedHandler() and |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1129 | * Strophe.Connection.deleteTimedHandler(). |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1130 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1131 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1132 | /** PrivateConstructor: Strophe.TimedHandler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1133 | * Create and initialize a new Strophe.TimedHandler object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1134 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1135 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1136 | * (Integer) period - The number of milliseconds to wait before the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1137 | * handler is called. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1138 | * (Function) handler - The callback to run when the handler fires. This |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1139 | * function should take no arguments. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1140 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1141 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1142 | * A new Strophe.TimedHandler object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1143 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1144 | Strophe.TimedHandler = function (period, handler) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1145 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1146 | this.period = period; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1147 | this.handler = handler; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1148 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1149 | this.lastCalled = new Date().getTime(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1150 | this.user = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1151 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1152 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1153 | Strophe.TimedHandler.prototype = { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1154 | /** PrivateFunction: run |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1155 | * Run the callback for the Strophe.TimedHandler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1156 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1157 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1158 | * true if the Strophe.TimedHandler should be called again, and false |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1159 | * otherwise. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1160 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1161 | run: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1162 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1163 | this.lastCalled = new Date().getTime(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1164 | return this.handler(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1165 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1166 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1167 | /** PrivateFunction: reset |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1168 | * Reset the last called time for the Strophe.TimedHandler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1169 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1170 | reset: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1171 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1172 | this.lastCalled = new Date().getTime(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1173 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1174 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1175 | /** PrivateFunction: toString |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1176 | * Get a string representation of the Strophe.TimedHandler object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1177 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1178 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1179 | * The string representation. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1180 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1181 | toString: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1182 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1183 | return "{TimedHandler: " + this.handler + "(" + this.period +")}"; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1184 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1185 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1186 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1187 | /** PrivateClass: Strophe.Request |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1188 | * _Private_ helper class that provides a cross implementation abstraction |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1189 | * for a BOSH related XMLHttpRequest. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1190 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1191 | * The Strophe.Request class is used internally to encapsulate BOSH request |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1192 | * information. It is not meant to be used from user's code. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1193 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1194 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1195 | /** PrivateConstructor: Strophe.Request |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1196 | * Create and initialize a new Strophe.Request object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1197 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1198 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1199 | * (XMLElement) elem - The XML data to be sent in the request. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1200 | * (Function) func - The function that will be called when the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1201 | * XMLHttpRequest readyState changes. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1202 | * (Integer) rid - The BOSH rid attribute associated with this request. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1203 | * (Integer) sends - The number of times this same request has been |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1204 | * sent. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1205 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1206 | Strophe.Request = function (elem, func, rid, sends) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1207 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1208 | this.id = ++Strophe._requestId; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1209 | this.xmlData = elem; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1210 | this.data = Strophe.serialize(elem); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1211 | // save original function in case we need to make a new request |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1212 | // from this one. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1213 | this.origFunc = func; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1214 | this.func = func; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1215 | this.rid = rid; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1216 | this.date = NaN; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1217 | this.sends = sends || 0; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1218 | this.abort = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1219 | this.dead = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1220 | this.age = function () { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1221 | if (!this.date) return 0; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1222 | var now = new Date(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1223 | return (now - this.date) / 1000; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1224 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1225 | this.timeDead = function () { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1226 | if (!this.dead) return 0; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1227 | var now = new Date(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1228 | return (now - this.dead) / 1000; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1229 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1230 | this.xhr = this._newXHR(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1231 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1232 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1233 | Strophe.Request.prototype = { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1234 | /** PrivateFunction: getResponse |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1235 | * Get a response from the underlying XMLHttpRequest. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1236 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1237 | * This function attempts to get a response from the request and checks |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1238 | * for errors. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1239 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1240 | * Throws: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1241 | * "parsererror" - A parser error occured. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1242 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1243 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1244 | * The DOM element tree of the response. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1245 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1246 | getResponse: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1247 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1248 | var node = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1249 | if (this.xhr.responseXML && this.xhr.responseXML.documentElement) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1250 | node = this.xhr.responseXML.documentElement; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1251 | if (node.tagName == "parsererror") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1252 | Strophe.error("invalid response received"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1253 | Strophe.error("responseText: " + this.xhr.responseText); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1254 | Strophe.error("responseXML: " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1255 | Strophe.serialize(this.xhr.responseXML)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1256 | throw "parsererror"; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1257 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1258 | } else if (this.xhr.responseText) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1259 | Strophe.error("invalid response received"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1260 | Strophe.error("responseText: " + this.xhr.responseText); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1261 | Strophe.error("responseXML: " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1262 | Strophe.serialize(this.xhr.responseXML)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1263 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1264 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1265 | return node; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1266 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1267 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1268 | /** PrivateFunction: _newXHR |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1269 | * _Private_ helper function to create XMLHttpRequests. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1270 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1271 | * This function creates XMLHttpRequests across all implementations. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1272 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1273 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1274 | * A new XMLHttpRequest. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1275 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1276 | _newXHR: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1277 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1278 | var xhr = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1279 | if (window.XMLHttpRequest) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1280 | xhr = new XMLHttpRequest(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1281 | if (xhr.overrideMimeType) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1282 | xhr.overrideMimeType("text/xml"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1283 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1284 | } else if (window.ActiveXObject) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1285 | xhr = new ActiveXObject("Microsoft.XMLHTTP"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1286 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1287 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1288 | xhr.onreadystatechange = this.func.prependArg(this); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1289 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1290 | return xhr; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1291 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1292 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1293 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1294 | /** Class: Strophe.Connection |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1295 | * XMPP Connection manager. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1296 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1297 | * Thie class is the main part of Strophe. It manages a BOSH connection |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1298 | * to an XMPP server and dispatches events to the user callbacks as |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1299 | * data arrives. It supports SASL PLAIN, SASL DIGEST-MD5, and legacy |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1300 | * authentication. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1301 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1302 | * After creating a Strophe.Connection object, the user will typically |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1303 | * call connect() with a user supplied callback to handle connection level |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1304 | * events like authentication failure, disconnection, or connection |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1305 | * complete. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1306 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1307 | * The user will also have several event handlers defined by using |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1308 | * addHandler() and addTimedHandler(). These will allow the user code to |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1309 | * respond to interesting stanzas or do something periodically with the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1310 | * connection. These handlers will be active once authentication is |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1311 | * finished. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1312 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1313 | * To send data to the connection, use send(). |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1314 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1315 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1316 | /** Constructor: Strophe.Connection |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1317 | * Create and initialize a Strophe.Connection object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1318 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1319 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1320 | * (String) service - The BOSH service URL. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1321 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1322 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1323 | * A new Strophe.Connection object. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1324 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1325 | Strophe.Connection = function (service) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1326 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1327 | /* The path to the httpbind service. */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1328 | this.service = service; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1329 | /* The connected JID. */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1330 | this.jid = ""; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1331 | /* request id for body tags */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1332 | this.rid = Math.floor(Math.random() * 4294967295); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1333 | /* The current session ID. */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1334 | this.sid = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1335 | this.streamId = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1336 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1337 | // SASL |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1338 | this.do_session = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1339 | this.do_bind = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1340 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1341 | // handler lists |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1342 | this.timedHandlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1343 | this.handlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1344 | this.removeTimeds = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1345 | this.removeHandlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1346 | this.addTimeds = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1347 | this.addHandlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1348 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1349 | this._idleTimeout = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1350 | this._disconnectTimeout = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1351 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1352 | this.authenticated = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1353 | this.disconnecting = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1354 | this.connected = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1355 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1356 | this.errors = 0; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1357 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1358 | this.paused = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1359 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1360 | // default BOSH window |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1361 | this.window = 5; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1362 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1363 | this._data = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1364 | this._requests = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1365 | this._uniqueId = Math.round(Math.random() * 10000); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1366 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1367 | this._sasl_success_handler = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1368 | this._sasl_failure_handler = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1369 | this._sasl_challenge_handler = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1370 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1371 | // setup onIdle callback every 1/10th of a second |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1372 | this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1373 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1374 | // initialize plugins |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1375 | for (var k in Strophe._connectionPlugins) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1376 | ptype = Strophe._connectionPlugins[k]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1377 | var F = function () {}; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1378 | F.prototype = ptype; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1379 | this[k] = new F(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1380 | this[k].init(this); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1381 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1382 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1383 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1384 | Strophe.Connection.prototype = { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1385 | /** Function: reset |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1386 | * Reset the connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1387 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1388 | * This function should be called after a connection is disconnected |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1389 | * before that connection is reused. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1390 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1391 | reset: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1392 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1393 | this.rid = Math.floor(Math.random() * 4294967295); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1394 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1395 | this.sid = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1396 | this.streamId = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1397 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1398 | // SASL |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1399 | this.do_session = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1400 | this.do_bind = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1401 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1402 | // handler lists |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1403 | this.timedHandlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1404 | this.handlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1405 | this.removeTimeds = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1406 | this.removeHandlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1407 | this.addTimeds = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1408 | this.addHandlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1409 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1410 | this.authenticated = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1411 | this.disconnecting = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1412 | this.connected = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1413 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1414 | this.errors = 0; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1415 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1416 | this._requests = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1417 | this._uniqueId = Math.round(Math.random()*10000); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1418 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1419 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1420 | /** Function: pause |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1421 | * Pause the request manager. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1422 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1423 | * This will prevent Strophe from sending any more requests to the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1424 | * server. This is very useful for temporarily pausing while a lot |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1425 | * of send() calls are happening quickly. This causes Strophe to |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1426 | * send the data in a single request, saving many request trips. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1427 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1428 | pause: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1429 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1430 | this.paused = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1431 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1432 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1433 | /** Function: resume |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1434 | * Resume the request manager. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1435 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1436 | * This resumes after pause() has been called. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1437 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1438 | resume: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1439 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1440 | this.paused = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1441 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1442 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1443 | /** Function: getUniqueId |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1444 | * Generate a unique ID for use in <iq/> elements. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1445 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1446 | * All <iq/> stanzas are required to have unique id attributes. This |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1447 | * function makes creating these easy. Each connection instance has |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1448 | * a counter which starts from zero, and the value of this counter |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1449 | * plus a colon followed by the suffix becomes the unique id. If no |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1450 | * suffix is supplied, the counter is used as the unique id. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1451 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1452 | * Suffixes are used to make debugging easier when reading the stream |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1453 | * data, and their use is recommended. The counter resets to 0 for |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1454 | * every new connection for the same reason. For connections to the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1455 | * same server that authenticate the same way, all the ids should be |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1456 | * the same, which makes it easy to see changes. This is useful for |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1457 | * automated testing as well. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1458 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1459 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1460 | * (String) suffix - A optional suffix to append to the id. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1461 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1462 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1463 | * A unique string to be used for the id attribute. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1464 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1465 | getUniqueId: function (suffix) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1466 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1467 | if (typeof(suffix) == "string" || typeof(suffix) == "number") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1468 | return ++this._uniqueId + ":" + suffix; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1469 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1470 | return ++this._uniqueId + ""; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1471 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1472 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1473 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1474 | /** Function: connect |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1475 | * Starts the connection process. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1476 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1477 | * As the connection process proceeds, the user supplied callback will |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1478 | * be triggered multiple times with status updates. The callback |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1479 | * should take two arguments - the status code and the error condition. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1480 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1481 | * The status code will be one of the values in the Strophe.Status |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1482 | * constants. The error condition will be one of the conditions |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1483 | * defined in RFC 3920 or the condition 'strophe-parsererror'. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1484 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1485 | * Please see XEP 124 for a more detailed explanation of the optional |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1486 | * parameters below. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1487 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1488 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1489 | * (String) jid - The user's JID. This may be a bare JID, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1490 | * or a full JID. If a node is not supplied, SASL ANONYMOUS |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1491 | * authentication will be attempted. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1492 | * (String) pass - The user's password. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1493 | * (Function) callback The connect callback function. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1494 | * (Integer) wait - The optional HTTPBIND wait value. This is the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1495 | * time the server will wait before returning an empty result for |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1496 | * a request. The default setting of 60 seconds is recommended. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1497 | * Other settings will require tweaks to the Strophe.TIMEOUT value. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1498 | * (Integer) hold - The optional HTTPBIND hold value. This is the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1499 | * number of connections the server will hold at one time. This |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1500 | * should almost always be set to 1 (the default). |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1501 | * (Integer) wind - The optional HTTBIND window value. This is the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1502 | * allowed range of request ids that are valid. The default is 5. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1503 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1504 | connect: function (jid, pass, callback, wait, hold, wind) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1505 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1506 | this.jid = jid; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1507 | this.pass = pass; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1508 | this.connect_callback = callback; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1509 | this.disconnecting = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1510 | this.connected = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1511 | this.authenticated = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1512 | this.errors = 0; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1513 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1514 | if (!wait) wait = 60; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1515 | if (!hold) hold = 1; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1516 | if (wind) this.window = wind; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1517 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1518 | // parse jid for domain and resource |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1519 | this.domain = Strophe.getDomainFromJid(this.jid); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1520 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1521 | // build the body tag |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1522 | var body = this._buildBody().attrs({ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1523 | to: this.domain, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1524 | "xml:lang": "en", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1525 | wait: wait, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1526 | hold: hold, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1527 | window: this.window, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1528 | content: "text/xml; charset=utf-8", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1529 | ver: "1.6", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1530 | "xmpp:version": "1.0", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1531 | "xmlns:xmpp": Strophe.NS.BOSH |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1532 | }); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1533 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1534 | this._changeConnectStatus(Strophe.Status.CONNECTING, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1535 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1536 | this._requests.push( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1537 | new Strophe.Request(body.tree(), |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1538 | this._onRequestStateChange.bind(this) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1539 | .prependArg(this._connect_cb.bind(this)), |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1540 | body.tree().getAttribute("rid"))); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1541 | this._throttledRequestHandler(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1542 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1543 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1544 | /** Function: attach |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1545 | * Attach to an already created and authenticated BOSH session. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1546 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1547 | * This function is provided to allow Strophe to attach to BOSH |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1548 | * sessions which have been created externally, perhaps by a Web |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1549 | * application. This is often used to support auto-login type features |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1550 | * without putting user credentials into the page. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1551 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1552 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1553 | * (String) jid - The full JID that is bound by the session. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1554 | * (String) sid - The SID of the BOSH session. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1555 | * (String) rid - The current RID of the BOSH session. This RID |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1556 | * will be used by the next request. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1557 | * (Function) callback The connect callback function. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1558 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1559 | attach: function (jid, sid, rid, callback) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1560 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1561 | this.jid = jid; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1562 | this.sid = sid; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1563 | this.rid = rid; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1564 | this.connect_callback = callback; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1565 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1566 | this.domain = Strophe.getDomainFromJid(this.jid); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1567 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1568 | this.authenticated = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1569 | this.connected = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1570 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1571 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1572 | /** Function: xmlInput |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1573 | * User overrideable function that receives XML data coming into the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1574 | * connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1575 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1576 | * The default function does nothing. User code can override this with |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1577 | * > Strophe.Connection.xmlInput = function (elem) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1578 | * > (user code) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1579 | * > }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1580 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1581 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1582 | * (XMLElement) elem - The XML data received by the connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1583 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1584 | xmlInput: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1585 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1586 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1587 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1588 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1589 | /** Function: xmlOutput |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1590 | * User overrideable function that receives XML data sent to the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1591 | * connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1592 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1593 | * The default function does nothing. User code can override this with |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1594 | * > Strophe.Connection.xmlOutput = function (elem) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1595 | * > (user code) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1596 | * > }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1597 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1598 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1599 | * (XMLElement) elem - The XMLdata sent by the connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1600 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1601 | xmlOutput: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1602 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1603 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1604 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1605 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1606 | /** Function: rawInput |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1607 | * User overrideable function that receives raw data coming into the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1608 | * connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1609 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1610 | * The default function does nothing. User code can override this with |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1611 | * > Strophe.Connection.rawInput = function (data) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1612 | * > (user code) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1613 | * > }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1614 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1615 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1616 | * (String) data - The data received by the connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1617 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1618 | rawInput: function (data) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1619 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1620 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1621 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1622 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1623 | /** Function: rawOutput |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1624 | * User overrideable function that receives raw data sent to the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1625 | * connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1626 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1627 | * The default function does nothing. User code can override this with |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1628 | * > Strophe.Connection.rawOutput = function (data) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1629 | * > (user code) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1630 | * > }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1631 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1632 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1633 | * (String) data - The data sent by the connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1634 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1635 | rawOutput: function (data) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1636 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1637 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1638 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1639 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1640 | /** Function: send |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1641 | * Send a stanza. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1642 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1643 | * This function is called to push data onto the send queue to |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1644 | * go out over the wire. Whenever a request is sent to the BOSH |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1645 | * server, all pending data is sent and the queue is flushed. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1646 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1647 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1648 | * (XMLElement | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1649 | * [XMLElement] | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1650 | * Strophe.Builder) elem - The stanza to send. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1651 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1652 | send: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1653 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1654 | if (elem === null) { return ; } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1655 | if (typeof(elem["sort"]) === "function") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1656 | for (var i = 0; i < elem.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1657 | this._queueData(elem[i]); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1658 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1659 | } else if (typeof(elem["tree"]) === "function") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1660 | this._queueData(elem.tree()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1661 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1662 | this._queueData(elem); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1663 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1664 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1665 | this._throttledRequestHandler(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1666 | clearTimeout(this._idleTimeout); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1667 | this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1668 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1669 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1670 | /** Function: sendIQ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1671 | * Helper function to send IQ stanzas. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1672 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1673 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1674 | * (XMLElement) elem - The stanza to send. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1675 | * (Function) callback - The callback function for a successful request. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1676 | * (Function) errback - The callback function for a failed or timed |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1677 | * out request. On timeout, the stanza will be null. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1678 | * (Integer) timeout - The time specified in milliseconds for a |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1679 | * timeout to occur. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1680 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1681 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1682 | * The id used to send the IQ. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1683 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1684 | sendIQ: function(elem, callback, errback, timeout) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1685 | var timeoutHandler = null, handler = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1686 | var that = this; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1687 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1688 | if (typeof(elem["tree"]) === "function") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1689 | elem = elem.tree(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1690 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1691 | var id = elem.getAttribute('id'); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1692 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1693 | // inject id if not found |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1694 | if (!id) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1695 | id = this.getUniqueId("sendIQ"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1696 | elem.setAttribute("id", id); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1697 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1698 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1699 | var handler = this.addHandler(function (stanza) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1700 | // remove timeout handler if there is one |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1701 | if (timeoutHandler) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1702 | that.deleteTimedHandler(timeoutHandler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1703 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1704 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1705 | var iqtype = stanza.getAttribute('type'); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1706 | if (iqtype === 'result') { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1707 | if (callback) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1708 | callback(stanza); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1709 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1710 | } else if (iqtype === 'error') { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1711 | if (errback) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1712 | errback(stanza); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1713 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1714 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1715 | throw { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1716 | name: "StropheError", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1717 | message: "Got bad IQ type of " + iqtype |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1718 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1719 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1720 | }, null, 'iq', null, id); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1721 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1722 | // if timeout specified, setup timeout handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1723 | if (timeout) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1724 | timeoutHandler = this.addTimedHandler(timeout, function () { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1725 | // get rid of normal handler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1726 | that.deleteHandler(handler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1727 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1728 | // call errback on timeout with null stanza |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1729 | if (errback) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1730 | errback(null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1731 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1732 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1733 | }); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1734 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1735 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1736 | this.send(elem); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1737 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1738 | return id; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1739 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1740 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1741 | /** PrivateFunction: _queueData |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1742 | * Queue outgoing data for later sending. Also ensures that the data |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1743 | * is a DOMElement. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1744 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1745 | _queueData: function (element) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1746 | if (element === null || |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1747 | !element["tagName"] || |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1748 | !element["childNodes"]) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1749 | throw { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1750 | name: "StropheError", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1751 | message: "Cannot queue non-DOMElement." |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1752 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1753 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1754 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1755 | this._data.push(element); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1756 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1757 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1758 | /** PrivateFunction: _sendRestart |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1759 | * Send an xmpp:restart stanza. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1760 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1761 | _sendRestart: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1762 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1763 | this._data.push("restart"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1764 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1765 | this._throttledRequestHandler(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1766 | clearTimeout(this._idleTimeout); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1767 | this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1768 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1769 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1770 | /** Function: addTimedHandler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1771 | * Add a timed handler to the connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1772 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1773 | * This function adds a timed handler. The provided handler will |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1774 | * be called every period milliseconds until it returns false, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1775 | * the connection is terminated, or the handler is removed. Handlers |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1776 | * that wish to continue being invoked should return true. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1777 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1778 | * Because of method binding it is necessary to save the result of |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1779 | * this function if you wish to remove a handler with |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1780 | * deleteTimedHandler(). |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1781 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1782 | * Note that user handlers are not active until authentication is |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1783 | * successful. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1784 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1785 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1786 | * (Integer) period - The period of the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1787 | * (Function) handler - The callback function. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1788 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1789 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1790 | * A reference to the handler that can be used to remove it. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1791 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1792 | addTimedHandler: function (period, handler) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1793 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1794 | var thand = new Strophe.TimedHandler(period, handler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1795 | this.addTimeds.push(thand); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1796 | return thand; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1797 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1798 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1799 | /** Function: deleteTimedHandler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1800 | * Delete a timed handler for a connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1801 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1802 | * This function removes a timed handler from the connection. The |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1803 | * handRef parameter is *not* the function passed to addTimedHandler(), |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1804 | * but is the reference returned from addTimedHandler(). |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1805 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1806 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1807 | * (Strophe.TimedHandler) handRef - The handler reference. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1808 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1809 | deleteTimedHandler: function (handRef) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1810 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1811 | // this must be done in the Idle loop so that we don't change |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1812 | // the handlers during iteration |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1813 | this.removeTimeds.push(handRef); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1814 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1815 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1816 | /** Function: addHandler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1817 | * Add a stanza handler for the connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1818 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1819 | * This function adds a stanza handler to the connection. The |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1820 | * handler callback will be called for any stanza that matches |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1821 | * the parameters. Note that if multiple parameters are supplied, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1822 | * they must all match for the handler to be invoked. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1823 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1824 | * The handler will receive the stanza that triggered it as its argument. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1825 | * The handler should return true if it is to be invoked again; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1826 | * returning false will remove the handler after it returns. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1827 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1828 | * As a convenience, the ns parameters applies to the top level element |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1829 | * and also any of its immediate children. This is primarily to make |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1830 | * matching /iq/query elements easy. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1831 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1832 | * The return value should be saved if you wish to remove the handler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1833 | * with deleteHandler(). |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1834 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1835 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1836 | * (Function) handler - The user callback. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1837 | * (String) ns - The namespace to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1838 | * (String) name - The stanza name to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1839 | * (String) type - The stanza type attribute to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1840 | * (String) id - The stanza id attribute to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1841 | * (String) from - The stanza from attribute to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1842 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1843 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1844 | * A reference to the handler that can be used to remove it. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1845 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1846 | addHandler: function (handler, ns, name, type, id, from) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1847 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1848 | var hand = new Strophe.Handler(handler, ns, name, type, id, from); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1849 | this.addHandlers.push(hand); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1850 | return hand; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1851 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1852 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1853 | /** Function: deleteHandler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1854 | * Delete a stanza handler for a connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1855 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1856 | * This function removes a stanza handler from the connection. The |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1857 | * handRef parameter is *not* the function passed to addHandler(), |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1858 | * but is the reference returned from addHandler(). |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1859 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1860 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1861 | * (Strophe.Handler) handRef - The handler reference. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1862 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1863 | deleteHandler: function (handRef) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1864 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1865 | // this must be done in the Idle loop so that we don't change |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1866 | // the handlers during iteration |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1867 | this.removeHandlers.push(handRef); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1868 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1869 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1870 | /** Function: disconnect |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1871 | * Start the graceful disconnection process. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1872 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1873 | * This function starts the disconnection process. This process starts |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1874 | * by sending unavailable presence and sending BOSH body of type |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1875 | * terminate. A timeout handler makes sure that disconnection happens |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1876 | * even if the BOSH server does not respond. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1877 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1878 | * The user supplied connection callback will be notified of the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1879 | * progress as this process happens. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1880 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1881 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1882 | * (String) reason - The reason the disconnect is occuring. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1883 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1884 | disconnect: function (reason) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1885 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1886 | this._changeConnectStatus(Strophe.Status.DISCONNECTING, reason); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1887 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1888 | Strophe.info("Disconnect was called because: " + reason); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1889 | if (this.connected) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1890 | // setup timeout handler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1891 | this._disconnectTimeout = this._addSysTimedHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1892 | 3000, this._onDisconnectTimeout.bind(this)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1893 | this._sendTerminate(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1894 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1895 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1896 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1897 | /** PrivateFunction: _changeConnectStatus |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1898 | * _Private_ helper function that makes sure plugins and the user's |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1899 | * callback are notified of connection status changes. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1900 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1901 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1902 | * (Integer) status - the new connection status, one of the values |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1903 | * in Strophe.Status |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1904 | * (String) condition - the error condition or null |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1905 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1906 | _changeConnectStatus: function (status, condition) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1907 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1908 | // notify all plugins listening for status changes |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1909 | for (var k in Strophe._connectionPlugins) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1910 | var plugin = this[k]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1911 | if (plugin.statusChanged) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1912 | try { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1913 | plugin.statusChanged(status, condition); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1914 | } catch (err) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1915 | Strophe.error("" + k + " plugin caused an exception " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1916 | "changing status: " + err); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1917 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1918 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1919 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1920 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1921 | // notify the user's callback |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1922 | if (this.connect_callback) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1923 | try { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1924 | this.connect_callback(status, condition); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1925 | } catch (err) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1926 | Strophe.error("User connection callback caused an " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1927 | "exception: " + err); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1928 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1929 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1930 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1931 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1932 | /** PrivateFunction: _buildBody |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1933 | * _Private_ helper function to generate the <body/> wrapper for BOSH. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1934 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1935 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1936 | * A Strophe.Builder with a <body/> element. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1937 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1938 | _buildBody: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1939 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1940 | var bodyWrap = $build('body', { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1941 | rid: this.rid++, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1942 | xmlns: Strophe.NS.HTTPBIND |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1943 | }); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1944 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1945 | if (this.sid !== null) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1946 | bodyWrap.attrs({sid: this.sid}); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1947 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1948 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1949 | return bodyWrap; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1950 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1951 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1952 | /** PrivateFunction: _removeRequest |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1953 | * _Private_ function to remove a request from the queue. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1954 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1955 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1956 | * (Strophe.Request) req - The request to remove. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1957 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1958 | _removeRequest: function (req) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1959 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1960 | Strophe.debug("removing request"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1961 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1962 | var i; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1963 | for (i = this._requests.length - 1; i >= 0; i--) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1964 | if (req == this._requests[i]) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1965 | this._requests.splice(i, 1); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1966 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1967 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1968 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1969 | // set the onreadystatechange handler to a null function so |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1970 | // that we don't get any misfires |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1971 | req.xhr.onreadystatechange = function () {}; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1972 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1973 | this._throttledRequestHandler(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1974 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1975 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1976 | /** PrivateFunction: _restartRequest |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1977 | * _Private_ function to restart a request that is presumed dead. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1978 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1979 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1980 | * (Integer) i - The index of the request in the queue. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1981 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1982 | _restartRequest: function (i) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1983 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1984 | var req = this._requests[i]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1985 | if (req.dead === null) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1986 | req.dead = new Date(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1987 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1988 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1989 | this._processRequest(i); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1990 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1991 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1992 | /** PrivateFunction: _processRequest |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1993 | * _Private_ function to process a request in the queue. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1994 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1995 | * This function takes requests off the queue and sends them and |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1996 | * restarts dead requests. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1997 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1998 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1999 | * (Integer) i - The index of the request in the queue. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2000 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2001 | _processRequest: function (i) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2002 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2003 | var req = this._requests[i]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2004 | var reqStatus = -1; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2005 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2006 | try { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2007 | if (req.xhr.readyState == 4) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2008 | reqStatus = req.xhr.status; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2009 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2010 | } catch (e) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2011 | Strophe.error("caught an error in _requests[" + i + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2012 | "], reqStatus: " + reqStatus); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2013 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2014 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2015 | if (typeof(reqStatus) == "undefined") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2016 | reqStatus = -1; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2017 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2018 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2019 | var now = new Date(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2020 | var time_elapsed = req.age(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2021 | var primaryTimeout = (!isNaN(time_elapsed) && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2022 | time_elapsed > Strophe.TIMEOUT); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2023 | var secondaryTimeout = (req.dead !== null && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2024 | req.timeDead() > Strophe.SECONDARY_TIMEOUT); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2025 | var requestCompletedWithServerError = (req.xhr.readyState == 4 && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2026 | (reqStatus < 1 || |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2027 | reqStatus >= 500)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2028 | var oldreq; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2029 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2030 | if (primaryTimeout || secondaryTimeout || |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2031 | requestCompletedWithServerError) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2032 | if (secondaryTimeout) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2033 | Strophe.error("Request " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2034 | this._requests[i].id + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2035 | " timed out (secondary), restarting"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2036 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2037 | req.abort = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2038 | req.xhr.abort(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2039 | oldreq = req; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2040 | this._requests[i] = new Strophe.Request(req.xmlData, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2041 | req.origFunc, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2042 | req.rid, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2043 | req.sends); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2044 | req = this._requests[i]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2045 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2046 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2047 | if (req.xhr.readyState === 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2048 | Strophe.debug("request id " + req.id + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2049 | "." + req.sends + " posting"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2050 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2051 | req.date = new Date(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2052 | try { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2053 | req.xhr.open("POST", this.service, true); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2054 | } catch (e) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2055 | Strophe.error("XHR open failed."); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2056 | if (!this.connected) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2057 | this._changeConnectStatus(Strophe.Status.CONNFAIL, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2058 | "bad-service"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2059 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2060 | this.disconnect(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2061 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2062 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2063 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2064 | // Fires the XHR request -- may be invoked immediately |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2065 | // or on a gradually expanding retry window for reconnects |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2066 | var sendFunc = function () { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2067 | req.xhr.send(req.data); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2068 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2069 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2070 | // Implement progressive backoff for reconnects -- |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2071 | // First retry (send == 1) should also be instantaneous |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2072 | if (req.sends > 1) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2073 | // Using a cube of the retry number creats a nicely |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2074 | // expanding retry window |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2075 | var backoff = Math.pow(req.sends, 3) * 1000; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2076 | setTimeout(sendFunc, backoff); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2077 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2078 | sendFunc(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2079 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2080 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2081 | req.sends++; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2082 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2083 | this.xmlOutput(req.xmlData); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2084 | this.rawOutput(req.data); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2085 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2086 | Strophe.debug("_throttledRequestHandler: " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2087 | (i === 0 ? "first" : "second") + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2088 | " request has readyState of " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2089 | req.xhr.readyState); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2090 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2091 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2092 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2093 | /** PrivateFunction: _throttledRequestHandler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2094 | * _Private_ function to throttle requests to the connection window. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2095 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2096 | * This function makes sure we don't send requests so fast that the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2097 | * request ids overflow the connection window in the case that one |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2098 | * request died. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2099 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2100 | _throttledRequestHandler: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2101 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2102 | if (!this._requests) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2103 | Strophe.debug("_throttledRequestHandler called with " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2104 | "undefined requests"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2105 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2106 | Strophe.debug("_throttledRequestHandler called with " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2107 | this._requests.length + " requests"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2108 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2109 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2110 | if (!this._requests || this._requests.length === 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2111 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2112 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2113 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2114 | if (this._requests.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2115 | this._processRequest(0); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2116 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2117 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2118 | if (this._requests.length > 1 && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2119 | Math.abs(this._requests[0].rid - |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2120 | this._requests[1].rid) < this.window - 1) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2121 | this._processRequest(1); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2122 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2123 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2124 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2125 | /** PrivateFunction: _onRequestStateChange |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2126 | * _Private_ handler for Strophe.Request state changes. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2127 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2128 | * This function is called when the XMLHttpRequest readyState changes. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2129 | * It contains a lot of error handling logic for the many ways that |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2130 | * requests can fail, and calls the request callback when requests |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2131 | * succeed. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2132 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2133 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2134 | * (Function) func - The handler for the request. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2135 | * (Strophe.Request) req - The request that is changing readyState. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2136 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2137 | _onRequestStateChange: function (func, req) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2138 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2139 | Strophe.debug("request id " + req.id + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2140 | "." + req.sends + " state changed to " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2141 | req.xhr.readyState); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2142 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2143 | if (req.abort) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2144 | req.abort = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2145 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2146 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2147 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2148 | // request complete |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2149 | var reqStatus; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2150 | if (req.xhr.readyState == 4) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2151 | reqStatus = 0; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2152 | try { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2153 | reqStatus = req.xhr.status; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2154 | } catch (e) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2155 | // ignore errors from undefined status attribute. works |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2156 | // around a browser bug |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2157 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2158 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2159 | if (typeof(reqStatus) == "undefined") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2160 | reqStatus = 0; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2161 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2162 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2163 | if (this.disconnecting) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2164 | if (reqStatus >= 400) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2165 | this._hitError(reqStatus); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2166 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2167 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2168 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2169 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2170 | var reqIs0 = (this._requests[0] == req); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2171 | var reqIs1 = (this._requests[1] == req); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2172 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2173 | if ((reqStatus > 0 && reqStatus < 500) || req.sends > 5) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2174 | // remove from internal queue |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2175 | this._removeRequest(req); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2176 | Strophe.debug("request id " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2177 | req.id + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2178 | " should now be removed"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2179 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2180 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2181 | // request succeeded |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2182 | if (reqStatus == 200) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2183 | // if request 1 finished, or request 0 finished and request |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2184 | // 1 is over Strophe.SECONDARY_TIMEOUT seconds old, we need to |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2185 | // restart the other - both will be in the first spot, as the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2186 | // completed request has been removed from the queue already |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2187 | if (reqIs1 || |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2188 | (reqIs0 && this._requests.length > 0 && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2189 | this._requests[0].age() > Strophe.SECONDARY_TIMEOUT)) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2190 | this._restartRequest(0); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2191 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2192 | // call handler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2193 | Strophe.debug("request id " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2194 | req.id + "." + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2195 | req.sends + " got 200"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2196 | func(req); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2197 | this.errors = 0; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2198 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2199 | Strophe.error("request id " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2200 | req.id + "." + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2201 | req.sends + " error " + reqStatus + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2202 | " happened"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2203 | if (reqStatus === 0 || |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2204 | (reqStatus >= 400 && reqStatus < 600) || |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2205 | reqStatus >= 12000) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2206 | this._hitError(reqStatus); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2207 | if (reqStatus >= 400 && reqStatus < 500) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2208 | this._changeConnectStatus(Strophe.Status.DISCONNECTING, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2209 | null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2210 | this._doDisconnect(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2211 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2212 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2213 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2214 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2215 | if (!((reqStatus > 0 && reqStatus < 10000) || |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2216 | req.sends > 5)) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2217 | this._throttledRequestHandler(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2218 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2219 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2220 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2221 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2222 | /** PrivateFunction: _hitError |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2223 | * _Private_ function to handle the error count. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2224 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2225 | * Requests are resent automatically until their error count reaches |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2226 | * 5. Each time an error is encountered, this function is called to |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2227 | * increment the count and disconnect if the count is too high. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2228 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2229 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2230 | * (Integer) reqStatus - The request status. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2231 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2232 | _hitError: function (reqStatus) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2233 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2234 | this.errors++; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2235 | Strophe.warn("request errored, status: " + reqStatus + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2236 | ", number of errors: " + this.errors); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2237 | if (this.errors > 4) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2238 | this._onDisconnectTimeout(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2239 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2240 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2241 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2242 | /** PrivateFunction: _doDisconnect |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2243 | * _Private_ function to disconnect. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2244 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2245 | * This is the last piece of the disconnection logic. This resets the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2246 | * connection and alerts the user's connection callback. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2247 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2248 | _doDisconnect: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2249 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2250 | Strophe.info("_doDisconnect was called"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2251 | this.authenticated = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2252 | this.disconnecting = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2253 | this.sid = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2254 | this.streamId = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2255 | this.rid = Math.floor(Math.random() * 4294967295); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2256 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2257 | // tell the parent we disconnected |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2258 | if (this.connected) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2259 | this._changeConnectStatus(Strophe.Status.DISCONNECTED, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2260 | this.connected = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2261 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2262 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2263 | // delete handlers |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2264 | this.handlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2265 | this.timedHandlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2266 | this.removeTimeds = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2267 | this.removeHandlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2268 | this.addTimeds = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2269 | this.addHandlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2270 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2271 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2272 | /** PrivateFunction: _dataRecv |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2273 | * _Private_ handler to processes incoming data from the the connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2274 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2275 | * Except for _connect_cb handling the initial connection request, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2276 | * this function handles the incoming data for all requests. This |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2277 | * function also fires stanza handlers that match each incoming |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2278 | * stanza. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2279 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2280 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2281 | * (Strophe.Request) req - The request that has data ready. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2282 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2283 | _dataRecv: function (req) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2284 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2285 | try { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2286 | var elem = req.getResponse(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2287 | } catch (e) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2288 | if (e != "parsererror") throw e; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2289 | this.disconnect("strophe-parsererror"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2290 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2291 | if (elem === null) return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2292 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2293 | this.xmlInput(elem); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2294 | this.rawInput(Strophe.serialize(elem)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2295 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2296 | // remove handlers scheduled for deletion |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2297 | var i, hand; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2298 | while (this.removeHandlers.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2299 | hand = this.removeHandlers.pop(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2300 | i = this.handlers.indexOf(hand); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2301 | if (i >= 0) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2302 | this.handlers.splice(i, 1); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2303 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2304 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2305 | // add handlers scheduled for addition |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2306 | while (this.addHandlers.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2307 | this.handlers.push(this.addHandlers.pop()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2308 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2309 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2310 | // handle graceful disconnect |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2311 | if (this.disconnecting && this._requests.length == 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2312 | this.deleteTimedHandler(this._disconnectTimeout); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2313 | this._disconnectTimeout = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2314 | this._doDisconnect(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2315 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2316 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2317 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2318 | var typ = elem.getAttribute("type"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2319 | var cond, conflict; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2320 | if (typ !== null && typ == "terminate") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2321 | // an error occurred |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2322 | cond = elem.getAttribute("condition"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2323 | conflict = elem.getElementsByTagName("conflict"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2324 | if (cond !== null) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2325 | if (cond == "remote-stream-error" && conflict.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2326 | cond = "conflict"; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2327 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2328 | this._changeConnectStatus(Strophe.Status.CONNFAIL, cond); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2329 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2330 | this._changeConnectStatus(Strophe.Status.CONNFAIL, "unknown"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2331 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2332 | this.disconnect(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2333 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2334 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2335 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2336 | // send each incoming stanza through the handler chain |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2337 | var self = this; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2338 | Strophe.forEachChild(elem, null, function (child) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2339 | var i, newList; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2340 | // process handlers |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2341 | newList = self.handlers; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2342 | self.handlers = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2343 | for (i = 0; i < newList.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2344 | var hand = newList[i]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2345 | if (hand.isMatch(child) && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2346 | (self.authenticated || !hand.user)) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2347 | if (hand.run(child)) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2348 | self.handlers.push(hand); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2349 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2350 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2351 | self.handlers.push(hand); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2352 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2353 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2354 | }); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2355 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2356 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2357 | /** PrivateFunction: _sendTerminate |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2358 | * _Private_ function to send initial disconnect sequence. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2359 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2360 | * This is the first step in a graceful disconnect. It sends |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2361 | * the BOSH server a terminate body and includes an unavailable |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2362 | * presence if authentication has completed. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2363 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2364 | _sendTerminate: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2365 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2366 | Strophe.info("_sendTerminate was called"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2367 | var body = this._buildBody().attrs({type: "terminate"}); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2368 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2369 | var presence, i; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2370 | if (this.authenticated) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2371 | body.c('presence', { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2372 | xmlns: Strophe.NS.CLIENT, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2373 | type: 'unavailable' |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2374 | }); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2375 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2376 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2377 | this.disconnecting = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2378 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2379 | var req = new Strophe.Request(body.tree(), |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2380 | this._onRequestStateChange.bind(this) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2381 | .prependArg(this._dataRecv.bind(this)), |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2382 | body.tree().getAttribute("rid")); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2383 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2384 | // abort and clear all waiting requests |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2385 | var r; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2386 | while (this._requests.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2387 | r = this._requests.pop(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2388 | r.xhr.abort(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2389 | r.abort = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2390 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2391 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2392 | this._requests.push(req); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2393 | this._throttledRequestHandler(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2394 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2395 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2396 | /** PrivateFunction: _connect_cb |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2397 | * _Private_ handler for initial connection request. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2398 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2399 | * This handler is used to process the initial connection request |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2400 | * response from the BOSH server. It is used to set up authentication |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2401 | * handlers and start the authentication process. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2402 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2403 | * SASL authentication will be attempted if available, otherwise |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2404 | * the code will fall back to legacy authentication. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2405 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2406 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2407 | * (Strophe.Request) req - The current request. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2408 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2409 | _connect_cb: function (req) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2410 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2411 | Strophe.info("_connect_cb was called"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2412 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2413 | this.connected = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2414 | var bodyWrap = req.getResponse(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2415 | if (!bodyWrap) return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2416 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2417 | this.xmlInput(bodyWrap); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2418 | this.rawInput(Strophe.serialize(bodyWrap)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2419 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2420 | var typ = bodyWrap.getAttribute("type"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2421 | var cond, conflict; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2422 | if (typ !== null && typ == "terminate") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2423 | // an error occurred |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2424 | cond = bodyWrap.getAttribute("condition"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2425 | conflict = bodyWrap.getElementsByTagName("conflict"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2426 | if (cond !== null) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2427 | if (cond == "remote-stream-error" && conflict.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2428 | cond = "conflict"; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2429 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2430 | this._changeConnectStatus(Strophe.Status.CONNFAIL, cond); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2431 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2432 | this._changeConnectStatus(Strophe.Status.CONNFAIL, "unknown"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2433 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2434 | return; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2435 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2436 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2437 | this.sid = bodyWrap.getAttribute("sid"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2438 | this.stream_id = bodyWrap.getAttribute("authid"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2439 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2440 | // TODO - add SASL anonymous for guest accounts |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2441 | var do_sasl_plain = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2442 | var do_sasl_digest_md5 = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2443 | var do_sasl_anonymous = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2444 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2445 | var mechanisms = bodyWrap.getElementsByTagName("mechanism"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2446 | var i, mech, auth_str, hashed_auth_str; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2447 | if (mechanisms.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2448 | for (i = 0; i < mechanisms.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2449 | mech = Strophe.getText(mechanisms[i]); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2450 | if (mech == 'DIGEST-MD5') { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2451 | do_sasl_digest_md5 = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2452 | } else if (mech == 'PLAIN') { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2453 | do_sasl_plain = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2454 | } else if (mech == 'ANONYMOUS') { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2455 | do_sasl_anonymous = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2456 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2457 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2458 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2459 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2460 | if (Strophe.getNodeFromJid(this.jid) === null && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2461 | do_sasl_anonymous) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2462 | this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2463 | this._sasl_success_handler = this._addSysHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2464 | this._sasl_success_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2465 | "success", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2466 | this._sasl_failure_handler = this._addSysHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2467 | this._sasl_failure_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2468 | "failure", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2469 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2470 | this.send($build("auth", { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2471 | xmlns: Strophe.NS.SASL, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2472 | mechanism: "ANONYMOUS" |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2473 | }).tree()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2474 | } else if (Strophe.getNodeFromJid(this.jid) === null) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2475 | // we don't have a node, which is required for non-anonymous |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2476 | // client connections |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2477 | this._changeConnectStatus(Strophe.Status.CONNFAIL, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2478 | 'x-strophe-bad-non-anon-jid'); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2479 | this.disconnect(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2480 | } else if (do_sasl_digest_md5) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2481 | this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2482 | this._sasl_challenge_handler = this._addSysHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2483 | this._sasl_challenge1_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2484 | "challenge", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2485 | this._sasl_failure_handler = this._addSysHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2486 | this._sasl_failure_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2487 | "failure", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2488 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2489 | this.send($build("auth", { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2490 | xmlns: Strophe.NS.SASL, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2491 | mechanism: "DIGEST-MD5" |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2492 | }).tree()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2493 | } else if (do_sasl_plain) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2494 | // Build the plain auth string (barejid null |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2495 | // username null password) and base 64 encoded. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2496 | auth_str = Strophe.escapeJid( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2497 | Strophe.getBareJidFromJid(this.jid)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2498 | auth_str = auth_str + "\u0000"; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2499 | auth_str = auth_str + Strophe.getNodeFromJid(this.jid); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2500 | auth_str = auth_str + "\u0000"; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2501 | auth_str = auth_str + this.pass; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2502 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2503 | this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2504 | this._sasl_success_handler = this._addSysHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2505 | this._sasl_success_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2506 | "success", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2507 | this._sasl_failure_handler = this._addSysHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2508 | this._sasl_failure_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2509 | "failure", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2510 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2511 | hashed_auth_str = encode64(auth_str); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2512 | this.send($build("auth", { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2513 | xmlns: Strophe.NS.SASL, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2514 | mechanism: "PLAIN" |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2515 | }).t(hashed_auth_str).tree()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2516 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2517 | this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2518 | this._addSysHandler(this._auth1_cb.bind(this), null, null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2519 | null, "_auth_1"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2520 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2521 | this.send($iq({ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2522 | type: "get", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2523 | to: this.domain, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2524 | id: "_auth_1" |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2525 | }).c("query", { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2526 | xmlns: Strophe.NS.AUTH |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2527 | }).c("username", {}).t(Strophe.getNodeFromJid(this.jid)).tree()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2528 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2529 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2530 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2531 | /** PrivateFunction: _sasl_challenge1_cb |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2532 | * _Private_ handler for DIGEST-MD5 SASL authentication. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2533 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2534 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2535 | * (XMLElement) elem - The challenge stanza. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2536 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2537 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2538 | * false to remove the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2539 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2540 | _sasl_challenge1_cb: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2541 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2542 | var attribMatch = /([a-z]+)=("[^"]+"|[^,"]+)(?:,|$)/; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2543 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2544 | var challenge = decode64(Strophe.getText(elem)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2545 | var cnonce = hex_md5(Math.random() * 1234567890); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2546 | var realm = ""; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2547 | var host = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2548 | var nonce = ""; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2549 | var qop = ""; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2550 | var matches; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2551 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2552 | // remove unneeded handlers |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2553 | this.deleteHandler(this._sasl_failure_handler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2554 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2555 | while (challenge.match(attribMatch)) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2556 | matches = challenge.match(attribMatch); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2557 | challenge = challenge.replace(matches[0], ""); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2558 | matches[2] = matches[2].replace(/^"(.+)"$/, "$1"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2559 | switch (matches[1]) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2560 | case "realm": |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2561 | realm = matches[2]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2562 | break; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2563 | case "nonce": |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2564 | nonce = matches[2]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2565 | break; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2566 | case "qop": |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2567 | qop = matches[2]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2568 | break; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2569 | case "host": |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2570 | host = matches[2]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2571 | break; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2572 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2573 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2574 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2575 | var digest_uri = "xmpp/" + this.domain; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2576 | if (host !== null) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2577 | digest_uri = digest_uri + "/" + host; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2578 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2579 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2580 | var A1 = str_md5(Strophe.getNodeFromJid(this.jid) + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2581 | ":" + realm + ":" + this.pass) + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2582 | ":" + nonce + ":" + cnonce; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2583 | var A2 = 'AUTHENTICATE:' + digest_uri; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2584 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2585 | var responseText = ""; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2586 | responseText += 'username="' + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2587 | Strophe.getNodeFromJid(this.jid) + '",'; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2588 | responseText += 'realm="' + realm + '",'; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2589 | responseText += 'nonce="' + nonce + '",'; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2590 | responseText += 'cnonce="' + cnonce + '",'; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2591 | responseText += 'nc="00000001",'; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2592 | responseText += 'qop="auth",'; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2593 | responseText += 'digest-uri="' + digest_uri + '",'; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2594 | responseText += 'response="' + hex_md5(hex_md5(A1) + ":" + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2595 | nonce + ":00000001:" + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2596 | cnonce + ":auth:" + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2597 | hex_md5(A2)) + '",'; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2598 | responseText += 'charset="utf-8"'; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2599 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2600 | this._sasl_challenge_handler = this._addSysHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2601 | this._sasl_challenge2_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2602 | "challenge", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2603 | this._sasl_success_handler = this._addSysHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2604 | this._sasl_success_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2605 | "success", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2606 | this._sasl_failure_handler = this._addSysHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2607 | this._sasl_failure_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2608 | "failure", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2609 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2610 | this.send($build('response', { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2611 | xmlns: Strophe.NS.SASL |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2612 | }).t(encode64(responseText)).tree()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2613 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2614 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2615 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2616 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2617 | /** PrivateFunction: _sasl_challenge2_cb |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2618 | * _Private_ handler for second step of DIGEST-MD5 SASL authentication. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2619 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2620 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2621 | * (XMLElement) elem - The challenge stanza. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2622 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2623 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2624 | * false to remove the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2625 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2626 | _sasl_challenge2_cb: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2627 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2628 | // remove unneeded handlers |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2629 | this.deleteHandler(this._sasl_success_handler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2630 | this.deleteHandler(this._sasl_failure_handler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2631 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2632 | this._sasl_success_handler = this._addSysHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2633 | this._sasl_success_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2634 | "success", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2635 | this._sasl_failure_handler = this._addSysHandler( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2636 | this._sasl_failure_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2637 | "failure", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2638 | this.send($build('response', {xmlns: Strophe.NS.SASL}).tree()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2639 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2640 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2641 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2642 | /** PrivateFunction: _auth1_cb |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2643 | * _Private_ handler for legacy authentication. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2644 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2645 | * This handler is called in response to the initial <iq type='get'/> |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2646 | * for legacy authentication. It builds an authentication <iq/> and |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2647 | * sends it, creating a handler (calling back to _auth2_cb()) to |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2648 | * handle the result |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2649 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2650 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2651 | * (XMLElement) elem - The stanza that triggered the callback. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2652 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2653 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2654 | * false to remove the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2655 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2656 | _auth1_cb: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2657 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2658 | var use_digest = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2659 | var check_query, check_digest; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2660 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2661 | if (elem.getAttribute("type") == "result") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2662 | // Find digest |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2663 | check_query = elem.childNodes[0]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2664 | if (check_query) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2665 | check_digest = check_query.getElementsByTagName("digest")[0]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2666 | if (check_digest) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2667 | use_digest = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2668 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2669 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2670 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2671 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2672 | // Use digest or plaintext depending on the server features |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2673 | var iq = $iq({type: "set", id: "_auth_2"}) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2674 | .c('query', {xmlns: Strophe.NS.AUTH}) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2675 | .c('username', {}).t(Strophe.getNodeFromJid(this.jid)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2676 | if (use_digest) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2677 | iq.up().c("digest", {}) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2678 | .t(hex_sha1(this.stream_id + this.pass)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2679 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2680 | iq.up().c('password', {}).t(this.pass); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2681 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2682 | if (!Strophe.getResourceFromJid(this.jid)) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2683 | // since the user has not supplied a resource, we pick |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2684 | // a default one here. unlike other auth methods, the server |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2685 | // cannot do this for us. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2686 | this.jid = Strophe.getBareJidFromJid(this.jid) + '/strophe'; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2687 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2688 | iq.up().c('resource', {}).t(Strophe.getResourceFromJid(this.jid)); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2689 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2690 | this._addSysHandler(this._auth2_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2691 | null, null, "_auth_2"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2692 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2693 | this.send(iq.tree()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2694 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2695 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2696 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2697 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2698 | /** PrivateFunction: _sasl_success_cb |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2699 | * _Private_ handler for succesful SASL authentication. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2700 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2701 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2702 | * (XMLElement) elem - The matching stanza. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2703 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2704 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2705 | * false to remove the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2706 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2707 | _sasl_success_cb: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2708 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2709 | Strophe.info("SASL authentication succeeded."); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2710 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2711 | // remove old handlers |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2712 | this.deleteHandler(this._sasl_failure_handler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2713 | this._sasl_failure_handler = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2714 | if (this._sasl_challenge_handler) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2715 | this.deleteHandler(this._sasl_challenge_handler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2716 | this._sasl_challenge_handler = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2717 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2718 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2719 | this._addSysHandler(this._sasl_auth1_cb.bind(this), null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2720 | "stream:features", null, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2721 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2722 | // we must send an xmpp:restart now |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2723 | this._sendRestart(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2724 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2725 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2726 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2727 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2728 | /** PrivateFunction: _sasl_auth1_cb |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2729 | * _Private_ handler to start stream binding. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2730 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2731 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2732 | * (XMLElement) elem - The matching stanza. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2733 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2734 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2735 | * false to remove the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2736 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2737 | _sasl_auth1_cb: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2738 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2739 | var i, child; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2740 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2741 | for (i = 0; i < elem.childNodes.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2742 | child = elem.childNodes[i]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2743 | if (child.nodeName == 'bind') { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2744 | this.do_bind = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2745 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2746 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2747 | if (child.nodeName == 'session') { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2748 | this.do_session = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2749 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2750 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2751 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2752 | if (!this.do_bind) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2753 | this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2754 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2755 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2756 | this._addSysHandler(this._sasl_bind_cb.bind(this), null, null, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2757 | null, "_bind_auth_2"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2758 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2759 | var resource = Strophe.getResourceFromJid(this.jid); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2760 | if (resource) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2761 | this.send($iq({type: "set", id: "_bind_auth_2"}) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2762 | .c('bind', {xmlns: Strophe.NS.BIND}) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2763 | .c('resource', {}).t(resource).tree()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2764 | else |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2765 | this.send($iq({type: "set", id: "_bind_auth_2"}) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2766 | .c('bind', {xmlns: Strophe.NS.BIND}) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2767 | .tree()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2768 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2769 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2770 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2771 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2772 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2773 | /** PrivateFunction: _sasl_bind_cb |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2774 | * _Private_ handler for binding result and session start. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2775 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2776 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2777 | * (XMLElement) elem - The matching stanza. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2778 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2779 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2780 | * false to remove the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2781 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2782 | _sasl_bind_cb: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2783 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2784 | if (elem.getAttribute("type") == "error") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2785 | Strophe.info("SASL binding failed."); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2786 | this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2787 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2788 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2789 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2790 | // TODO - need to grab errors |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2791 | var bind = elem.getElementsByTagName("bind"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2792 | var jidNode; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2793 | if (bind.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2794 | // Grab jid |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2795 | jidNode = bind[0].getElementsByTagName("jid"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2796 | if (jidNode.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2797 | this.jid = Strophe.getText(jidNode[0]); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2798 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2799 | if (this.do_session) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2800 | this._addSysHandler(this._sasl_session_cb.bind(this), |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2801 | null, null, null, "_session_auth_2"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2802 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2803 | this.send($iq({type: "set", id: "_session_auth_2"}) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2804 | .c('session', {xmlns: Strophe.NS.SESSION}) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2805 | .tree()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2806 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2807 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2808 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2809 | Strophe.info("SASL binding failed."); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2810 | this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2811 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2812 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2813 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2814 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2815 | /** PrivateFunction: _sasl_session_cb |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2816 | * _Private_ handler to finish successful SASL connection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2817 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2818 | * This sets Connection.authenticated to true on success, which |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2819 | * starts the processing of user handlers. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2820 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2821 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2822 | * (XMLElement) elem - The matching stanza. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2823 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2824 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2825 | * false to remove the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2826 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2827 | _sasl_session_cb: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2828 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2829 | if (elem.getAttribute("type") == "result") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2830 | this.authenticated = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2831 | this._changeConnectStatus(Strophe.Status.CONNECTED, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2832 | } else if (elem.getAttribute("type") == "error") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2833 | Strophe.info("Session creation failed."); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2834 | this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2835 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2836 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2837 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2838 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2839 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2840 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2841 | /** PrivateFunction: _sasl_failure_cb |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2842 | * _Private_ handler for SASL authentication failure. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2843 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2844 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2845 | * (XMLElement) elem - The matching stanza. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2846 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2847 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2848 | * false to remove the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2849 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2850 | _sasl_failure_cb: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2851 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2852 | // delete unneeded handlers |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2853 | if (this._sasl_success_handler) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2854 | this.deleteHandler(this._sasl_success_handler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2855 | this._sasl_success_handler = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2856 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2857 | if (this._sasl_challenge_handler) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2858 | this.deleteHandler(this._sasl_challenge_handler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2859 | this._sasl_challenge_handler = null; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2860 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2861 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2862 | this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2863 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2864 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2865 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2866 | /** PrivateFunction: _auth2_cb |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2867 | * _Private_ handler to finish legacy authentication. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2868 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2869 | * This handler is called when the result from the jabber:iq:auth |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2870 | * <iq/> stanza is returned. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2871 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2872 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2873 | * (XMLElement) elem - The stanza that triggered the callback. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2874 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2875 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2876 | * false to remove the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2877 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2878 | _auth2_cb: function (elem) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2879 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2880 | if (elem.getAttribute("type") == "result") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2881 | this.authenticated = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2882 | this._changeConnectStatus(Strophe.Status.CONNECTED, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2883 | } else if (elem.getAttribute("type") == "error") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2884 | this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2885 | this.disconnect(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2886 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2887 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2888 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2889 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2890 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2891 | /** PrivateFunction: _addSysTimedHandler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2892 | * _Private_ function to add a system level timed handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2893 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2894 | * This function is used to add a Strophe.TimedHandler for the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2895 | * library code. System timed handlers are allowed to run before |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2896 | * authentication is complete. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2897 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2898 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2899 | * (Integer) period - The period of the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2900 | * (Function) handler - The callback function. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2901 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2902 | _addSysTimedHandler: function (period, handler) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2903 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2904 | var thand = new Strophe.TimedHandler(period, handler); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2905 | thand.user = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2906 | this.addTimeds.push(thand); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2907 | return thand; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2908 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2909 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2910 | /** PrivateFunction: _addSysHandler |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2911 | * _Private_ function to add a system level stanza handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2912 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2913 | * This function is used to add a Strophe.Handler for the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2914 | * library code. System stanza handlers are allowed to run before |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2915 | * authentication is complete. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2916 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2917 | * Parameters: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2918 | * (Function) handler - The callback function. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2919 | * (String) ns - The namespace to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2920 | * (String) name - The stanza name to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2921 | * (String) type - The stanza type attribute to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2922 | * (String) id - The stanza id attribute to match. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2923 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2924 | _addSysHandler: function (handler, ns, name, type, id) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2925 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2926 | var hand = new Strophe.Handler(handler, ns, name, type, id); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2927 | hand.user = false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2928 | this.addHandlers.push(hand); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2929 | return hand; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2930 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2931 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2932 | /** PrivateFunction: _onDisconnectTimeout |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2933 | * _Private_ timeout handler for handling non-graceful disconnection. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2934 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2935 | * If the graceful disconnect process does not complete within the |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2936 | * time allotted, this handler finishes the disconnect anyway. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2937 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2938 | * Returns: |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2939 | * false to remove the handler. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2940 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2941 | _onDisconnectTimeout: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2942 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2943 | Strophe.info("_onDisconnectTimeout was called"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2944 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2945 | // cancel all remaining requests and clear the queue |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2946 | var req; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2947 | while (this._requests.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2948 | req = this._requests.pop(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2949 | req.xhr.abort(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2950 | req.abort = true; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2951 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2952 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2953 | // actually disconnect |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2954 | this._doDisconnect(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2955 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2956 | return false; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2957 | }, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2958 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2959 | /** PrivateFunction: _onIdle |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2960 | * _Private_ handler to process events during idle cycle. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2961 | * |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2962 | * This handler is called every 100ms to fire timed handlers that |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2963 | * are ready and keep poll requests going. |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2964 | */ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2965 | _onIdle: function () |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2966 | { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2967 | var i, thand, since, newList; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2968 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2969 | // remove timed handlers that have been scheduled for deletion |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2970 | while (this.removeTimeds.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2971 | thand = this.removeTimeds.pop(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2972 | i = this.timedHandlers.indexOf(thand); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2973 | if (i >= 0) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2974 | this.timedHandlers.splice(i, 1); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2975 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2976 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2977 | // add timed handlers scheduled for addition |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2978 | while (this.addTimeds.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2979 | this.timedHandlers.push(this.addTimeds.pop()); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2980 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2981 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2982 | // call ready timed handlers |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2983 | var now = new Date().getTime(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2984 | newList = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2985 | for (i = 0; i < this.timedHandlers.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2986 | thand = this.timedHandlers[i]; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2987 | if (this.authenticated || !thand.user) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2988 | since = thand.lastCalled + thand.period; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2989 | if (since - now <= 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2990 | if (thand.run()) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2991 | newList.push(thand); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2992 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2993 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2994 | newList.push(thand); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2995 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2996 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2997 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2998 | this.timedHandlers = newList; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2999 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3000 | var body, time_elapsed; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3001 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3002 | // if no requests are in progress, poll |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3003 | if (this.authenticated && this._requests.length === 0 && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3004 | this._data.length === 0 && !this.disconnecting) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3005 | Strophe.info("no requests during idle cycle, sending " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3006 | "blank request"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3007 | this._data.push(null); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3008 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3009 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3010 | if (this._requests.length < 2 && this._data.length > 0 && |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3011 | !this.paused) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3012 | body = this._buildBody(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3013 | for (i = 0; i < this._data.length; i++) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3014 | if (this._data[i] !== null) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3015 | if (this._data[i] === "restart") { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3016 | body.attrs({ |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3017 | to: this.domain, |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3018 | "xml:lang": "en", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3019 | "xmpp:restart": "true", |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3020 | "xmlns:xmpp": Strophe.NS.BOSH |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3021 | }) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3022 | } else { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3023 | body.cnode(this._data[i]).up(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3024 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3025 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3026 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3027 | delete this._data; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3028 | this._data = []; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3029 | this._requests.push( |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3030 | new Strophe.Request(body.tree(), |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3031 | this._onRequestStateChange.bind(this) |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3032 | .prependArg(this._dataRecv.bind(this)), |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3033 | body.tree().getAttribute("rid"))); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3034 | this._processRequest(this._requests.length - 1); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3035 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3036 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3037 | if (this._requests.length > 0) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3038 | time_elapsed = this._requests[0].age(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3039 | if (this._requests[0].dead !== null) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3040 | if (this._requests[0].timeDead() > |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3041 | Strophe.SECONDARY_TIMEOUT) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3042 | this._throttledRequestHandler(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3043 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3044 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3045 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3046 | if (time_elapsed > Strophe.TIMEOUT) { |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3047 | Strophe.warn("Request " + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3048 | this._requests[0].id + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3049 | " timed out, over " + Strophe.TIMEOUT + |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3050 | " seconds since last activity"); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3051 | this._throttledRequestHandler(); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3052 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3053 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3054 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3055 | // reactivate the timer |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3056 | clearTimeout(this._idleTimeout); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3057 | this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3058 | } |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3059 | }; |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3060 | |
7c8fb429c2c5
Add js/strophe/ directory containing Strophe
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3061 |