]> git.mxchange.org Git - friendica-addons.git/blob - jappixmini/jappix/js/anonymous.js
Update strings
[friendica-addons.git] / jappixmini / jappix / js / anonymous.js
1 /*
2
3 Jappix - An open social platform
4 These are the anonymous mode JS script for Jappix
5
6 -------------------------------------------------
7
8 License: AGPL
9 Authors: Vanaryon, LinkMauve
10 Last revision: 02/10/11
11
12 */
13
14 // Connected to an anonymous session
15 function anonymousConnected(con) {
16         logThis('Jappix (anonymous) is now connected.', 3);
17         
18         // Connected marker
19         CONNECTED = true;
20         CURRENT_SESSION = true;
21         RECONNECT_TRY = 0;
22         RECONNECT_TIMER = 0;
23         
24         // Not resumed?
25         if(!RESUME) {
26                 // Create the app
27                 createTalkPage();
28                 
29                 // Send our first presence
30                 firstPresence('');
31                 
32                 // Set last activity stamp
33                 LAST_ACTIVITY = getTimeStamp();
34                 
35                 // Create the new groupchat
36                 checkChatCreate(generateXID(ANONYMOUS_ROOM, 'groupchat'), 'groupchat');
37                 
38                 // Remove some nasty elements for the anonymous mode
39                 $('.tools-mucadmin, .tools-add').remove();
40         }
41         
42         // Resumed
43         else {
44                 // Send again our presence
45                 presenceSend();
46                 
47                 // Change the title
48                 updateTitle();
49         }
50         
51         // Remove the waiting icon
52         removeGeneralWait();
53 }
54
55 // Disconnected from an anonymous session
56 function anonymousDisconnected() {
57         logThis('Jappix (anonymous) is now disconnected.', 3);
58 }
59
60 // Logins to a anonymous account
61 function anonymousLogin(server) {
62         try {
63                 // We define the http binding parameters
64                 oArgs = new Object();
65                 
66                 if(HOST_BOSH_MAIN)
67                         oArgs.httpbase = HOST_BOSH_MAIN;
68                 else
69                         oArgs.httpbase = HOST_BOSH;
70                 
71                 // We create the new http-binding connection
72                 con = new JSJaCHttpBindingConnection(oArgs);
73                 
74                 // And we handle everything that happen
75                 con.registerHandler('message', handleMessage);
76                 con.registerHandler('presence', handlePresence);
77                 con.registerHandler('iq', handleIQ);
78                 con.registerHandler('onconnect', anonymousConnected);
79                 con.registerHandler('onerror', handleError);
80                 con.registerHandler('ondisconnect', anonymousDisconnected);
81                 
82                 // We set the anonymous connection parameters
83                 oArgs = new Object();
84                 oArgs.domain = server;
85                 oArgs.authtype = 'saslanon';
86                 oArgs.resource = JAPPIX_RESOURCE + ' Anonymous (' + (new Date()).getTime() + ')';
87                 oArgs.secure = true;
88                 oArgs.xmllang = XML_LANG;
89                 
90                 // We connect !
91                 con.connect(oArgs);
92                 
93                 // Change the page title
94                 pageTitle('wait');
95         }
96         
97         catch(e) {
98                 // Logs errors
99                 logThis('Error while anonymous loggin in: ' + e, 1);
100                 
101                 // Reset Jappix
102                 anonymousDisconnected();
103                 
104                 // Open an unknown error
105                 openThisError(2);
106         }
107         
108         finally {
109                 return false;
110         }
111 }
112
113 // Addon launcher
114 function launchAnonymous() {
115         logThis('Anonymous mode detected, connecting...', 3);
116         
117         // We add the login wait div
118         showGeneralWait();
119         
120         // Get the vars
121         if(LINK_VARS['r'])
122                 ANONYMOUS_ROOM = LINK_VARS['r'];
123         if(LINK_VARS['n'])
124                 ANONYMOUS_NICK = LINK_VARS['n'];
125         
126         // Fire the login action
127         anonymousLogin(HOST_ANONYMOUS);
128 }
129
130 // Launch this addon!
131 $(document).ready(launchAnonymous);