source: trunk/instant_messenger/js/client.js @ 268

Revision 268, 2.2 KB checked in by niltonneto, 16 years ago (diff)
  • Property svn:executable set to *
Line 
1var con = new IMConnector;
2var disconnected = false;
3
4function client()
5{
6        var jabber = new Jabber;
7        var buffer = '';
8        var xtools = new XTools;
9
10        function request(data)
11        {
12                if ( !disconnected )
13                        con.go('$this.Ujabber.listen', {'stream':stream, 'request':request});
14        }
15        function stream(data)
16        {
17                function trim(pData)
18                {
19                        return pData.replace(/^ +| +$/g, '');
20                }
21                data = trim(data);
22                if ( data == 'disconnected' || data == '</stream:stream>')
23                {
24                        disconnected = true;
25                        var XmlDoc = "<disconnected>" +
26                                                        "<path>" + path_im + "</path>" +
27                                                 "</disconnected>";
28
29                        im_window.load('__contacts_im_','instant_messenger_content','<title>.::Expresso Messenger::.</title>','window.xsl','',true,true,false);
30                        im_window.elementC('__contacts_im_').innerHTML  = xtools.parse(XmlDoc,'disconnected.xsl');
31                        func.byId('img_status_im').src = im_unavailable.src;
32                        im.status = 'type=unavailable';
33                        im.statusFlag = 'unavailable';                                 
34
35                }
36                else if ( data.lastIndexOf('>') == data.length - 1)
37                {
38                        if ( buffer.length )
39                        {
40                                data = buffer + data;
41                                buffer = '';
42                        }
43
44                        // com xmlns ocorre problemas durante o parse entre
45                        // xml e xsl e por esse motivo está sendo retirado
46                        data = '<handler>' + data.replace(/ xmlns='.*?'/g, '') + '</handler>';
47
48                        if ( window.ActiveXObject )
49                        {
50                                var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
51                                xmlDoc.async = "false";
52                                xmlDoc.loadXML(data);
53                        }
54                        else
55                        {
56                                var parser = new DOMParser();
57                                var xmlDoc = parser.parseFromString(data, "text/xml");
58                        }
59
60                        var node = xmlDoc.documentElement.firstChild;
61
62                        while ( node )
63                        {
64                                try
65                                {
66                                        with ( node )
67                                        {
68                                                jabber.doIt(nodeName, node);
69                                        }
70                                        node = node.nextSibling;
71                                }
72                                catch(e)
73                                {
74                                        node = node.nextSibling;
75                                }
76                        }
77                }
78                else
79                {
80                        buffer += data;
81                }
82        }
83
84        function contacts(data)
85        {
86        }
87        request();
88        setTimeout("con.go('$this.Ujabber.getContacts', {'request':"+contacts+"})", 3000);
89}
90
91var _bkp_onbeforeunload = window.onbeforeunload;
92
93window.onbeforeunload = function()
94{
95        if ( typeof _bkp_onbeforeunload == 'function' )
96                _bkp_onbeforeunload();
97
98        disconnected = true;
99        var i;
100        for ( i in con.__HTTP__ )
101                con.__HTTP__[i].abort();
102};
Note: See TracBrowser for help on using the repository browser.