vkhater-social_stream 0.16.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (1177) hide show
  1. data/.gitignore +15 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +10 -0
  4. data/.yardopts +2 -0
  5. data/Gemfile +17 -0
  6. data/LICENSE +20 -0
  7. data/README.rdoc +67 -0
  8. data/Rakefile +28 -0
  9. data/base/.gitignore +16 -0
  10. data/base/.rspec +1 -0
  11. data/base/.yardopts +2 -0
  12. data/base/Gemfile +10 -0
  13. data/base/LICENSE +20 -0
  14. data/base/README.rdoc +68 -0
  15. data/base/Rakefile +35 -0
  16. data/base/app/assets/images/HTML5.png +0 -0
  17. data/base/app/assets/images/HTML5_Semantics.png +0 -0
  18. data/base/app/assets/images/HTML5_Styling.png +0 -0
  19. data/base/app/assets/images/Jcrop.gif +0 -0
  20. data/base/app/assets/images/arrow-end.png +0 -0
  21. data/base/app/assets/images/arrow-start.png +0 -0
  22. data/base/app/assets/images/arrow.png +0 -0
  23. data/base/app/assets/images/big-logo.png +0 -0
  24. data/base/app/assets/images/btn/1-facebook.png +0 -0
  25. data/base/app/assets/images/btn/_notes/btn_certificates.png.mno +4 -0
  26. data/base/app/assets/images/btn/activity.png +0 -0
  27. data/base/app/assets/images/btn/arrowBlue.png +0 -0
  28. data/base/app/assets/images/btn/arrow_session_change.png +0 -0
  29. data/base/app/assets/images/btn/arrows-ffffff.png +0 -0
  30. data/base/app/assets/images/btn/bold.png +0 -0
  31. data/base/app/assets/images/btn/btn_account.png +0 -0
  32. data/base/app/assets/images/btn/btn_activities.png +0 -0
  33. data/base/app/assets/images/btn/btn_bookmark.png +0 -0
  34. data/base/app/assets/images/btn/btn_browse.png +0 -0
  35. data/base/app/assets/images/btn/btn_check.png +0 -0
  36. data/base/app/assets/images/btn/btn_close.png +0 -0
  37. data/base/app/assets/images/btn/btn_comment.png +0 -0
  38. data/base/app/assets/images/btn/btn_comment_add.png +0 -0
  39. data/base/app/assets/images/btn/btn_config.png +0 -0
  40. data/base/app/assets/images/btn/btn_date.png +0 -0
  41. data/base/app/assets/images/btn/btn_delete.png +0 -0
  42. data/base/app/assets/images/btn/btn_down.png +0 -0
  43. data/base/app/assets/images/btn/btn_edit.png +0 -0
  44. data/base/app/assets/images/btn/btn_exit.png +0 -0
  45. data/base/app/assets/images/btn/btn_find.png +0 -0
  46. data/base/app/assets/images/btn/btn_follow.png +0 -0
  47. data/base/app/assets/images/btn/btn_foward.png +0 -0
  48. data/base/app/assets/images/btn/btn_friend.png +0 -0
  49. data/base/app/assets/images/btn/btn_gallery.png +0 -0
  50. data/base/app/assets/images/btn/btn_group.png +0 -0
  51. data/base/app/assets/images/btn/btn_help.png +0 -0
  52. data/base/app/assets/images/btn/btn_home.png +0 -0
  53. data/base/app/assets/images/btn/btn_inbox.png +0 -0
  54. data/base/app/assets/images/btn/btn_info.png +0 -0
  55. data/base/app/assets/images/btn/btn_invitation.png +0 -0
  56. data/base/app/assets/images/btn/btn_like.png +0 -0
  57. data/base/app/assets/images/btn/btn_next.png +0 -0
  58. data/base/app/assets/images/btn/btn_notification.png +0 -0
  59. data/base/app/assets/images/btn/btn_notification_delete.png +0 -0
  60. data/base/app/assets/images/btn/btn_notification_read.png +0 -0
  61. data/base/app/assets/images/btn/btn_notifications.png +0 -0
  62. data/base/app/assets/images/btn/btn_page_link.png +0 -0
  63. data/base/app/assets/images/btn/btn_partner.png +0 -0
  64. data/base/app/assets/images/btn/btn_photo.png +0 -0
  65. data/base/app/assets/images/btn/btn_play.png +0 -0
  66. data/base/app/assets/images/btn/btn_printer.png +0 -0
  67. data/base/app/assets/images/btn/btn_profile.png +0 -0
  68. data/base/app/assets/images/btn/btn_rank.png +0 -0
  69. data/base/app/assets/images/btn/btn_read.png +0 -0
  70. data/base/app/assets/images/btn/btn_security.png +0 -0
  71. data/base/app/assets/images/btn/btn_send.png +0 -0
  72. data/base/app/assets/images/btn/btn_spam.png +0 -0
  73. data/base/app/assets/images/btn/btn_star.png +0 -0
  74. data/base/app/assets/images/btn/btn_tag.png +0 -0
  75. data/base/app/assets/images/btn/btn_write.png +0 -0
  76. data/base/app/assets/images/btn/close.png +0 -0
  77. data/base/app/assets/images/btn/date.png +0 -0
  78. data/base/app/assets/images/btn/delete.png +0 -0
  79. data/base/app/assets/images/btn/download.png +0 -0
  80. data/base/app/assets/images/btn/edit.png +0 -0
  81. data/base/app/assets/images/btn/error.png +0 -0
  82. data/base/app/assets/images/btn/facebook.png +0 -0
  83. data/base/app/assets/images/btn/flag.png +0 -0
  84. data/base/app/assets/images/btn/group_left.png +0 -0
  85. data/base/app/assets/images/btn/group_right.png +0 -0
  86. data/base/app/assets/images/btn/header_notifications.png +0 -0
  87. data/base/app/assets/images/btn/index_71.png +0 -0
  88. data/base/app/assets/images/btn/info.png +0 -0
  89. data/base/app/assets/images/btn/italic.png +0 -0
  90. data/base/app/assets/images/btn/like.png +0 -0
  91. data/base/app/assets/images/btn/linkedin.png +0 -0
  92. data/base/app/assets/images/btn/message_conversation.png +0 -0
  93. data/base/app/assets/images/btn/message_inbox.png +0 -0
  94. data/base/app/assets/images/btn/message_new.png +0 -0
  95. data/base/app/assets/images/btn/message_sentbox.png +0 -0
  96. data/base/app/assets/images/btn/message_trash.png +0 -0
  97. data/base/app/assets/images/btn/new.png +0 -0
  98. data/base/app/assets/images/btn/next_conference.png +0 -0
  99. data/base/app/assets/images/btn/next_space.png +0 -0
  100. data/base/app/assets/images/btn/nolike.png +0 -0
  101. data/base/app/assets/images/btn/notifications.png +0 -0
  102. data/base/app/assets/images/btn/pixel.png +0 -0
  103. data/base/app/assets/images/btn/point_blue.png +0 -0
  104. data/base/app/assets/images/btn/point_gray.png +0 -0
  105. data/base/app/assets/images/btn/post.png +0 -0
  106. data/base/app/assets/images/btn/search.png +0 -0
  107. data/base/app/assets/images/btn/search_icon.png +0 -0
  108. data/base/app/assets/images/btn/shadow.png +0 -0
  109. data/base/app/assets/images/btn/share.png +0 -0
  110. data/base/app/assets/images/btn/subtime.png +0 -0
  111. data/base/app/assets/images/btn/success.png +0 -0
  112. data/base/app/assets/images/btn/tag_cloud.png +0 -0
  113. data/base/app/assets/images/btn/twitter-follow-icon.png +0 -0
  114. data/base/app/assets/images/btn/twitter.png +0 -0
  115. data/base/app/assets/images/btn/uno.png +0 -0
  116. data/base/app/assets/images/btn/viewer.png +0 -0
  117. data/base/app/assets/images/btn/warning.png +0 -0
  118. data/base/app/assets/images/cancel.png +0 -0
  119. data/base/app/assets/images/cleditor/buttons.gif +0 -0
  120. data/base/app/assets/images/cleditor/toolbar.gif +0 -0
  121. data/base/app/assets/images/frontpage/collaborate.png +0 -0
  122. data/base/app/assets/images/frontpage/comments.png +0 -0
  123. data/base/app/assets/images/frontpage/green_sq.png +0 -0
  124. data/base/app/assets/images/frontpage/meet.png +0 -0
  125. data/base/app/assets/images/frontpage/people.png +0 -0
  126. data/base/app/assets/images/frontpage/purple_sq.png +0 -0
  127. data/base/app/assets/images/frontpage/right_comments.gif +0 -0
  128. data/base/app/assets/images/frontpage/right_conference.png +0 -0
  129. data/base/app/assets/images/frontpage/right_organizers.gif +0 -0
  130. data/base/app/assets/images/frontpage/right_people.gif +0 -0
  131. data/base/app/assets/images/frontpage/right_social.gif +0 -0
  132. data/base/app/assets/images/frontpage/right_tags.gif +0 -0
  133. data/base/app/assets/images/frontpage/right_webcam.gif +0 -0
  134. data/base/app/assets/images/frontpage/share.png +0 -0
  135. data/base/app/assets/images/frontpage/tags.png +0 -0
  136. data/base/app/assets/images/frontpage/yellow_sq.png +0 -0
  137. data/base/app/assets/images/header-logo.png +0 -0
  138. data/base/app/assets/images/html5-badge-h-css3-semantics.png +0 -0
  139. data/base/app/assets/images/icon_checkbox.png +0 -0
  140. data/base/app/assets/images/icons/favicon.ico +0 -0
  141. data/base/app/assets/images/left.png +0 -0
  142. data/base/app/assets/images/lightbox-blank.gif +0 -0
  143. data/base/app/assets/images/lightbox-btn-close.gif +0 -0
  144. data/base/app/assets/images/lightbox-btn-next.gif +0 -0
  145. data/base/app/assets/images/lightbox-btn-prev.gif +0 -0
  146. data/base/app/assets/images/lightbox-ico-loading.gif +0 -0
  147. data/base/app/assets/images/loader.gif +0 -0
  148. data/base/app/assets/images/loading.gif +0 -0
  149. data/base/app/assets/images/logo.png +0 -0
  150. data/base/app/assets/images/logos/actor/group.png +0 -0
  151. data/base/app/assets/images/logos/actor/remote_subject.png +0 -0
  152. data/base/app/assets/images/logos/actor/remote_user.png +0 -0
  153. data/base/app/assets/images/logos/actor/user.png +0 -0
  154. data/base/app/assets/images/logos/contact/group.png +0 -0
  155. data/base/app/assets/images/logos/contact/user.png +0 -0
  156. data/base/app/assets/images/logos/original/group.png +0 -0
  157. data/base/app/assets/images/logos/original/user.png +0 -0
  158. data/base/app/assets/images/logos/profile/group.png +0 -0
  159. data/base/app/assets/images/logos/profile/user.png +0 -0
  160. data/base/app/assets/images/logos/representation/group.png +0 -0
  161. data/base/app/assets/images/logos/representation/user.png +0 -0
  162. data/base/app/assets/images/mini-loading.gif +0 -0
  163. data/base/app/assets/images/right.png +0 -0
  164. data/base/app/assets/images/tipsy.gif +0 -0
  165. data/base/app/assets/javascripts/activities.js.erb +250 -0
  166. data/base/app/assets/javascripts/activities_security_chosen-modified.jquery.js +767 -0
  167. data/base/app/assets/javascripts/cheesecake.js +6 -0
  168. data/base/app/assets/javascripts/contacts.js +4 -0
  169. data/base/app/assets/javascripts/conversations.js +3 -0
  170. data/base/app/assets/javascripts/groups.js +5 -0
  171. data/base/app/assets/javascripts/invitations.js +8 -0
  172. data/base/app/assets/javascripts/jquery.ad-gallery.js +850 -0
  173. data/base/app/assets/javascripts/jquery.ad-gallery.pack.js +10 -0
  174. data/base/app/assets/javascripts/layouts.js +21 -0
  175. data/base/app/assets/javascripts/messages.js +4 -0
  176. data/base/app/assets/javascripts/posts.js +1 -0
  177. data/base/app/assets/javascripts/preloader.js +6 -0
  178. data/base/app/assets/javascripts/profiles.js +9 -0
  179. data/base/app/assets/javascripts/relation_customs.js +32 -0
  180. data/base/app/assets/javascripts/search.js.erb +3 -0
  181. data/base/app/assets/javascripts/settings.js +14 -0
  182. data/base/app/assets/javascripts/social_stream-base.js +11 -0
  183. data/base/app/assets/javascripts/ties.js +67 -0
  184. data/base/app/assets/javascripts/toolbar.js +1 -0
  185. data/base/app/assets/javascripts/users.js +2 -0
  186. data/base/app/assets/stylesheets/0_devise_sign.css +28 -0
  187. data/base/app/assets/stylesheets/_colors.scss +25 -0
  188. data/base/app/assets/stylesheets/activities.css.scss +88 -0
  189. data/base/app/assets/stylesheets/base.css.scss +257 -0
  190. data/base/app/assets/stylesheets/cheesecake.css.scss +55 -0
  191. data/base/app/assets/stylesheets/contacts.css.scss +100 -0
  192. data/base/app/assets/stylesheets/conversations.css +4 -0
  193. data/base/app/assets/stylesheets/footer.css.scss +22 -0
  194. data/base/app/assets/stylesheets/frontpage.css.scss +70 -0
  195. data/base/app/assets/stylesheets/groups.css +4 -0
  196. data/base/app/assets/stylesheets/header.css.scss +203 -0
  197. data/base/app/assets/stylesheets/home.css.scss +53 -0
  198. data/base/app/assets/stylesheets/images/add-policy.png +0 -0
  199. data/base/app/assets/stylesheets/images/fcbkcomplete/close.gif +0 -0
  200. data/base/app/assets/stylesheets/images/loading.gif +0 -0
  201. data/base/app/assets/stylesheets/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  202. data/base/app/assets/stylesheets/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  203. data/base/app/assets/stylesheets/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  204. data/base/app/assets/stylesheets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  205. data/base/app/assets/stylesheets/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  206. data/base/app/assets/stylesheets/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  207. data/base/app/assets/stylesheets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  208. data/base/app/assets/stylesheets/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  209. data/base/app/assets/stylesheets/images/ui-icons_222222_256x240.png +0 -0
  210. data/base/app/assets/stylesheets/images/ui-icons_2e83ff_256x240.png +0 -0
  211. data/base/app/assets/stylesheets/images/ui-icons_454545_256x240.png +0 -0
  212. data/base/app/assets/stylesheets/images/ui-icons_888888_256x240.png +0 -0
  213. data/base/app/assets/stylesheets/images/ui-icons_cd0a0a_256x240.png +0 -0
  214. data/base/app/assets/stylesheets/invitations.css +3 -0
  215. data/base/app/assets/stylesheets/location.css.scss +38 -0
  216. data/base/app/assets/stylesheets/menu.css.scss +19 -0
  217. data/base/app/assets/stylesheets/messages.css.scss +141 -0
  218. data/base/app/assets/stylesheets/opa75.png +0 -0
  219. data/base/app/assets/stylesheets/profiles.css +4 -0
  220. data/base/app/assets/stylesheets/relation_customs.css.scss +233 -0
  221. data/base/app/assets/stylesheets/search.css.scss +165 -0
  222. data/base/app/assets/stylesheets/settings.css +9 -0
  223. data/base/app/assets/stylesheets/social_stream-base.css +5 -0
  224. data/base/app/assets/stylesheets/ties.css.scss +12 -0
  225. data/base/app/assets/stylesheets/toolbar.css +10 -0
  226. data/base/app/assets/stylesheets/users.css +4 -0
  227. data/base/app/controllers/activities_controller.rb +19 -0
  228. data/base/app/controllers/api_controller.rb +38 -0
  229. data/base/app/controllers/authentications_controller.rb +17 -0
  230. data/base/app/controllers/cheesecake_controller.rb +9 -0
  231. data/base/app/controllers/comments_controller.rb +8 -0
  232. data/base/app/controllers/contacts_controller.rb +95 -0
  233. data/base/app/controllers/conversations_controller.rb +102 -0
  234. data/base/app/controllers/frontpage_controller.rb +23 -0
  235. data/base/app/controllers/groups_controller.rb +58 -0
  236. data/base/app/controllers/home_controller.rb +3 -0
  237. data/base/app/controllers/invitations_controller.rb +36 -0
  238. data/base/app/controllers/likes_controller.rb +41 -0
  239. data/base/app/controllers/messages_controller.rb +87 -0
  240. data/base/app/controllers/notifications_controller.rb +73 -0
  241. data/base/app/controllers/omniauth_callbacks_controller.rb +17 -0
  242. data/base/app/controllers/permissions_controller.rb +15 -0
  243. data/base/app/controllers/posts_controller.rb +3 -0
  244. data/base/app/controllers/profiles_controller.rb +9 -0
  245. data/base/app/controllers/relation/customs_controller.rb +6 -0
  246. data/base/app/controllers/search_controller.rb +79 -0
  247. data/base/app/controllers/settings_controller.rb +43 -0
  248. data/base/app/controllers/subjects_controller.rb +7 -0
  249. data/base/app/controllers/tags_controller.rb +15 -0
  250. data/base/app/controllers/ties_controller.rb +11 -0
  251. data/base/app/controllers/users_controller.rb +31 -0
  252. data/base/app/helpers/activities_helper.rb +37 -0
  253. data/base/app/helpers/contacts_helper.rb +24 -0
  254. data/base/app/helpers/groups_helper.rb +3 -0
  255. data/base/app/helpers/location_helper.rb +46 -0
  256. data/base/app/helpers/permissions_helper.rb +16 -0
  257. data/base/app/helpers/profiles_helper.rb +37 -0
  258. data/base/app/helpers/search_helper.rb +38 -0
  259. data/base/app/helpers/settings_helper.rb +9 -0
  260. data/base/app/helpers/sidebar_helper.rb +10 -0
  261. data/base/app/helpers/subjects_helper.rb +15 -0
  262. data/base/app/helpers/toolbar_helper.rb +109 -0
  263. data/base/app/helpers/users_helper.rb +4 -0
  264. data/base/app/mailers/invitation_mailer.rb +11 -0
  265. data/base/app/models/ability.rb +2 -0
  266. data/base/app/models/activity.rb +390 -0
  267. data/base/app/models/activity_object.rb +64 -0
  268. data/base/app/models/activity_object_activity.rb +14 -0
  269. data/base/app/models/activity_verb.rb +22 -0
  270. data/base/app/models/actor.rb +553 -0
  271. data/base/app/models/audience.rb +9 -0
  272. data/base/app/models/authentication.rb +3 -0
  273. data/base/app/models/comment.rb +10 -0
  274. data/base/app/models/contact.rb +209 -0
  275. data/base/app/models/group.rb +51 -0
  276. data/base/app/models/like.rb +49 -0
  277. data/base/app/models/permission.rb +52 -0
  278. data/base/app/models/post.rb +12 -0
  279. data/base/app/models/profile.rb +58 -0
  280. data/base/app/models/relation.rb +169 -0
  281. data/base/app/models/relation/custom.rb +112 -0
  282. data/base/app/models/relation/public.rb +11 -0
  283. data/base/app/models/relation/reject.rb +3 -0
  284. data/base/app/models/relation/single.rb +22 -0
  285. data/base/app/models/relation_permission.rb +4 -0
  286. data/base/app/models/tie.rb +147 -0
  287. data/base/app/models/user.rb +148 -0
  288. data/base/app/views/activities/_activity.html.erb +5 -0
  289. data/base/app/views/activities/_child.html.erb +18 -0
  290. data/base/app/views/activities/_comments.html.erb +3 -0
  291. data/base/app/views/activities/_filter.html.erb +83 -0
  292. data/base/app/views/activities/_index.html.erb +14 -0
  293. data/base/app/views/activities/_new.html.erb +56 -0
  294. data/base/app/views/activities/_options.html.erb +27 -0
  295. data/base/app/views/activities/_root.html.erb +37 -0
  296. data/base/app/views/activities/_wall.html.erb +5 -0
  297. data/base/app/views/activities/index.html.erb +0 -0
  298. data/base/app/views/activities/index.js.erb +3 -0
  299. data/base/app/views/activity_objects/_activity_object.html.erb +7 -0
  300. data/base/app/views/actors/_actor.html.erb +0 -0
  301. data/base/app/views/actors/_actor_cheesecake.html.erb +4 -0
  302. data/base/app/views/api/activity_atom_feed.atom.builder +40 -0
  303. data/base/app/views/avatars/index.html.erb +15 -0
  304. data/base/app/views/avatars/update.js.erb +15 -0
  305. data/base/app/views/cheesecake/_index.html.erb +38 -0
  306. data/base/app/views/cheesecake/index.html.erb +10 -0
  307. data/base/app/views/comments/_comment.html.erb +1 -0
  308. data/base/app/views/comments/_new.html.erb +47 -0
  309. data/base/app/views/comments/create.js.erb +10 -0
  310. data/base/app/views/comments/destroy.js.erb +1 -0
  311. data/base/app/views/contacts/_contact.html.erb +20 -0
  312. data/base/app/views/contacts/_form.html.erb +38 -0
  313. data/base/app/views/contacts/_index.html.erb +40 -0
  314. data/base/app/views/contacts/_link.html.erb +9 -0
  315. data/base/app/views/contacts/_pendings.html.erb +18 -0
  316. data/base/app/views/contacts/_suggestions.html.erb +15 -0
  317. data/base/app/views/contacts/_suggestions_and_pendings.html.erb +6 -0
  318. data/base/app/views/contacts/destroy.js.erb +6 -0
  319. data/base/app/views/contacts/edit.html.erb +6 -0
  320. data/base/app/views/contacts/index.html.erb +37 -0
  321. data/base/app/views/contacts/index.js.erb +3 -0
  322. data/base/app/views/contacts/new.html.erb +5 -0
  323. data/base/app/views/contacts/suggestion.html.erb +1 -0
  324. data/base/app/views/contacts/suggestion.js.erb +1 -0
  325. data/base/app/views/conversations/_conversation.html.erb +38 -0
  326. data/base/app/views/conversations/_conversation_full.html.erb +71 -0
  327. data/base/app/views/conversations/_conversations.html.erb +5 -0
  328. data/base/app/views/conversations/_index.html.erb +11 -0
  329. data/base/app/views/conversations/_show.html.erb +13 -0
  330. data/base/app/views/conversations/edit.html.erb +10 -0
  331. data/base/app/views/conversations/index.html.erb +15 -0
  332. data/base/app/views/conversations/index.js.erb +6 -0
  333. data/base/app/views/conversations/show.html.erb +33 -0
  334. data/base/app/views/conversations/show.js.erb +26 -0
  335. data/base/app/views/devise/passwords/edit.html.erb +21 -0
  336. data/base/app/views/devise/passwords/new.html.erb +27 -0
  337. data/base/app/views/devise/registrations/_delete_account.html.erb +20 -0
  338. data/base/app/views/devise/registrations/_edit_user.html.erb +113 -0
  339. data/base/app/views/devise/registrations/edit.html.erb +20 -0
  340. data/base/app/views/devise/registrations/new.html.erb +44 -0
  341. data/base/app/views/devise/sessions/new.html.erb +35 -0
  342. data/base/app/views/devise/shared/_links.erb +25 -0
  343. data/base/app/views/frontpage/_caracteristics.html.erb +23 -0
  344. data/base/app/views/frontpage/_social_networks.html.erb +3 -0
  345. data/base/app/views/frontpage/_sponsor.html.erb +12 -0
  346. data/base/app/views/frontpage/host_meta.xml.builder +11 -0
  347. data/base/app/views/frontpage/index.html.erb +69 -0
  348. data/base/app/views/groups/_group.html.erb +4 -0
  349. data/base/app/views/groups/_group_focus_search.html.erb +2 -0
  350. data/base/app/views/groups/_group_global_search.html.erb +2 -0
  351. data/base/app/views/groups/_group_with_details.html.erb +2 -0
  352. data/base/app/views/groups/_index.html.erb +19 -0
  353. data/base/app/views/groups/_new.html.erb +81 -0
  354. data/base/app/views/groups/_show.html.erb +33 -0
  355. data/base/app/views/groups/_tag_cloud.html.erb +25 -0
  356. data/base/app/views/groups/index.html.erb +57 -0
  357. data/base/app/views/groups/index.js.erb +1 -0
  358. data/base/app/views/groups/new.html.erb +9 -0
  359. data/base/app/views/groups/show.html.erb +1 -0
  360. data/base/app/views/groups/show.js.erb +2 -0
  361. data/base/app/views/home/_groups.html.erb +24 -0
  362. data/base/app/views/home/index.html.erb +19 -0
  363. data/base/app/views/home/index.js.erb +5 -0
  364. data/base/app/views/invitation_mailer/send_invitation.html.erb +79 -0
  365. data/base/app/views/invitation_mailer/send_invitation.text.erb +21 -0
  366. data/base/app/views/invitations/_new.html.erb +28 -0
  367. data/base/app/views/invitations/new.html.erb +9 -0
  368. data/base/app/views/invitations/new.js.erb +4 -0
  369. data/base/app/views/layouts/_account.html.erb +18 -0
  370. data/base/app/views/layouts/_flash.html.erb +5 -0
  371. data/base/app/views/layouts/_footer.html.erb +16 -0
  372. data/base/app/views/layouts/_header.erb +5 -0
  373. data/base/app/views/layouts/_header_dropdown_menu.html.erb +19 -0
  374. data/base/app/views/layouts/_header_dropdown_menu_sessions.html.erb +14 -0
  375. data/base/app/views/layouts/_header_signed_in.erb +45 -0
  376. data/base/app/views/layouts/_header_signed_out.erb +34 -0
  377. data/base/app/views/layouts/_representation.html.erb +28 -0
  378. data/base/app/views/layouts/_search.html.erb +62 -0
  379. data/base/app/views/layouts/_settings.html.erb +18 -0
  380. data/base/app/views/layouts/application.html.erb +60 -0
  381. data/base/app/views/layouts/frontpage.html.erb +43 -0
  382. data/base/app/views/likes/create.js.erb +2 -0
  383. data/base/app/views/likes/destroy.js.erb +1 -0
  384. data/base/app/views/location/_location.html.erb +3 -0
  385. data/base/app/views/location/_location_body.html.erb +18 -0
  386. data/base/app/views/message_mailer/new_message_email.html.erb +35 -0
  387. data/base/app/views/message_mailer/new_message_email.text.erb +8 -0
  388. data/base/app/views/message_mailer/reply_message_email.html.erb +35 -0
  389. data/base/app/views/message_mailer/reply_message_email.text.erb +8 -0
  390. data/base/app/views/messages/_form.html.erb +39 -0
  391. data/base/app/views/messages/_message.html.erb +31 -0
  392. data/base/app/views/messages/_new.html.erb +10 -0
  393. data/base/app/views/messages/new.html.erb +37 -0
  394. data/base/app/views/messages/new.js.erb +28 -0
  395. data/base/app/views/notification_mailer/new_notification_email.html.erb +35 -0
  396. data/base/app/views/notification_mailer/new_notification_email.text.erb +9 -0
  397. data/base/app/views/notifications/_index.html.erb +21 -0
  398. data/base/app/views/notifications/_notification.html.erb +41 -0
  399. data/base/app/views/notifications/activities/_follow.html.erb +10 -0
  400. data/base/app/views/notifications/activities/_follow.text.erb +8 -0
  401. data/base/app/views/notifications/activities/_like.html.erb +30 -0
  402. data/base/app/views/notifications/activities/_like.text.erb +23 -0
  403. data/base/app/views/notifications/activities/_make-friend.html.erb +10 -0
  404. data/base/app/views/notifications/activities/_make-friend.text.erb +7 -0
  405. data/base/app/views/notifications/activities/_post.html.erb +22 -0
  406. data/base/app/views/notifications/activities/_post.text.erb +17 -0
  407. data/base/app/views/notifications/activities/_update.html.erb +18 -0
  408. data/base/app/views/notifications/activities/_update.text.erb +15 -0
  409. data/base/app/views/notifications/index.html.erb +13 -0
  410. data/base/app/views/notifications/index.js.erb +6 -0
  411. data/base/app/views/objects/_destroy.js.erb +2 -0
  412. data/base/app/views/objects/_new_activity.html.erb +8 -0
  413. data/base/app/views/objects/_show.html.erb +3 -0
  414. data/base/app/views/permissions/_index.html.erb +35 -0
  415. data/base/app/views/permissions/index.js.erb +15 -0
  416. data/base/app/views/posts/_new_activity.html.erb +1 -0
  417. data/base/app/views/posts/_new_activity_fields.erb +7 -0
  418. data/base/app/views/posts/_post.html.erb +3 -0
  419. data/base/app/views/posts/_post_focus_search.html.erb +37 -0
  420. data/base/app/views/posts/_post_global_search.html.erb +18 -0
  421. data/base/app/views/posts/_post_with_details.html.erb +3 -0
  422. data/base/app/views/posts/create.js.erb +7 -0
  423. data/base/app/views/posts/destroy.js.erb +1 -0
  424. data/base/app/views/posts/show.html.erb +10 -0
  425. data/base/app/views/profiles/_contact.html.erb +81 -0
  426. data/base/app/views/profiles/_experience.html.erb +22 -0
  427. data/base/app/views/profiles/_personal.html.erb +74 -0
  428. data/base/app/views/profiles/_profile.html.erb +40 -0
  429. data/base/app/views/profiles/_tags.html.erb +22 -0
  430. data/base/app/views/profiles/edit.html.erb +205 -0
  431. data/base/app/views/profiles/show.html.erb +22 -0
  432. data/base/app/views/profiles/update.js.erb +20 -0
  433. data/base/app/views/relation/customs/_form.html.erb +29 -0
  434. data/base/app/views/relation/customs/_list.html.erb +63 -0
  435. data/base/app/views/relation/customs/_update_rules.js.erb +5 -0
  436. data/base/app/views/relation/customs/create.js.erb +21 -0
  437. data/base/app/views/relation/customs/index.html.erb +43 -0
  438. data/base/app/views/relation/customs/update.js.erb +11 -0
  439. data/base/app/views/search/_extended_search.html.erb +19 -0
  440. data/base/app/views/search/_form.html.erb +54 -0
  441. data/base/app/views/search/_header_search.html.erb +16 -0
  442. data/base/app/views/search/_index.html.erb +12 -0
  443. data/base/app/views/search/index.html.erb +9 -0
  444. data/base/app/views/search/index.js.erb +22 -0
  445. data/base/app/views/settings/_api_key.html.erb +26 -0
  446. data/base/app/views/settings/_destroy.html.erb +17 -0
  447. data/base/app/views/settings/_index.html.erb +8 -0
  448. data/base/app/views/settings/_notifications.html.erb +34 -0
  449. data/base/app/views/settings/index.html.erb +16 -0
  450. data/base/app/views/settings/index.js.erb +7 -0
  451. data/base/app/views/subjects/_contacts.html.erb +18 -0
  452. data/base/app/views/subjects/_show.js.erb +5 -0
  453. data/base/app/views/subjects/_subject.html.erb +8 -0
  454. data/base/app/views/subjects/_subject_with_details.html.erb +17 -0
  455. data/base/app/views/ties/index.html.erb +8 -0
  456. data/base/app/views/toolbar/_home.html.erb +15 -0
  457. data/base/app/views/toolbar/_logo.html.erb +23 -0
  458. data/base/app/views/toolbar/_messages.html.erb +11 -0
  459. data/base/app/views/toolbar/_profile.html.erb +24 -0
  460. data/base/app/views/toolbar/_subject.html.erb +10 -0
  461. data/base/app/views/users/_groups.html.erb +22 -0
  462. data/base/app/views/users/_index.html.erb +19 -0
  463. data/base/app/views/users/_show.html.erb +34 -0
  464. data/base/app/views/users/_user.html.erb +2 -0
  465. data/base/app/views/users/_user_focus_search.html.erb +2 -0
  466. data/base/app/views/users/_user_global_search.html.erb +2 -0
  467. data/base/app/views/users/_user_with_details.html.erb +2 -0
  468. data/base/app/views/users/index.html.erb +41 -0
  469. data/base/app/views/users/index.js.erb +1 -0
  470. data/base/app/views/users/info.html.erb +0 -0
  471. data/base/app/views/users/show.html.erb +1 -0
  472. data/base/app/views/users/show.js.erb +2 -0
  473. data/base/app/views/users/show.xml.builder +15 -0
  474. data/base/config/locales/en.yml +472 -0
  475. data/base/config/locales/es.yml +470 -0
  476. data/base/config/routes.rb +102 -0
  477. data/base/db/migrate/20110610112023_create_social_stream.rb +319 -0
  478. data/base/db/migrate/20110705103202_empty_ties_count.rb +17 -0
  479. data/base/db/migrate/20110712090343_remove_spheres.rb +30 -0
  480. data/base/db/migrate/20110712142140_remove_permission_function.rb +26 -0
  481. data/base/db/migrate/20110912074426_add_reject_relation.rb +29 -0
  482. data/base/db/migrate/20111124100618_object_actors.rb +52 -0
  483. data/base/db/migrate/20111221103509_add_language_field.rb +13 -0
  484. data/base/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +37 -0
  485. data/base/lib/acts_as_taggable_on/social_stream.rb +58 -0
  486. data/base/lib/generators/social_stream/base/install_generator.rb +66 -0
  487. data/base/lib/generators/social_stream/base/templates/initializer.rb +32 -0
  488. data/base/lib/generators/social_stream/base/templates/navigation.rb +4 -0
  489. data/base/lib/generators/social_stream/base/templates/relations.yml +39 -0
  490. data/base/lib/generators/social_stream/base/templates/sphinx.yml +9 -0
  491. data/base/lib/paperclip/social_stream.rb +6 -0
  492. data/base/lib/social_stream-base.rb +104 -0
  493. data/base/lib/social_stream/ability.rb +7 -0
  494. data/base/lib/social_stream/ability/base.rb +101 -0
  495. data/base/lib/social_stream/base/dependencies.rb +47 -0
  496. data/base/lib/social_stream/base/engine.rb +69 -0
  497. data/base/lib/social_stream/base/version.rb +5 -0
  498. data/base/lib/social_stream/controllers/cancan_devise_integration.rb +33 -0
  499. data/base/lib/social_stream/controllers/helpers.rb +135 -0
  500. data/base/lib/social_stream/controllers/objects.rb +39 -0
  501. data/base/lib/social_stream/d3.rb +53 -0
  502. data/base/lib/social_stream/migrations/base.rb +58 -0
  503. data/base/lib/social_stream/migrations/components.rb +19 -0
  504. data/base/lib/social_stream/models/object.rb +133 -0
  505. data/base/lib/social_stream/models/subject.rb +118 -0
  506. data/base/lib/social_stream/models/supertype.rb +37 -0
  507. data/base/lib/social_stream/populate.rb +26 -0
  508. data/base/lib/social_stream/test_helpers.rb +11 -0
  509. data/base/lib/social_stream/test_helpers/controllers.rb +122 -0
  510. data/base/lib/social_stream/toolbar_config/base.rb +94 -0
  511. data/base/lib/social_stream/views/list.rb +17 -0
  512. data/base/lib/social_stream/views/settings/base.rb +43 -0
  513. data/base/lib/social_stream/views/sidebar/base.rb +27 -0
  514. data/base/lib/tasks/db/populate.rake +241 -0
  515. data/base/lib/tasks/workers.rake +163 -0
  516. data/base/social_stream-base.gemspec +83 -0
  517. data/base/spec/controllers/comments_controller_spec.rb +66 -0
  518. data/base/spec/controllers/contacts_controller_spec.rb +111 -0
  519. data/base/spec/controllers/frontpage_controller_spec.rb +16 -0
  520. data/base/spec/controllers/groups_controller_spec.rb +178 -0
  521. data/base/spec/controllers/home_controller_spec.rb +56 -0
  522. data/base/spec/controllers/invitations_controller_spec.rb +34 -0
  523. data/base/spec/controllers/likes_controller_spec.rb +48 -0
  524. data/base/spec/controllers/notifications_controller_spec.rb +46 -0
  525. data/base/spec/controllers/permissions_controller_spec.rb +45 -0
  526. data/base/spec/controllers/posts_controller_spec.rb +233 -0
  527. data/base/spec/controllers/profiles_controller_spec.rb +102 -0
  528. data/base/spec/controllers/relation_customs_controller_spec.rb +139 -0
  529. data/base/spec/controllers/representations_spec.rb +74 -0
  530. data/base/spec/controllers/settings_controller_spec.rb +41 -0
  531. data/base/spec/controllers/subjects_controller.rb +14 -0
  532. data/base/spec/controllers/users_controller_spec.rb +98 -0
  533. data/base/spec/dummy/.gitignore +5 -0
  534. data/base/spec/dummy/Rakefile +7 -0
  535. data/base/spec/dummy/app/assets/javascripts/application.js +8 -0
  536. data/base/spec/dummy/app/assets/stylesheets/application.css +8 -0
  537. data/base/spec/dummy/app/controllers/application_controller.rb +3 -0
  538. data/base/spec/dummy/app/helpers/application_helper.rb +2 -0
  539. data/base/spec/dummy/config.ru +4 -0
  540. data/base/spec/dummy/config/application.rb +44 -0
  541. data/base/spec/dummy/config/boot.rb +10 -0
  542. data/base/spec/dummy/config/database.yml +40 -0
  543. data/base/spec/dummy/config/environment.rb +5 -0
  544. data/base/spec/dummy/config/environments/development.rb +30 -0
  545. data/base/spec/dummy/config/environments/production.rb +54 -0
  546. data/base/spec/dummy/config/environments/test.rb +40 -0
  547. data/base/spec/dummy/config/environments/test_pg.rb +35 -0
  548. data/base/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  549. data/base/spec/dummy/config/initializers/devise.rb +220 -0
  550. data/base/spec/dummy/config/initializers/inflections.rb +10 -0
  551. data/base/spec/dummy/config/initializers/mailboxer.rb +8 -0
  552. data/base/spec/dummy/config/initializers/mime_types.rb +5 -0
  553. data/base/spec/dummy/config/initializers/secret_token.rb +7 -0
  554. data/base/spec/dummy/config/initializers/session_store.rb +8 -0
  555. data/base/spec/dummy/config/initializers/social_stream.rb +32 -0
  556. data/base/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  557. data/base/spec/dummy/config/locales/en.yml +5 -0
  558. data/base/spec/dummy/config/navigation.rb +4 -0
  559. data/base/spec/dummy/config/relations.yml +39 -0
  560. data/base/spec/dummy/config/routes.rb +60 -0
  561. data/base/spec/dummy/db/schema.rb +5 -0
  562. data/base/spec/dummy/db/seeds.rb +8 -0
  563. data/base/spec/dummy/public/404.html +26 -0
  564. data/base/spec/dummy/public/422.html +26 -0
  565. data/base/spec/dummy/public/500.html +26 -0
  566. data/base/spec/dummy/public/favicon.ico +0 -0
  567. data/base/spec/dummy/script/rails +6 -0
  568. data/base/spec/factories/activity.rb +52 -0
  569. data/base/spec/factories/comment.rb +6 -0
  570. data/base/spec/factories/contact.rb +16 -0
  571. data/base/spec/factories/group.rb +5 -0
  572. data/base/spec/factories/post.rb +11 -0
  573. data/base/spec/factories/relation_custom.rb +4 -0
  574. data/base/spec/factories/tie.rb +43 -0
  575. data/base/spec/factories/user.rb +6 -0
  576. data/base/spec/integration/navigation_spec.rb +33 -0
  577. data/base/spec/models/activity_authorization_spec.rb +350 -0
  578. data/base/spec/models/activity_spec.rb +131 -0
  579. data/base/spec/models/actor_spec.rb +80 -0
  580. data/base/spec/models/contact_spec.rb +53 -0
  581. data/base/spec/models/group_spec.rb +28 -0
  582. data/base/spec/models/like_spec.rb +68 -0
  583. data/base/spec/models/post_spec.rb +63 -0
  584. data/base/spec/models/profile_spec.rb +39 -0
  585. data/base/spec/models/relation_spec.rb +78 -0
  586. data/base/spec/models/tie_spec.rb +169 -0
  587. data/base/spec/models/user_spec.rb +109 -0
  588. data/base/spec/social_stream_spec.rb +7 -0
  589. data/base/spec/spec_helper.rb +26 -0
  590. data/base/spec/support/cancan.rb +1 -0
  591. data/base/spec/support/db.rb +7 -0
  592. data/base/spec/support/devise.rb +4 -0
  593. data/base/spec/support/mock.rb +4 -0
  594. data/base/vendor/assets/javascripts/ajax.paginate.js +46 -0
  595. data/base/vendor/assets/javascripts/d3.geom.js +825 -0
  596. data/base/vendor/assets/javascripts/d3.js +4013 -0
  597. data/base/vendor/assets/javascripts/d3.layout.js +1865 -0
  598. data/base/vendor/assets/javascripts/hoverIntent.js +84 -0
  599. data/base/vendor/assets/javascripts/jqcloud-0.1.3.js +87 -0
  600. data/base/vendor/assets/javascripts/jquery.ae.image.resize.js +69 -0
  601. data/base/vendor/assets/javascripts/jquery.ba-url.js +1091 -0
  602. data/base/vendor/assets/javascripts/jquery.cleditor.min.js +31 -0
  603. data/base/vendor/assets/javascripts/jquery.fcbkcomplete.js +553 -0
  604. data/base/vendor/assets/javascripts/jquery.lightbox-with-resize-plugin.js +533 -0
  605. data/base/vendor/assets/javascripts/jquery.livequery.js +250 -0
  606. data/base/vendor/assets/javascripts/jquery.screw.js +186 -0
  607. data/base/vendor/assets/javascripts/jquery.scrollTo.min.js +11 -0
  608. data/base/vendor/assets/javascripts/jquery.tipsy.js +263 -0
  609. data/base/vendor/assets/javascripts/jquery.validate.js +1166 -0
  610. data/base/vendor/assets/javascripts/jquery.validate.old.js +1132 -0
  611. data/base/vendor/assets/javascripts/jquery.watermarkinput.js +81 -0
  612. data/base/vendor/assets/javascripts/menu.js +25 -0
  613. data/base/vendor/assets/javascripts/superfish.js +121 -0
  614. data/base/vendor/assets/stylesheets/carousel.css +23 -0
  615. data/base/vendor/assets/stylesheets/chosen-sprite.png +0 -0
  616. data/base/vendor/assets/stylesheets/chosen.css +317 -0
  617. data/base/vendor/assets/stylesheets/fcbkComplete.css +44 -0
  618. data/base/vendor/assets/stylesheets/jqcloud.css +15 -0
  619. data/base/vendor/assets/stylesheets/jquery-ui.css +620 -0
  620. data/base/vendor/assets/stylesheets/jquery.cleditor.css +24 -0
  621. data/base/vendor/assets/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  622. data/base/vendor/assets/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  623. data/base/vendor/assets/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  624. data/base/vendor/assets/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  625. data/base/vendor/assets/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  626. data/base/vendor/assets/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  627. data/base/vendor/assets/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  628. data/base/vendor/assets/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  629. data/base/vendor/assets/stylesheets/smoothness/images/ui-icons_222222_256x240.png +0 -0
  630. data/base/vendor/assets/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  631. data/base/vendor/assets/stylesheets/smoothness/images/ui-icons_454545_256x240.png +0 -0
  632. data/base/vendor/assets/stylesheets/smoothness/images/ui-icons_888888_256x240.png +0 -0
  633. data/base/vendor/assets/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  634. data/base/vendor/assets/stylesheets/smoothness/jquery-ui-1.7.3.custom.css +405 -0
  635. data/base/vendor/assets/stylesheets/smoothness/jquery-ui-1.8.4.custom.css +572 -0
  636. data/base/vendor/assets/stylesheets/tipsy.css +25 -0
  637. data/bin/social_stream +57 -0
  638. data/bin/social_stream_heroku +76 -0
  639. data/documents/.gitignore +15 -0
  640. data/documents/.rspec +1 -0
  641. data/documents/Gemfile +5 -0
  642. data/documents/MIT-LICENSE +20 -0
  643. data/documents/README.rdoc +6 -0
  644. data/documents/Rakefile +26 -0
  645. data/documents/app/assets/flash/Jplayer.swf +0 -0
  646. data/documents/app/assets/images/16/audio.png +0 -0
  647. data/documents/app/assets/images/16/btn_documents.png +0 -0
  648. data/documents/app/assets/images/16/default.png +0 -0
  649. data/documents/app/assets/images/16/doc.png +0 -0
  650. data/documents/app/assets/images/16/mpeg.png +0 -0
  651. data/documents/app/assets/images/16/pdf.png +0 -0
  652. data/documents/app/assets/images/16/photo.png +0 -0
  653. data/documents/app/assets/images/16/plain.png +0 -0
  654. data/documents/app/assets/images/16/ppt.png +0 -0
  655. data/documents/app/assets/images/16/rar.png +0 -0
  656. data/documents/app/assets/images/16/video.png +0 -0
  657. data/documents/app/assets/images/16/xls.png +0 -0
  658. data/documents/app/assets/images/16/zip.png +0 -0
  659. data/documents/app/assets/images/48/audio.png +0 -0
  660. data/documents/app/assets/images/48/default.png +0 -0
  661. data/documents/app/assets/images/48/excel.png +0 -0
  662. data/documents/app/assets/images/48/mpeg.png +0 -0
  663. data/documents/app/assets/images/48/pdf.png +0 -0
  664. data/documents/app/assets/images/48/ppt.png +0 -0
  665. data/documents/app/assets/images/48/rar.png +0 -0
  666. data/documents/app/assets/images/48/resource.png +0 -0
  667. data/documents/app/assets/images/48/video.png +0 -0
  668. data/documents/app/assets/images/48/word.png +0 -0
  669. data/documents/app/assets/images/48/zip.png +0 -0
  670. data/documents/app/assets/images/btn/btn_audio.png +0 -0
  671. data/documents/app/assets/images/btn/btn_document.png +0 -0
  672. data/documents/app/assets/images/btn/btn_excel.png +0 -0
  673. data/documents/app/assets/images/btn/btn_pdf.png +0 -0
  674. data/documents/app/assets/images/btn/btn_picture.png +0 -0
  675. data/documents/app/assets/images/btn/btn_resource.png +0 -0
  676. data/documents/app/assets/images/btn/btn_video.png +0 -0
  677. data/documents/app/assets/images/btn/btn_word.png +0 -0
  678. data/documents/app/assets/images/btn/document.png +0 -0
  679. data/documents/app/assets/javascripts/documents.js.erb +71 -0
  680. data/documents/app/assets/javascripts/social_stream-documents.js +3 -0
  681. data/documents/app/assets/stylesheets/documents.css.scss +271 -0
  682. data/documents/app/assets/stylesheets/show.css.scss +111 -0
  683. data/documents/app/assets/stylesheets/social_stream-documents.css +6 -0
  684. data/documents/app/controllers/audios_controller.rb +2 -0
  685. data/documents/app/controllers/documents_controller.rb +97 -0
  686. data/documents/app/controllers/pictures_controller.rb +2 -0
  687. data/documents/app/controllers/videos_controller.rb +2 -0
  688. data/documents/app/helpers/documents_helper.rb +30 -0
  689. data/documents/app/models/audio.rb +24 -0
  690. data/documents/app/models/document.rb +78 -0
  691. data/documents/app/models/picture.rb +30 -0
  692. data/documents/app/models/video.rb +29 -0
  693. data/documents/app/views/audios/_audio.html.erb +27 -0
  694. data/documents/app/views/audios/_audio_focus_search.html.erb +3 -0
  695. data/documents/app/views/audios/_audio_global_search.html.erb +3 -0
  696. data/documents/app/views/audios/_audio_processed.html.erb +45 -0
  697. data/documents/app/views/audios/_audio_processing.html.erb +7 -0
  698. data/documents/app/views/audios/_audio_show.html.erb +62 -0
  699. data/documents/app/views/audios/_audio_with_details.html.erb +3 -0
  700. data/documents/app/views/audios/_new.html.erb +1 -0
  701. data/documents/app/views/audios/destroy.js.erb +1 -0
  702. data/documents/app/views/audios/index.html.erb +1 -0
  703. data/documents/app/views/audios/show.html.erb +2 -0
  704. data/documents/app/views/common_documents/_document_info.html.erb +48 -0
  705. data/documents/app/views/common_documents/_edit_form.html.erb +57 -0
  706. data/documents/app/views/common_documents/_headers.html.erb +72 -0
  707. data/documents/app/views/common_documents/_index.html.erb +68 -0
  708. data/documents/app/views/common_documents/_show.html.erb +34 -0
  709. data/documents/app/views/documents/_document.html.erb +15 -0
  710. data/documents/app/views/documents/_document_focus_search.html.erb +2 -0
  711. data/documents/app/views/documents/_document_global_search.html.erb +2 -0
  712. data/documents/app/views/documents/_document_show.html.erb +7 -0
  713. data/documents/app/views/documents/_document_with_details.html.erb +13 -0
  714. data/documents/app/views/documents/_new_activity.html.erb +1 -0
  715. data/documents/app/views/documents/_new_activity_fields.html.erb +1 -0
  716. data/documents/app/views/documents/destroy.js.erb +1 -0
  717. data/documents/app/views/documents/index.html.erb +1 -0
  718. data/documents/app/views/documents/show.html.erb +2 -0
  719. data/documents/app/views/pictures/_new.html.erb +1 -0
  720. data/documents/app/views/pictures/_picture.html.erb +42 -0
  721. data/documents/app/views/pictures/_picture_focus_search.html.erb +2 -0
  722. data/documents/app/views/pictures/_picture_global_search.html.erb +2 -0
  723. data/documents/app/views/pictures/_picture_show.html.erb +26 -0
  724. data/documents/app/views/pictures/_picture_with_details.html.erb +2 -0
  725. data/documents/app/views/pictures/destroy.js.erb +1 -0
  726. data/documents/app/views/pictures/index.html.erb +1 -0
  727. data/documents/app/views/pictures/show.html.erb +2 -0
  728. data/documents/app/views/videos/_new.html.erb +1 -0
  729. data/documents/app/views/videos/_video.html.erb +29 -0
  730. data/documents/app/views/videos/_video_focus_search.html.erb +2 -0
  731. data/documents/app/views/videos/_video_global_search.html.erb +2 -0
  732. data/documents/app/views/videos/_video_processed.html.erb +50 -0
  733. data/documents/app/views/videos/_video_processing.html.erb +7 -0
  734. data/documents/app/views/videos/_video_show.html.erb +64 -0
  735. data/documents/app/views/videos/_video_with_details.html.erb +2 -0
  736. data/documents/app/views/videos/destroy.js.erb +1 -0
  737. data/documents/app/views/videos/index.html.erb +1 -0
  738. data/documents/app/views/videos/show.html.erb +2 -0
  739. data/documents/app/worker/audioencoder.rb +7 -0
  740. data/documents/app/worker/videoencoder.rb +7 -0
  741. data/documents/config/locales/en.yml +67 -0
  742. data/documents/config/locales/es.yml +67 -0
  743. data/documents/config/routes.rb +22 -0
  744. data/documents/db/migrate/20110615143707_create_social_stream_documents.rb +24 -0
  745. data/documents/db/migrate/20110922173707_add_file_processing_to_document.rb +9 -0
  746. data/documents/db/migrate/20111005112707_add_title_and_description_to_document.rb +11 -0
  747. data/documents/lib/generators/social_stream/documents/install_generator.rb +24 -0
  748. data/documents/lib/social_stream-documents.rb +25 -0
  749. data/documents/lib/social_stream/documents/engine.rb +46 -0
  750. data/documents/lib/social_stream/documents/version.rb +5 -0
  751. data/documents/lib/social_stream/migrations/documents.rb +9 -0
  752. data/documents/lib/social_stream/toolbar_config/documents.rb +27 -0
  753. data/documents/social_stream-documents.gemspec +30 -0
  754. data/documents/spec/controllers/documents_controller_spec.rb +118 -0
  755. data/documents/spec/controllers/pictures_controller_spec.rb +80 -0
  756. data/documents/spec/dummy/.gitignore +1 -0
  757. data/documents/spec/dummy/Rakefile +7 -0
  758. data/documents/spec/dummy/app/controllers/application_controller.rb +3 -0
  759. data/documents/spec/dummy/app/helpers/application_helper.rb +2 -0
  760. data/documents/spec/dummy/app/views/layouts/application.html.erb +14 -0
  761. data/documents/spec/dummy/config.ru +4 -0
  762. data/documents/spec/dummy/config/application.rb +45 -0
  763. data/documents/spec/dummy/config/boot.rb +10 -0
  764. data/documents/spec/dummy/config/database.yml +22 -0
  765. data/documents/spec/dummy/config/environment.rb +5 -0
  766. data/documents/spec/dummy/config/environments/development.rb +25 -0
  767. data/documents/spec/dummy/config/environments/production.rb +49 -0
  768. data/documents/spec/dummy/config/environments/test.rb +37 -0
  769. data/documents/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  770. data/documents/spec/dummy/config/initializers/devise.rb +176 -0
  771. data/documents/spec/dummy/config/initializers/inflections.rb +10 -0
  772. data/documents/spec/dummy/config/initializers/mime_types.rb +5 -0
  773. data/documents/spec/dummy/config/initializers/secret_token.rb +7 -0
  774. data/documents/spec/dummy/config/initializers/session_store.rb +8 -0
  775. data/documents/spec/dummy/config/locales/en.yml +5 -0
  776. data/documents/spec/dummy/config/navigation.rb +0 -0
  777. data/documents/spec/dummy/config/relations.yml +39 -0
  778. data/documents/spec/dummy/config/routes.rb +60 -0
  779. data/documents/spec/dummy/db/.gitkeep +0 -0
  780. data/documents/spec/dummy/public/404.html +26 -0
  781. data/documents/spec/dummy/public/422.html +26 -0
  782. data/documents/spec/dummy/public/500.html +26 -0
  783. data/documents/spec/dummy/public/favicon.ico +0 -0
  784. data/documents/spec/dummy/public/javascripts/application.js +2 -0
  785. data/documents/spec/dummy/public/javascripts/controls.js +965 -0
  786. data/documents/spec/dummy/public/javascripts/dragdrop.js +974 -0
  787. data/documents/spec/dummy/public/javascripts/effects.js +1123 -0
  788. data/documents/spec/dummy/public/javascripts/prototype.js +6001 -0
  789. data/documents/spec/dummy/public/javascripts/rails.js +191 -0
  790. data/documents/spec/dummy/public/stylesheets/.gitkeep +0 -0
  791. data/documents/spec/dummy/script/rails +6 -0
  792. data/documents/spec/factories/document.rb +20 -0
  793. data/documents/spec/factories/files/privado.png +0 -0
  794. data/documents/spec/factories/files/rails.png +0 -0
  795. data/documents/spec/factories/files/small.pdf +157 -0
  796. data/documents/spec/factories/picture.rb +21 -0
  797. data/documents/spec/integration/navigation_spec.rb +9 -0
  798. data/documents/spec/models/video_spec.rb +9 -0
  799. data/documents/spec/socialstream_documents_spec.rb +7 -0
  800. data/documents/spec/spec_helper.rb +46 -0
  801. data/documents/spec/support/cancan.rb +1 -0
  802. data/documents/spec/support/db.rb +8 -0
  803. data/documents/spec/support/devise.rb +4 -0
  804. data/documents/spec/support/mock.rb +4 -0
  805. data/documents/vendor/assets/javascripts/jquery.jplayer.js +78 -0
  806. data/documents/vendor/assets/stylesheets/jplayer.blue.monday.css +448 -0
  807. data/documents/vendor/assets/stylesheets/jplayer.blue.monday.jpg +0 -0
  808. data/documents/vendor/assets/stylesheets/jplayer.blue.monday.video.play.hover.png +0 -0
  809. data/documents/vendor/assets/stylesheets/jplayer.blue.monday.video.play.png +0 -0
  810. data/documents/vendor/assets/stylesheets/jquery.lightbox.css +101 -0
  811. data/documents/vendor/assets/stylesheets/pbar-ani.gif +0 -0
  812. data/events/.gitignore +10 -0
  813. data/events/Gemfile +5 -0
  814. data/events/README.rdoc +3 -0
  815. data/events/Rakefile +26 -0
  816. data/events/app/assets/javascripts/0_init.js +4 -0
  817. data/events/app/assets/javascripts/events.js.coffee +66 -0
  818. data/events/app/assets/javascripts/social_stream-events.js +1 -0
  819. data/events/app/assets/stylesheets/events.css.scss +66 -0
  820. data/events/app/assets/stylesheets/social_stream-events.css +3 -0
  821. data/events/app/controllers/events_controller.rb +40 -0
  822. data/events/app/controllers/rooms_controller.rb +7 -0
  823. data/events/app/helpers/events_helper.rb +16 -0
  824. data/events/app/models/event.rb +53 -0
  825. data/events/app/models/room.rb +8 -0
  826. data/events/app/views/events/_calendar_month.erb +1 -0
  827. data/events/app/views/events/_event.html.erb +1 -0
  828. data/events/app/views/events/_new.html.erb +40 -0
  829. data/events/app/views/events/_sidebar_calendar.html.erb +34 -0
  830. data/events/app/views/events/create.js.erb +21 -0
  831. data/events/app/views/events/destroy.js.erb +1 -0
  832. data/events/app/views/events/index.html.erb +99 -0
  833. data/events/app/views/rooms/_form.html.erb +31 -0
  834. data/events/app/views/rooms/_index.html.erb +10 -0
  835. data/events/app/views/rooms/_settings.html.erb +23 -0
  836. data/events/app/views/rooms/create.js.erb +7 -0
  837. data/events/app/views/rooms/destroy.js.erb +1 -0
  838. data/events/config/locales/en.yml +35 -0
  839. data/events/config/locales/es.yml +35 -0
  840. data/events/config/routes.rb +3 -0
  841. data/events/db/migrate/20111101193523_create_events.rb +13 -0
  842. data/events/db/migrate/20111120104349_create_rooms.rb +26 -0
  843. data/events/db/migrate/20111204155637_add_scheduler.rb +33 -0
  844. data/events/db/migrate/20111218203314_change_scheduler.rb +11 -0
  845. data/events/lib/generators/social_stream/events/install_generator.rb +24 -0
  846. data/events/lib/social_stream-events.rb +27 -0
  847. data/events/lib/social_stream/events/ability.rb +13 -0
  848. data/events/lib/social_stream/events/engine.rb +29 -0
  849. data/events/lib/social_stream/events/models/actor.rb +13 -0
  850. data/events/lib/social_stream/events/version.rb +5 -0
  851. data/events/lib/social_stream/migrations/events.rb +8 -0
  852. data/events/lib/social_stream/toolbar_config/events.rb +22 -0
  853. data/events/lib/social_stream/views/settings/events.rb +18 -0
  854. data/events/lib/social_stream/views/sidebar/events.rb +15 -0
  855. data/events/social_stream-events.gemspec +24 -0
  856. data/events/vendor/assets/images/boxy-ne.png +0 -0
  857. data/events/vendor/assets/images/boxy-nw.png +0 -0
  858. data/events/vendor/assets/images/boxy-se.png +0 -0
  859. data/events/vendor/assets/images/boxy-sw.png +0 -0
  860. data/events/vendor/assets/javascripts/fullcalendar.js +5210 -0
  861. data/events/vendor/assets/javascripts/gcal.js +112 -0
  862. data/events/vendor/assets/javascripts/jquery.boxy.js +570 -0
  863. data/events/vendor/assets/javascripts/sprintf.js +183 -0
  864. data/events/vendor/assets/stylesheets/boxy.css +49 -0
  865. data/events/vendor/assets/stylesheets/fullcalendar.css +618 -0
  866. data/events/vendor/assets/stylesheets/fullcalendar.print.css +61 -0
  867. data/lib/generators/social_stream/USAGE +6 -0
  868. data/lib/generators/social_stream/install_generator.rb +6 -0
  869. data/lib/social_stream.rb +13 -0
  870. data/lib/social_stream/release.rb +51 -0
  871. data/lib/social_stream/release/component/release.rb +29 -0
  872. data/lib/social_stream/release/component/version_file.rb +18 -0
  873. data/lib/social_stream/release/dependency_update.rb +14 -0
  874. data/lib/social_stream/release/global/release.rb +70 -0
  875. data/lib/social_stream/release/global/version_file.rb +68 -0
  876. data/lib/social_stream/version.rb +3 -0
  877. data/linkser/.gitignore +14 -0
  878. data/linkser/.rspec +1 -0
  879. data/linkser/Gemfile +5 -0
  880. data/linkser/MIT-LICENSE +20 -0
  881. data/linkser/README.rdoc +6 -0
  882. data/linkser/Rakefile +26 -0
  883. data/linkser/app/assets/javascripts/linkser.js.erb +63 -0
  884. data/linkser/app/assets/javascripts/social_stream-linkser.js +2 -0
  885. data/linkser/app/assets/stylesheets/linkser.css.scss +68 -0
  886. data/linkser/app/assets/stylesheets/social_stream-linkser.css +3 -0
  887. data/linkser/app/controllers/links_controller.rb +3 -0
  888. data/linkser/app/controllers/linkser_controller.rb +20 -0
  889. data/linkser/app/models/link.rb +47 -0
  890. data/linkser/app/views/links/_error.html.erb +4 -0
  891. data/linkser/app/views/links/_link.html.erb +37 -0
  892. data/linkser/app/views/links/_link_preview.html.erb +34 -0
  893. data/linkser/app/views/links/create.js.erb +15 -0
  894. data/linkser/app/views/links/destroy.js.erb +1 -0
  895. data/linkser/app/views/links/show.html.erb +10 -0
  896. data/linkser/config/locales/en.yml +14 -0
  897. data/linkser/config/locales/es.yml +14 -0
  898. data/linkser/config/routes.rb +3 -0
  899. data/linkser/db/migrate/20111129100618_create_social_stream_linkser.rb +21 -0
  900. data/linkser/db/migrate/20111219122952_add_width_height_to_link.rb +15 -0
  901. data/linkser/lib/generators/social_stream/linkser/install_generator.rb +24 -0
  902. data/linkser/lib/social_stream-linkser.rb +16 -0
  903. data/linkser/lib/social_stream/linkser/engine.rb +7 -0
  904. data/linkser/lib/social_stream/linkser/version.rb +5 -0
  905. data/linkser/lib/social_stream/migrations/linkser.rb +9 -0
  906. data/linkser/social_stream-linkser.gemspec +26 -0
  907. data/linkser/spec/dummy/Rakefile +7 -0
  908. data/linkser/spec/dummy/app/controllers/application_controller.rb +3 -0
  909. data/linkser/spec/dummy/app/helpers/application_helper.rb +2 -0
  910. data/linkser/spec/dummy/app/views/layouts/application.html.erb +14 -0
  911. data/linkser/spec/dummy/config.ru +4 -0
  912. data/linkser/spec/dummy/config/application.rb +45 -0
  913. data/linkser/spec/dummy/config/boot.rb +10 -0
  914. data/linkser/spec/dummy/config/database.yml +22 -0
  915. data/linkser/spec/dummy/config/environment.rb +5 -0
  916. data/linkser/spec/dummy/config/environments/development.rb +25 -0
  917. data/linkser/spec/dummy/config/environments/production.rb +49 -0
  918. data/linkser/spec/dummy/config/environments/test.rb +37 -0
  919. data/linkser/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  920. data/linkser/spec/dummy/config/initializers/devise.rb +176 -0
  921. data/linkser/spec/dummy/config/initializers/inflections.rb +10 -0
  922. data/linkser/spec/dummy/config/initializers/mime_types.rb +5 -0
  923. data/linkser/spec/dummy/config/initializers/secret_token.rb +7 -0
  924. data/linkser/spec/dummy/config/initializers/session_store.rb +8 -0
  925. data/linkser/spec/dummy/config/locales/en.yml +5 -0
  926. data/linkser/spec/dummy/config/navigation.rb +0 -0
  927. data/linkser/spec/dummy/config/relations.yml +39 -0
  928. data/linkser/spec/dummy/config/routes.rb +60 -0
  929. data/linkser/spec/dummy/db/.gitkeep +0 -0
  930. data/linkser/spec/dummy/documents/documents/000/000/001/original.pdf +157 -0
  931. data/linkser/spec/dummy/documents/documents/000/000/002/original.pdf +157 -0
  932. data/linkser/spec/dummy/documents/documents/000/000/003/original.pdf +157 -0
  933. data/linkser/spec/dummy/documents/documents/000/000/004/original.pdf +157 -0
  934. data/linkser/spec/dummy/documents/documents/000/000/005/original.pdf +157 -0
  935. data/linkser/spec/dummy/documents/documents/000/000/006/original.pdf +157 -0
  936. data/linkser/spec/dummy/documents/documents/000/000/007/original.pdf +157 -0
  937. data/linkser/spec/dummy/documents/documents/000/000/008/original.pdf +157 -0
  938. data/linkser/spec/dummy/documents/documents/000/000/009/original.pdf +157 -0
  939. data/linkser/spec/dummy/documents/documents/000/000/010/original.pdf +157 -0
  940. data/linkser/spec/dummy/documents/pictures/000/000/011/original.png +0 -0
  941. data/linkser/spec/dummy/documents/pictures/000/000/011/thumb.png +0 -0
  942. data/linkser/spec/dummy/documents/pictures/000/000/011/thumb0.png +0 -0
  943. data/linkser/spec/dummy/documents/pictures/000/000/012/original.png +0 -0
  944. data/linkser/spec/dummy/documents/pictures/000/000/012/thumb.png +0 -0
  945. data/linkser/spec/dummy/documents/pictures/000/000/012/thumb0.png +0 -0
  946. data/linkser/spec/dummy/documents/pictures/000/000/013/original.png +0 -0
  947. data/linkser/spec/dummy/documents/pictures/000/000/013/thumb.png +0 -0
  948. data/linkser/spec/dummy/documents/pictures/000/000/013/thumb0.png +0 -0
  949. data/linkser/spec/dummy/documents/pictures/000/000/014/original.png +0 -0
  950. data/linkser/spec/dummy/documents/pictures/000/000/014/thumb.png +0 -0
  951. data/linkser/spec/dummy/documents/pictures/000/000/014/thumb0.png +0 -0
  952. data/linkser/spec/dummy/documents/pictures/000/000/015/original.png +0 -0
  953. data/linkser/spec/dummy/documents/pictures/000/000/015/thumb.png +0 -0
  954. data/linkser/spec/dummy/documents/pictures/000/000/015/thumb0.png +0 -0
  955. data/linkser/spec/dummy/documents/pictures/000/000/016/original.png +0 -0
  956. data/linkser/spec/dummy/documents/pictures/000/000/016/thumb.png +0 -0
  957. data/linkser/spec/dummy/documents/pictures/000/000/016/thumb0.png +0 -0
  958. data/linkser/spec/dummy/documents/pictures/000/000/017/original.png +0 -0
  959. data/linkser/spec/dummy/documents/pictures/000/000/017/thumb.png +0 -0
  960. data/linkser/spec/dummy/documents/pictures/000/000/017/thumb0.png +0 -0
  961. data/linkser/spec/dummy/documents/pictures/000/000/018/original.png +0 -0
  962. data/linkser/spec/dummy/documents/pictures/000/000/018/thumb.png +0 -0
  963. data/linkser/spec/dummy/documents/pictures/000/000/018/thumb0.png +0 -0
  964. data/linkser/spec/dummy/documents/pictures/000/000/019/original.png +0 -0
  965. data/linkser/spec/dummy/documents/pictures/000/000/019/thumb.png +0 -0
  966. data/linkser/spec/dummy/documents/pictures/000/000/019/thumb0.png +0 -0
  967. data/linkser/spec/dummy/documents/pictures/000/000/020/original.png +0 -0
  968. data/linkser/spec/dummy/documents/pictures/000/000/020/thumb.png +0 -0
  969. data/linkser/spec/dummy/documents/pictures/000/000/020/thumb0.png +0 -0
  970. data/linkser/spec/dummy/public/404.html +26 -0
  971. data/linkser/spec/dummy/public/422.html +26 -0
  972. data/linkser/spec/dummy/public/500.html +26 -0
  973. data/linkser/spec/dummy/public/favicon.ico +0 -0
  974. data/linkser/spec/dummy/public/javascripts/application.js +2 -0
  975. data/linkser/spec/dummy/public/javascripts/controls.js +965 -0
  976. data/linkser/spec/dummy/public/javascripts/dragdrop.js +974 -0
  977. data/linkser/spec/dummy/public/javascripts/effects.js +1123 -0
  978. data/linkser/spec/dummy/public/javascripts/prototype.js +6001 -0
  979. data/linkser/spec/dummy/public/javascripts/rails.js +191 -0
  980. data/linkser/spec/dummy/public/stylesheets/.gitkeep +0 -0
  981. data/linkser/spec/dummy/script/rails +6 -0
  982. data/linkser/spec/integration/navigation_spec.rb +9 -0
  983. data/linkser/spec/socialstream_linkser_spec.rb +7 -0
  984. data/linkser/spec/spec_helper.rb +48 -0
  985. data/linkser/spec/support/cancan.rb +1 -0
  986. data/linkser/spec/support/db.rb +8 -0
  987. data/linkser/spec/support/devise.rb +4 -0
  988. data/linkser/spec/support/mock.rb +4 -0
  989. data/linkser/vendor/assets/javascripts/jquery.jplayer.js +78 -0
  990. data/linkser/vendor/assets/stylesheets/jplayer.blue.monday.css +448 -0
  991. data/linkser/vendor/assets/stylesheets/jplayer.blue.monday.jpg +0 -0
  992. data/linkser/vendor/assets/stylesheets/jplayer.blue.monday.video.play.hover.png +0 -0
  993. data/linkser/vendor/assets/stylesheets/jplayer.blue.monday.video.play.png +0 -0
  994. data/linkser/vendor/assets/stylesheets/jquery.lightbox.css +101 -0
  995. data/linkser/vendor/assets/stylesheets/pbar-ani.gif +0 -0
  996. data/presence/.gitignore +5 -0
  997. data/presence/Gemfile +4 -0
  998. data/presence/Rakefile +8 -0
  999. data/presence/app/assets/audio/chat/onMessageAudio.mp3 +0 -0
  1000. data/presence/app/assets/audio/chat/onMessageAudio.wav +0 -0
  1001. data/presence/app/assets/images/black_arrow3.png +0 -0
  1002. data/presence/app/assets/images/emoticons/beer.png +0 -0
  1003. data/presence/app/assets/images/emoticons/clock.png +0 -0
  1004. data/presence/app/assets/images/emoticons/face-raspberry.png +0 -0
  1005. data/presence/app/assets/images/emoticons/face-sad.png +0 -0
  1006. data/presence/app/assets/images/emoticons/face-smile.png +0 -0
  1007. data/presence/app/assets/images/emoticons/face-tired.png +0 -0
  1008. data/presence/app/assets/images/emoticons/face-wink.png +0 -0
  1009. data/presence/app/assets/images/emoticons/present.png +0 -0
  1010. data/presence/app/assets/images/emoticons/rain.png +0 -0
  1011. data/presence/app/assets/images/emoticons/sun.png +0 -0
  1012. data/presence/app/assets/images/status/available.png +0 -0
  1013. data/presence/app/assets/images/status/away.png +0 -0
  1014. data/presence/app/assets/images/status/dnd.png +0 -0
  1015. data/presence/app/assets/images/status/offline.png +0 -0
  1016. data/presence/app/assets/javascripts/chat_audio.js +73 -0
  1017. data/presence/app/assets/javascripts/chat_interface_manager.js.erb +334 -0
  1018. data/presence/app/assets/javascripts/chat_parser.js +257 -0
  1019. data/presence/app/assets/javascripts/chat_utilities.js +223 -0
  1020. data/presence/app/assets/javascripts/chat_window_manager.js +186 -0
  1021. data/presence/app/assets/javascripts/social_stream-presence.js +5 -0
  1022. data/presence/app/assets/javascripts/store.js +19 -0
  1023. data/presence/app/assets/javascripts/xmpp_client_management.js.erb +326 -0
  1024. data/presence/app/assets/stylesheets/chat.css.scss +350 -0
  1025. data/presence/app/assets/stylesheets/social_stream-presence.css +4 -0
  1026. data/presence/app/controllers/xmpp_controller.rb +187 -0
  1027. data/presence/app/helpers/xmpp_helper.rb +20 -0
  1028. data/presence/app/views/chat/_connecting.html.erb +8 -0
  1029. data/presence/app/views/chat/_contacts.html.erb +47 -0
  1030. data/presence/app/views/chat/_index.html.erb +41 -0
  1031. data/presence/app/views/chat/_off.html.erb +54 -0
  1032. data/presence/app/views/chat/_settings.html.erb +34 -0
  1033. data/presence/app/views/xmpp/active_users.html.erb +33 -0
  1034. data/presence/config/locales/en.yml +20 -0
  1035. data/presence/config/locales/es.yml +21 -0
  1036. data/presence/config/routes.rb +13 -0
  1037. data/presence/db/migrate/20110711111408_add_connected_column_to_user.rb +9 -0
  1038. data/presence/db/migrate/20110928135031_add_status_column_to_user.rb +9 -0
  1039. data/presence/db/migrate/20111116194112_add_chat_enabled_column_to_user.rb +9 -0
  1040. data/presence/ejabberd/conf/ejabberd_example.cfg +621 -0
  1041. data/presence/ejabberd/conf/ssconfig_example.cfg +33 -0
  1042. data/presence/ejabberd/ejabberd_files.zip +0 -0
  1043. data/presence/ejabberd/ejabberd_scripts/authentication_script +167 -0
  1044. data/presence/ejabberd/ejabberd_scripts/development_scripts/compile_module +34 -0
  1045. data/presence/ejabberd/ejabberd_scripts/development_scripts/generate_random_password +18 -0
  1046. data/presence/ejabberd/ejabberd_scripts/development_scripts/kill_authentication_script.sh +13 -0
  1047. data/presence/ejabberd/ejabberd_scripts/development_scripts/reset_logs.sh +21 -0
  1048. data/presence/ejabberd/ejabberd_scripts/development_scripts/show_config.sh +37 -0
  1049. data/presence/ejabberd/ejabberd_scripts/development_scripts/start_ejabberd.sh +68 -0
  1050. data/presence/ejabberd/ejabberd_scripts/development_scripts/stop_ejabberd.sh +12 -0
  1051. data/presence/ejabberd/ejabberd_scripts/emanagement +555 -0
  1052. data/presence/ejabberd/ejabberd_scripts/reset_connection_script +300 -0
  1053. data/presence/ejabberd/ejabberd_scripts/rest_api_client_script +304 -0
  1054. data/presence/ejabberd/ejabberd_scripts/set_script_header.sh +112 -0
  1055. data/presence/ejabberd/ejabberd_scripts/synchronize_presence_script +300 -0
  1056. data/presence/ejabberd/installer.sh +267 -0
  1057. data/presence/ejabberd/mod_admin_extra/mod_admin_extra.beam +0 -0
  1058. data/presence/ejabberd/mod_admin_extra/mod_admin_extra.erl +1560 -0
  1059. data/presence/ejabberd/mod_sspresence/mod_sspresence.beam +0 -0
  1060. data/presence/ejabberd/mod_sspresence/mod_sspresence.erl +193 -0
  1061. data/presence/lib/generators/social_stream/presence/install_generator.rb +28 -0
  1062. data/presence/lib/generators/social_stream/presence/templates/initializer.rb +34 -0
  1063. data/presence/lib/social_stream-presence.rb +50 -0
  1064. data/presence/lib/social_stream/migrations/presence.rb +8 -0
  1065. data/presence/lib/social_stream/presence/engine.rb +17 -0
  1066. data/presence/lib/social_stream/presence/models/buddy_manager.rb +104 -0
  1067. data/presence/lib/social_stream/presence/version.rb +5 -0
  1068. data/presence/lib/social_stream/presence/xmpp_server_order.rb +549 -0
  1069. data/presence/lib/social_stream/views/settings/presence.rb +20 -0
  1070. data/presence/lib/tasks/presence/installer.rake +136 -0
  1071. data/presence/lib/tasks/presence/synchronize.rake +22 -0
  1072. data/presence/social_stream-presence.gemspec +32 -0
  1073. data/presence/spec/demo/.gitignore +5 -0
  1074. data/presence/spec/demo/.rspec +1 -0
  1075. data/presence/spec/demo/README +261 -0
  1076. data/presence/spec/demo/Rakefile +7 -0
  1077. data/presence/spec/demo/app/assets/images/rails.png +0 -0
  1078. data/presence/spec/demo/app/assets/javascripts/application.js +9 -0
  1079. data/presence/spec/demo/app/assets/stylesheets/application.css +7 -0
  1080. data/presence/spec/demo/app/controllers/application_controller.rb +3 -0
  1081. data/presence/spec/demo/app/helpers/application_helper.rb +2 -0
  1082. data/presence/spec/demo/app/mailers/.gitkeep +0 -0
  1083. data/presence/spec/demo/app/models/.gitkeep +0 -0
  1084. data/presence/spec/demo/app/views/layouts/application.html.erb +14 -0
  1085. data/presence/spec/demo/autotest/discover.rb +2 -0
  1086. data/presence/spec/demo/config.ru +4 -0
  1087. data/presence/spec/demo/config/application.rb +41 -0
  1088. data/presence/spec/demo/config/boot.rb +6 -0
  1089. data/presence/spec/demo/config/database.yml +25 -0
  1090. data/presence/spec/demo/config/environment.rb +5 -0
  1091. data/presence/spec/demo/config/environments/development.rb +27 -0
  1092. data/presence/spec/demo/config/environments/production.rb +54 -0
  1093. data/presence/spec/demo/config/environments/test.rb +39 -0
  1094. data/presence/spec/demo/config/initializers/backtrace_silencers.rb +7 -0
  1095. data/presence/spec/demo/config/initializers/inflections.rb +10 -0
  1096. data/presence/spec/demo/config/initializers/mime_types.rb +5 -0
  1097. data/presence/spec/demo/config/initializers/secret_token.rb +7 -0
  1098. data/presence/spec/demo/config/initializers/session_store.rb +8 -0
  1099. data/presence/spec/demo/config/initializers/wrap_parameters.rb +12 -0
  1100. data/presence/spec/demo/config/locales/en.yml +5 -0
  1101. data/presence/spec/demo/config/routes.rb +58 -0
  1102. data/presence/spec/demo/db/seeds.rb +7 -0
  1103. data/presence/spec/demo/doc/README_FOR_APP +2 -0
  1104. data/presence/spec/demo/lib/tasks/.gitkeep +0 -0
  1105. data/presence/spec/demo/log/.gitkeep +0 -0
  1106. data/presence/spec/demo/public/404.html +26 -0
  1107. data/presence/spec/demo/public/422.html +26 -0
  1108. data/presence/spec/demo/public/500.html +26 -0
  1109. data/presence/spec/demo/public/favicon.ico +0 -0
  1110. data/presence/spec/demo/public/index.html +241 -0
  1111. data/presence/spec/demo/public/robots.txt +5 -0
  1112. data/presence/spec/demo/script/rails +6 -0
  1113. data/presence/spec/demo/spec/spec_helper.rb +27 -0
  1114. data/presence/spec/demo/test/fixtures/.gitkeep +0 -0
  1115. data/presence/spec/demo/test/functional/.gitkeep +0 -0
  1116. data/presence/spec/demo/test/integration/.gitkeep +0 -0
  1117. data/presence/spec/demo/test/performance/browsing_test.rb +12 -0
  1118. data/presence/spec/demo/test/test_helper.rb +13 -0
  1119. data/presence/spec/demo/test/unit/.gitkeep +0 -0
  1120. data/presence/spec/demo/vendor/assets/stylesheets/.gitkeep +0 -0
  1121. data/presence/spec/demo/vendor/plugins/.gitkeep +0 -0
  1122. data/presence/spec/discover.rb +2 -0
  1123. data/presence/spec/spec_helper.rb +27 -0
  1124. data/presence/vendor/assets/javascripts/jquery.tools.tooltip.js +11 -0
  1125. data/presence/vendor/assets/javascripts/jquery.ui.chatbox.js +341 -0
  1126. data/presence/vendor/assets/javascripts/strophe.js +3612 -0
  1127. data/presence/vendor/assets/stylesheets/jquery.ui.chatbox.css +54 -0
  1128. data/social_stream.gemspec +46 -0
  1129. data/social_stream.thor +10 -0
  1130. data/spec/controllers/frontpage_controller_spec.rb +11 -0
  1131. data/spec/dummy/.gitignore +5 -0
  1132. data/spec/dummy/Rakefile +7 -0
  1133. data/spec/dummy/app/assets/images/rails.png +0 -0
  1134. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  1135. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  1136. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  1137. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  1138. data/spec/dummy/app/mailers/.gitkeep +0 -0
  1139. data/spec/dummy/app/models/.gitkeep +0 -0
  1140. data/spec/dummy/config.ru +4 -0
  1141. data/spec/dummy/config/application.rb +45 -0
  1142. data/spec/dummy/config/boot.rb +10 -0
  1143. data/spec/dummy/config/database.yml +36 -0
  1144. data/spec/dummy/config/environment.rb +5 -0
  1145. data/spec/dummy/config/environments/development.rb +27 -0
  1146. data/spec/dummy/config/environments/production.rb +54 -0
  1147. data/spec/dummy/config/environments/test.rb +39 -0
  1148. data/spec/dummy/config/environments/test_mysql.rb +39 -0
  1149. data/spec/dummy/config/environments/test_postgres.rb +39 -0
  1150. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  1151. data/spec/dummy/config/initializers/devise.rb +176 -0
  1152. data/spec/dummy/config/initializers/inflections.rb +10 -0
  1153. data/spec/dummy/config/initializers/mailboxer.rb +8 -0
  1154. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  1155. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  1156. data/spec/dummy/config/initializers/session_store.rb +8 -0
  1157. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  1158. data/spec/dummy/config/locales/en.yml +5 -0
  1159. data/spec/dummy/config/navigation.rb +4 -0
  1160. data/spec/dummy/config/relations.yml +39 -0
  1161. data/spec/dummy/config/routes.rb +60 -0
  1162. data/spec/dummy/db/migrate/.gitkeep +0 -0
  1163. data/spec/dummy/db/schema.rb +9 -0
  1164. data/spec/dummy/db/seeds.rb +8 -0
  1165. data/spec/dummy/public/404.html +26 -0
  1166. data/spec/dummy/public/422.html +26 -0
  1167. data/spec/dummy/public/500.html +26 -0
  1168. data/spec/dummy/public/favicon.ico +0 -0
  1169. data/spec/dummy/public/robots.txt +5 -0
  1170. data/spec/dummy/script/rails +6 -0
  1171. data/spec/integration/navigation_spec.rb +9 -0
  1172. data/spec/social_stream_spec.rb +7 -0
  1173. data/spec/spec_helper.rb +27 -0
  1174. data/spec/support/components.rb +7 -0
  1175. data/spec/support/db.rb +15 -0
  1176. data/spec/support/optimizations.rb +4 -0
  1177. metadata +1340 -0
@@ -0,0 +1,3612 @@
1
+ // This code was written by Tyler Akins and has been placed in the
2
+ // public domain. It would be nice if you left this header intact.
3
+ // Base64 code from Tyler Akins -- http://rumkin.com
4
+
5
+ var Base64 = (function () {
6
+ var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
7
+
8
+ var obj = {
9
+ /**
10
+ * Encodes a string in base64
11
+ * @param {String} input The string to encode in base64.
12
+ */
13
+ encode: function (input) {
14
+ var output = "";
15
+ var chr1, chr2, chr3;
16
+ var enc1, enc2, enc3, enc4;
17
+ var i = 0;
18
+
19
+ do {
20
+ chr1 = input.charCodeAt(i++);
21
+ chr2 = input.charCodeAt(i++);
22
+ chr3 = input.charCodeAt(i++);
23
+
24
+ enc1 = chr1 >> 2;
25
+ enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
26
+ enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
27
+ enc4 = chr3 & 63;
28
+
29
+ if (isNaN(chr2)) {
30
+ enc3 = enc4 = 64;
31
+ } else if (isNaN(chr3)) {
32
+ enc4 = 64;
33
+ }
34
+
35
+ output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
36
+ keyStr.charAt(enc3) + keyStr.charAt(enc4);
37
+ } while (i < input.length);
38
+
39
+ return output;
40
+ },
41
+
42
+ /**
43
+ * Decodes a base64 string.
44
+ * @param {String} input The string to decode.
45
+ */
46
+ decode: function (input) {
47
+ var output = "";
48
+ var chr1, chr2, chr3;
49
+ var enc1, enc2, enc3, enc4;
50
+ var i = 0;
51
+
52
+ // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
53
+ input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
54
+
55
+ do {
56
+ enc1 = keyStr.indexOf(input.charAt(i++));
57
+ enc2 = keyStr.indexOf(input.charAt(i++));
58
+ enc3 = keyStr.indexOf(input.charAt(i++));
59
+ enc4 = keyStr.indexOf(input.charAt(i++));
60
+
61
+ chr1 = (enc1 << 2) | (enc2 >> 4);
62
+ chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
63
+ chr3 = ((enc3 & 3) << 6) | enc4;
64
+
65
+ output = output + String.fromCharCode(chr1);
66
+
67
+ if (enc3 != 64) {
68
+ output = output + String.fromCharCode(chr2);
69
+ }
70
+ if (enc4 != 64) {
71
+ output = output + String.fromCharCode(chr3);
72
+ }
73
+ } while (i < input.length);
74
+
75
+ return output;
76
+ }
77
+ };
78
+
79
+ return obj;
80
+ })();
81
+ /*
82
+ * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
83
+ * Digest Algorithm, as defined in RFC 1321.
84
+ * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
85
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
86
+ * Distributed under the BSD License
87
+ * See http://pajhome.org.uk/crypt/md5 for more info.
88
+ */
89
+
90
+ var MD5 = (function () {
91
+ /*
92
+ * Configurable variables. You may need to tweak these to be compatible with
93
+ * the server-side, but the defaults work in most cases.
94
+ */
95
+ var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
96
+ var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
97
+ var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
98
+
99
+ /*
100
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
101
+ * to work around bugs in some JS interpreters.
102
+ */
103
+ var safe_add = function (x, y) {
104
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF);
105
+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
106
+ return (msw << 16) | (lsw & 0xFFFF);
107
+ };
108
+
109
+ /*
110
+ * Bitwise rotate a 32-bit number to the left.
111
+ */
112
+ var bit_rol = function (num, cnt) {
113
+ return (num << cnt) | (num >>> (32 - cnt));
114
+ };
115
+
116
+ /*
117
+ * Convert a string to an array of little-endian words
118
+ * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
119
+ */
120
+ var str2binl = function (str) {
121
+ var bin = [];
122
+ var mask = (1 << chrsz) - 1;
123
+ for(var i = 0; i < str.length * chrsz; i += chrsz)
124
+ {
125
+ bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
126
+ }
127
+ return bin;
128
+ };
129
+
130
+ /*
131
+ * Convert an array of little-endian words to a string
132
+ */
133
+ var binl2str = function (bin) {
134
+ var str = "";
135
+ var mask = (1 << chrsz) - 1;
136
+ for(var i = 0; i < bin.length * 32; i += chrsz)
137
+ {
138
+ str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
139
+ }
140
+ return str;
141
+ };
142
+
143
+ /*
144
+ * Convert an array of little-endian words to a hex string.
145
+ */
146
+ var binl2hex = function (binarray) {
147
+ var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
148
+ var str = "";
149
+ for(var i = 0; i < binarray.length * 4; i++)
150
+ {
151
+ str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
152
+ hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);
153
+ }
154
+ return str;
155
+ };
156
+
157
+ /*
158
+ * Convert an array of little-endian words to a base-64 string
159
+ */
160
+ var binl2b64 = function (binarray) {
161
+ var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
162
+ var str = "";
163
+ var triplet, j;
164
+ for(var i = 0; i < binarray.length * 4; i += 3)
165
+ {
166
+ triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16) |
167
+ (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 ) |
168
+ ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
169
+ for(j = 0; j < 4; j++)
170
+ {
171
+ if(i * 8 + j * 6 > binarray.length * 32) { str += b64pad; }
172
+ else { str += tab.charAt((triplet >> 6*(3-j)) & 0x3F); }
173
+ }
174
+ }
175
+ return str;
176
+ };
177
+
178
+ /*
179
+ * These functions implement the four basic operations the algorithm uses.
180
+ */
181
+ var md5_cmn = function (q, a, b, x, s, t) {
182
+ return safe_add(bit_rol(safe_add(safe_add(a, q),safe_add(x, t)), s),b);
183
+ };
184
+
185
+ var md5_ff = function (a, b, c, d, x, s, t) {
186
+ return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
187
+ };
188
+
189
+ var md5_gg = function (a, b, c, d, x, s, t) {
190
+ return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
191
+ };
192
+
193
+ var md5_hh = function (a, b, c, d, x, s, t) {
194
+ return md5_cmn(b ^ c ^ d, a, b, x, s, t);
195
+ };
196
+
197
+ var md5_ii = function (a, b, c, d, x, s, t) {
198
+ return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
199
+ };
200
+
201
+ /*
202
+ * Calculate the MD5 of an array of little-endian words, and a bit length
203
+ */
204
+ var core_md5 = function (x, len) {
205
+ /* append padding */
206
+ x[len >> 5] |= 0x80 << ((len) % 32);
207
+ x[(((len + 64) >>> 9) << 4) + 14] = len;
208
+
209
+ var a = 1732584193;
210
+ var b = -271733879;
211
+ var c = -1732584194;
212
+ var d = 271733878;
213
+
214
+ var olda, oldb, oldc, oldd;
215
+ for (var i = 0; i < x.length; i += 16)
216
+ {
217
+ olda = a;
218
+ oldb = b;
219
+ oldc = c;
220
+ oldd = d;
221
+
222
+ a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
223
+ d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
224
+ c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
225
+ b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
226
+ a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
227
+ d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
228
+ c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
229
+ b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
230
+ a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
231
+ d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
232
+ c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
233
+ b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
234
+ a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
235
+ d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
236
+ c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
237
+ b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
238
+
239
+ a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
240
+ d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
241
+ c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
242
+ b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
243
+ a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
244
+ d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
245
+ c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
246
+ b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
247
+ a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
248
+ d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
249
+ c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
250
+ b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
251
+ a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
252
+ d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
253
+ c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
254
+ b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
255
+
256
+ a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
257
+ d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
258
+ c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
259
+ b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
260
+ a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
261
+ d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
262
+ c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
263
+ b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
264
+ a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
265
+ d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
266
+ c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
267
+ b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
268
+ a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
269
+ d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
270
+ c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
271
+ b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
272
+
273
+ a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
274
+ d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
275
+ c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
276
+ b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
277
+ a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
278
+ d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
279
+ c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
280
+ b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
281
+ a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
282
+ d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
283
+ c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
284
+ b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
285
+ a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
286
+ d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
287
+ c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
288
+ b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
289
+
290
+ a = safe_add(a, olda);
291
+ b = safe_add(b, oldb);
292
+ c = safe_add(c, oldc);
293
+ d = safe_add(d, oldd);
294
+ }
295
+ return [a, b, c, d];
296
+ };
297
+
298
+
299
+ /*
300
+ * Calculate the HMAC-MD5, of a key and some data
301
+ */
302
+ var core_hmac_md5 = function (key, data) {
303
+ var bkey = str2binl(key);
304
+ if(bkey.length > 16) { bkey = core_md5(bkey, key.length * chrsz); }
305
+
306
+ var ipad = new Array(16), opad = new Array(16);
307
+ for(var i = 0; i < 16; i++)
308
+ {
309
+ ipad[i] = bkey[i] ^ 0x36363636;
310
+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
311
+ }
312
+
313
+ var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
314
+ return core_md5(opad.concat(hash), 512 + 128);
315
+ };
316
+
317
+ var obj = {
318
+ /*
319
+ * These are the functions you'll usually want to call.
320
+ * They take string arguments and return either hex or base-64 encoded
321
+ * strings.
322
+ */
323
+ hexdigest: function (s) {
324
+ return binl2hex(core_md5(str2binl(s), s.length * chrsz));
325
+ },
326
+
327
+ b64digest: function (s) {
328
+ return binl2b64(core_md5(str2binl(s), s.length * chrsz));
329
+ },
330
+
331
+ hash: function (s) {
332
+ return binl2str(core_md5(str2binl(s), s.length * chrsz));
333
+ },
334
+
335
+ hmac_hexdigest: function (key, data) {
336
+ return binl2hex(core_hmac_md5(key, data));
337
+ },
338
+
339
+ hmac_b64digest: function (key, data) {
340
+ return binl2b64(core_hmac_md5(key, data));
341
+ },
342
+
343
+ hmac_hash: function (key, data) {
344
+ return binl2str(core_hmac_md5(key, data));
345
+ },
346
+
347
+ /*
348
+ * Perform a simple self-test to see if the VM is working
349
+ */
350
+ test: function () {
351
+ return MD5.hexdigest("abc") === "900150983cd24fb0d6963f7d28e17f72";
352
+ }
353
+ };
354
+
355
+ return obj;
356
+ })();
357
+ /*
358
+ This program is distributed under the terms of the MIT license.
359
+ Please see the LICENSE file for details.
360
+
361
+ Copyright 2006-2008, OGG, LLC
362
+ */
363
+
364
+ /* jslint configuration: */
365
+ /*global document, window, setTimeout, clearTimeout, console,
366
+ XMLHttpRequest, ActiveXObject,
367
+ Base64, MD5,
368
+ Strophe, $build, $msg, $iq, $pres */
369
+
370
+ /** File: strophe.js
371
+ * A JavaScript library for XMPP BOSH.
372
+ *
373
+ * This is the JavaScript version of the Strophe library. Since JavaScript
374
+ * has no facilities for persistent TCP connections, this library uses
375
+ * Bidirectional-streams Over Synchronous HTTP (BOSH) to emulate
376
+ * a persistent, stateful, two-way connection to an XMPP server. More
377
+ * information on BOSH can be found in XEP 124.
378
+ */
379
+
380
+ /** PrivateFunction: Function.prototype.bind
381
+ * Bind a function to an instance.
382
+ *
383
+ * This Function object extension method creates a bound method similar
384
+ * to those in Python. This means that the 'this' object will point
385
+ * to the instance you want. See
386
+ * <a href='https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind'>MDC's bind() documentation</a> and
387
+ * <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>
388
+ * for a complete explanation.
389
+ *
390
+ * This extension already exists in some browsers (namely, Firefox 3), but
391
+ * we provide it to support those that don't.
392
+ *
393
+ * Parameters:
394
+ * (Object) obj - The object that will become 'this' in the bound function.
395
+ * (Object) argN - An option argument that will be prepended to the
396
+ * arguments given for the function call
397
+ *
398
+ * Returns:
399
+ * The bound function.
400
+ */
401
+ if (!Function.prototype.bind) {
402
+ Function.prototype.bind = function (obj /*, arg1, arg2, ... */)
403
+ {
404
+ var func = this;
405
+ var _slice = Array.prototype.slice;
406
+ var _concat = Array.prototype.concat;
407
+ var _args = _slice.call(arguments, 1);
408
+
409
+ return function () {
410
+ return func.apply(obj ? obj : this,
411
+ _concat.call(_args,
412
+ _slice.call(arguments, 0)));
413
+ };
414
+ };
415
+ }
416
+
417
+ /** PrivateFunction: Array.prototype.indexOf
418
+ * Return the index of an object in an array.
419
+ *
420
+ * This function is not supplied by some JavaScript implementations, so
421
+ * we provide it if it is missing. This code is from:
422
+ * http://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Objects:Array:indexOf
423
+ *
424
+ * Parameters:
425
+ * (Object) elt - The object to look for.
426
+ * (Integer) from - The index from which to start looking. (optional).
427
+ *
428
+ * Returns:
429
+ * The index of elt in the array or -1 if not found.
430
+ */
431
+ if (!Array.prototype.indexOf)
432
+ {
433
+ Array.prototype.indexOf = function(elt /*, from*/)
434
+ {
435
+ var len = this.length;
436
+
437
+ var from = Number(arguments[1]) || 0;
438
+ from = (from < 0) ? Math.ceil(from) : Math.floor(from);
439
+ if (from < 0) {
440
+ from += len;
441
+ }
442
+
443
+ for (; from < len; from++) {
444
+ if (from in this && this[from] === elt) {
445
+ return from;
446
+ }
447
+ }
448
+
449
+ return -1;
450
+ };
451
+ }
452
+
453
+ /* All of the Strophe globals are defined in this special function below so
454
+ * that references to the globals become closures. This will ensure that
455
+ * on page reload, these references will still be available to callbacks
456
+ * that are still executing.
457
+ */
458
+
459
+ (function (callback) {
460
+ var Strophe;
461
+
462
+ /** Function: $build
463
+ * Create a Strophe.Builder.
464
+ * This is an alias for 'new Strophe.Builder(name, attrs)'.
465
+ *
466
+ * Parameters:
467
+ * (String) name - The root element name.
468
+ * (Object) attrs - The attributes for the root element in object notation.
469
+ *
470
+ * Returns:
471
+ * A new Strophe.Builder object.
472
+ */
473
+ function $build(name, attrs) { return new Strophe.Builder(name, attrs); }
474
+ /** Function: $msg
475
+ * Create a Strophe.Builder with a <message/> element as the root.
476
+ *
477
+ * Parmaeters:
478
+ * (Object) attrs - The <message/> element attributes in object notation.
479
+ *
480
+ * Returns:
481
+ * A new Strophe.Builder object.
482
+ */
483
+ function $msg(attrs) { return new Strophe.Builder("message", attrs); }
484
+ /** Function: $iq
485
+ * Create a Strophe.Builder with an <iq/> element as the root.
486
+ *
487
+ * Parameters:
488
+ * (Object) attrs - The <iq/> element attributes in object notation.
489
+ *
490
+ * Returns:
491
+ * A new Strophe.Builder object.
492
+ */
493
+ function $iq(attrs) { return new Strophe.Builder("iq", attrs); }
494
+ /** Function: $pres
495
+ * Create a Strophe.Builder with a <presence/> element as the root.
496
+ *
497
+ * Parameters:
498
+ * (Object) attrs - The <presence/> element attributes in object notation.
499
+ *
500
+ * Returns:
501
+ * A new Strophe.Builder object.
502
+ */
503
+ function $pres(attrs) { return new Strophe.Builder("presence", attrs); }
504
+
505
+ /** Class: Strophe
506
+ * An object container for all Strophe library functions.
507
+ *
508
+ * This class is just a container for all the objects and constants
509
+ * used in the library. It is not meant to be instantiated, but to
510
+ * provide a namespace for library objects, constants, and functions.
511
+ */
512
+ Strophe = {
513
+ /** Constant: VERSION
514
+ * The version of the Strophe library. Unreleased builds will have
515
+ * a version of head-HASH where HASH is a partial revision.
516
+ */
517
+ VERSION: "1.0.2",
518
+
519
+ /** Constants: XMPP Namespace Constants
520
+ * Common namespace constants from the XMPP RFCs and XEPs.
521
+ *
522
+ * NS.HTTPBIND - HTTP BIND namespace from XEP 124.
523
+ * NS.BOSH - BOSH namespace from XEP 206.
524
+ * NS.CLIENT - Main XMPP client namespace.
525
+ * NS.AUTH - Legacy authentication namespace.
526
+ * NS.ROSTER - Roster operations namespace.
527
+ * NS.PROFILE - Profile namespace.
528
+ * NS.DISCO_INFO - Service discovery info namespace from XEP 30.
529
+ * NS.DISCO_ITEMS - Service discovery items namespace from XEP 30.
530
+ * NS.MUC - Multi-User Chat namespace from XEP 45.
531
+ * NS.SASL - XMPP SASL namespace from RFC 3920.
532
+ * NS.STREAM - XMPP Streams namespace from RFC 3920.
533
+ * NS.BIND - XMPP Binding namespace from RFC 3920.
534
+ * NS.SESSION - XMPP Session namespace from RFC 3920.
535
+ */
536
+ NS: {
537
+ HTTPBIND: "http://jabber.org/protocol/httpbind",
538
+ BOSH: "urn:xmpp:xbosh",
539
+ CLIENT: "jabber:client",
540
+ AUTH: "jabber:iq:auth",
541
+ ROSTER: "jabber:iq:roster",
542
+ PROFILE: "jabber:iq:profile",
543
+ DISCO_INFO: "http://jabber.org/protocol/disco#info",
544
+ DISCO_ITEMS: "http://jabber.org/protocol/disco#items",
545
+ MUC: "http://jabber.org/protocol/muc",
546
+ SASL: "urn:ietf:params:xml:ns:xmpp-sasl",
547
+ STREAM: "http://etherx.jabber.org/streams",
548
+ BIND: "urn:ietf:params:xml:ns:xmpp-bind",
549
+ SESSION: "urn:ietf:params:xml:ns:xmpp-session",
550
+ VERSION: "jabber:iq:version",
551
+ STANZAS: "urn:ietf:params:xml:ns:xmpp-stanzas"
552
+ },
553
+
554
+ /** Function: addNamespace
555
+ * This function is used to extend the current namespaces in
556
+ * Strophe.NS. It takes a key and a value with the key being the
557
+ * name of the new namespace, with its actual value.
558
+ * For example:
559
+ * Strophe.addNamespace('PUBSUB', "http://jabber.org/protocol/pubsub");
560
+ *
561
+ * Parameters:
562
+ * (String) name - The name under which the namespace will be
563
+ * referenced under Strophe.NS
564
+ * (String) value - The actual namespace.
565
+ */
566
+ addNamespace: function (name, value)
567
+ {
568
+ Strophe.NS[name] = value;
569
+ },
570
+
571
+ /** Constants: Connection Status Constants
572
+ * Connection status constants for use by the connection handler
573
+ * callback.
574
+ *
575
+ * Status.ERROR - An error has occurred
576
+ * Status.CONNECTING - The connection is currently being made
577
+ * Status.CONNFAIL - The connection attempt failed
578
+ * Status.AUTHENTICATING - The connection is authenticating
579
+ * Status.AUTHFAIL - The authentication attempt failed
580
+ * Status.CONNECTED - The connection has succeeded
581
+ * Status.DISCONNECTED - The connection has been terminated
582
+ * Status.DISCONNECTING - The connection is currently being terminated
583
+ * Status.ATTACHED - The connection has been attached
584
+ */
585
+ Status: {
586
+ ERROR: 0,
587
+ CONNECTING: 1,
588
+ CONNFAIL: 2,
589
+ AUTHENTICATING: 3,
590
+ AUTHFAIL: 4,
591
+ CONNECTED: 5,
592
+ DISCONNECTED: 6,
593
+ DISCONNECTING: 7,
594
+ ATTACHED: 8
595
+ },
596
+
597
+ /** Constants: Log Level Constants
598
+ * Logging level indicators.
599
+ *
600
+ * LogLevel.DEBUG - Debug output
601
+ * LogLevel.INFO - Informational output
602
+ * LogLevel.WARN - Warnings
603
+ * LogLevel.ERROR - Errors
604
+ * LogLevel.FATAL - Fatal errors
605
+ */
606
+ LogLevel: {
607
+ DEBUG: 0,
608
+ INFO: 1,
609
+ WARN: 2,
610
+ ERROR: 3,
611
+ FATAL: 4
612
+ },
613
+
614
+ /** PrivateConstants: DOM Element Type Constants
615
+ * DOM element types.
616
+ *
617
+ * ElementType.NORMAL - Normal element.
618
+ * ElementType.TEXT - Text data element.
619
+ */
620
+ ElementType: {
621
+ NORMAL: 1,
622
+ TEXT: 3,
623
+ CDATA: 4
624
+ },
625
+
626
+ /** PrivateConstants: Timeout Values
627
+ * Timeout values for error states. These values are in seconds.
628
+ * These should not be changed unless you know exactly what you are
629
+ * doing.
630
+ *
631
+ * TIMEOUT - Timeout multiplier. A waiting request will be considered
632
+ * failed after Math.floor(TIMEOUT * wait) seconds have elapsed.
633
+ * This defaults to 1.1, and with default wait, 66 seconds.
634
+ * SECONDARY_TIMEOUT - Secondary timeout multiplier. In cases where
635
+ * Strophe can detect early failure, it will consider the request
636
+ * failed if it doesn't return after
637
+ * Math.floor(SECONDARY_TIMEOUT * wait) seconds have elapsed.
638
+ * This defaults to 0.1, and with default wait, 6 seconds.
639
+ */
640
+ TIMEOUT: 1.1,
641
+ SECONDARY_TIMEOUT: 0.1,
642
+
643
+ /** Function: forEachChild
644
+ * Map a function over some or all child elements of a given element.
645
+ *
646
+ * This is a small convenience function for mapping a function over
647
+ * some or all of the children of an element. If elemName is null, all
648
+ * children will be passed to the function, otherwise only children
649
+ * whose tag names match elemName will be passed.
650
+ *
651
+ * Parameters:
652
+ * (XMLElement) elem - The element to operate on.
653
+ * (String) elemName - The child element tag name filter.
654
+ * (Function) func - The function to apply to each child. This
655
+ * function should take a single argument, a DOM element.
656
+ */
657
+ forEachChild: function (elem, elemName, func)
658
+ {
659
+ var i, childNode;
660
+
661
+ for (i = 0; i < elem.childNodes.length; i++) {
662
+ childNode = elem.childNodes[i];
663
+ if (childNode.nodeType == Strophe.ElementType.NORMAL &&
664
+ (!elemName || this.isTagEqual(childNode, elemName))) {
665
+ func(childNode);
666
+ }
667
+ }
668
+ },
669
+
670
+ /** Function: isTagEqual
671
+ * Compare an element's tag name with a string.
672
+ *
673
+ * This function is case insensitive.
674
+ *
675
+ * Parameters:
676
+ * (XMLElement) el - A DOM element.
677
+ * (String) name - The element name.
678
+ *
679
+ * Returns:
680
+ * true if the element's tag name matches _el_, and false
681
+ * otherwise.
682
+ */
683
+ isTagEqual: function (el, name)
684
+ {
685
+ return el.tagName.toLowerCase() == name.toLowerCase();
686
+ },
687
+
688
+ /** PrivateVariable: _xmlGenerator
689
+ * _Private_ variable that caches a DOM document to
690
+ * generate elements.
691
+ */
692
+ _xmlGenerator: null,
693
+
694
+ /** PrivateFunction: _makeGenerator
695
+ * _Private_ function that creates a dummy XML DOM document to serve as
696
+ * an element and text node generator.
697
+ */
698
+ _makeGenerator: function () {
699
+ var doc;
700
+
701
+ if (document.implementation.createDocument === undefined) {
702
+ doc = this._getIEXmlDom();
703
+ doc.appendChild(doc.createElement('strophe'));
704
+ } else {
705
+ doc = document.implementation
706
+ .createDocument('jabber:client', 'strophe', null);
707
+ }
708
+
709
+ return doc;
710
+ },
711
+
712
+ /** Function: xmlGenerator
713
+ * Get the DOM document to generate elements.
714
+ *
715
+ * Returns:
716
+ * The currently used DOM document.
717
+ */
718
+ xmlGenerator: function () {
719
+ if (!Strophe._xmlGenerator) {
720
+ Strophe._xmlGenerator = Strophe._makeGenerator();
721
+ }
722
+ return Strophe._xmlGenerator;
723
+ },
724
+
725
+ /** PrivateFunction: _getIEXmlDom
726
+ * Gets IE xml doc object
727
+ *
728
+ * Returns:
729
+ * A Microsoft XML DOM Object
730
+ * See Also:
731
+ * http://msdn.microsoft.com/en-us/library/ms757837%28VS.85%29.aspx
732
+ */
733
+ _getIEXmlDom : function() {
734
+ var doc = null;
735
+ var docStrings = [
736
+ "Msxml2.DOMDocument.6.0",
737
+ "Msxml2.DOMDocument.5.0",
738
+ "Msxml2.DOMDocument.4.0",
739
+ "MSXML2.DOMDocument.3.0",
740
+ "MSXML2.DOMDocument",
741
+ "MSXML.DOMDocument",
742
+ "Microsoft.XMLDOM"
743
+ ];
744
+
745
+ for (var d = 0; d < docStrings.length; d++) {
746
+ if (doc === null) {
747
+ try {
748
+ doc = new ActiveXObject(docStrings[d]);
749
+ } catch (e) {
750
+ doc = null;
751
+ }
752
+ } else {
753
+ break;
754
+ }
755
+ }
756
+
757
+ return doc;
758
+ },
759
+
760
+ /** Function: xmlElement
761
+ * Create an XML DOM element.
762
+ *
763
+ * This function creates an XML DOM element correctly across all
764
+ * implementations. Note that these are not HTML DOM elements, which
765
+ * aren't appropriate for XMPP stanzas.
766
+ *
767
+ * Parameters:
768
+ * (String) name - The name for the element.
769
+ * (Array|Object) attrs - An optional array or object containing
770
+ * key/value pairs to use as element attributes. The object should
771
+ * be in the format {'key': 'value'} or {key: 'value'}. The array
772
+ * should have the format [['key1', 'value1'], ['key2', 'value2']].
773
+ * (String) text - The text child data for the element.
774
+ *
775
+ * Returns:
776
+ * A new XML DOM element.
777
+ */
778
+ xmlElement: function (name)
779
+ {
780
+ if (!name) { return null; }
781
+
782
+ var node = Strophe.xmlGenerator().createElement(name);
783
+
784
+ // FIXME: this should throw errors if args are the wrong type or
785
+ // there are more than two optional args
786
+ var a, i, k;
787
+ for (a = 1; a < arguments.length; a++) {
788
+ if (!arguments[a]) { continue; }
789
+ if (typeof(arguments[a]) == "string" ||
790
+ typeof(arguments[a]) == "number") {
791
+ node.appendChild(Strophe.xmlTextNode(arguments[a]));
792
+ } else if (typeof(arguments[a]) == "object" &&
793
+ typeof(arguments[a].sort) == "function") {
794
+ for (i = 0; i < arguments[a].length; i++) {
795
+ if (typeof(arguments[a][i]) == "object" &&
796
+ typeof(arguments[a][i].sort) == "function") {
797
+ node.setAttribute(arguments[a][i][0],
798
+ arguments[a][i][1]);
799
+ }
800
+ }
801
+ } else if (typeof(arguments[a]) == "object") {
802
+ for (k in arguments[a]) {
803
+ if (arguments[a].hasOwnProperty(k)) {
804
+ node.setAttribute(k, arguments[a][k]);
805
+ }
806
+ }
807
+ }
808
+ }
809
+
810
+ return node;
811
+ },
812
+
813
+ /* Function: xmlescape
814
+ * Excapes invalid xml characters.
815
+ *
816
+ * Parameters:
817
+ * (String) text - text to escape.
818
+ *
819
+ * Returns:
820
+ * Escaped text.
821
+ */
822
+ xmlescape: function(text)
823
+ {
824
+ text = text.replace(/\&/g, "&amp;");
825
+ text = text.replace(/</g, "&lt;");
826
+ text = text.replace(/>/g, "&gt;");
827
+ text = text.replace(/'/g, "&apos;");
828
+ text = text.replace(/"/g, "&quot;");
829
+ return text;
830
+ },
831
+
832
+ /** Function: xmlTextNode
833
+ * Creates an XML DOM text node.
834
+ *
835
+ * Provides a cross implementation version of document.createTextNode.
836
+ *
837
+ * Parameters:
838
+ * (String) text - The content of the text node.
839
+ *
840
+ * Returns:
841
+ * A new XML DOM text node.
842
+ */
843
+ xmlTextNode: function (text)
844
+ {
845
+ //ensure text is escaped
846
+ text = Strophe.xmlescape(text);
847
+
848
+ return Strophe.xmlGenerator().createTextNode(text);
849
+ },
850
+
851
+ /** Function: getText
852
+ * Get the concatenation of all text children of an element.
853
+ *
854
+ * Parameters:
855
+ * (XMLElement) elem - A DOM element.
856
+ *
857
+ * Returns:
858
+ * A String with the concatenated text of all text element children.
859
+ */
860
+ getText: function (elem)
861
+ {
862
+ if (!elem) { return null; }
863
+
864
+ var str = "";
865
+ if (elem.childNodes.length === 0 && elem.nodeType ==
866
+ Strophe.ElementType.TEXT) {
867
+ str += elem.nodeValue;
868
+ }
869
+
870
+ for (var i = 0; i < elem.childNodes.length; i++) {
871
+ if (elem.childNodes[i].nodeType == Strophe.ElementType.TEXT) {
872
+ str += elem.childNodes[i].nodeValue;
873
+ }
874
+ }
875
+
876
+ return str;
877
+ },
878
+
879
+ /** Function: copyElement
880
+ * Copy an XML DOM element.
881
+ *
882
+ * This function copies a DOM element and all its descendants and returns
883
+ * the new copy.
884
+ *
885
+ * Parameters:
886
+ * (XMLElement) elem - A DOM element.
887
+ *
888
+ * Returns:
889
+ * A new, copied DOM element tree.
890
+ */
891
+ copyElement: function (elem)
892
+ {
893
+ var i, el;
894
+ if (elem.nodeType == Strophe.ElementType.NORMAL) {
895
+ el = Strophe.xmlElement(elem.tagName);
896
+
897
+ for (i = 0; i < elem.attributes.length; i++) {
898
+ el.setAttribute(elem.attributes[i].nodeName.toLowerCase(),
899
+ elem.attributes[i].value);
900
+ }
901
+
902
+ for (i = 0; i < elem.childNodes.length; i++) {
903
+ el.appendChild(Strophe.copyElement(elem.childNodes[i]));
904
+ }
905
+ } else if (elem.nodeType == Strophe.ElementType.TEXT) {
906
+ el = Strophe.xmlGenerator().createTextNode(elem.nodeValue);
907
+ }
908
+
909
+ return el;
910
+ },
911
+
912
+ /** Function: escapeNode
913
+ * Escape the node part (also called local part) of a JID.
914
+ *
915
+ * Parameters:
916
+ * (String) node - A node (or local part).
917
+ *
918
+ * Returns:
919
+ * An escaped node (or local part).
920
+ */
921
+ escapeNode: function (node)
922
+ {
923
+ return node.replace(/^\s+|\s+$/g, '')
924
+ .replace(/\\/g, "\\5c")
925
+ .replace(/ /g, "\\20")
926
+ .replace(/\"/g, "\\22")
927
+ .replace(/\&/g, "\\26")
928
+ .replace(/\'/g, "\\27")
929
+ .replace(/\//g, "\\2f")
930
+ .replace(/:/g, "\\3a")
931
+ .replace(/</g, "\\3c")
932
+ .replace(/>/g, "\\3e")
933
+ .replace(/@/g, "\\40");
934
+ },
935
+
936
+ /** Function: unescapeNode
937
+ * Unescape a node part (also called local part) of a JID.
938
+ *
939
+ * Parameters:
940
+ * (String) node - A node (or local part).
941
+ *
942
+ * Returns:
943
+ * An unescaped node (or local part).
944
+ */
945
+ unescapeNode: function (node)
946
+ {
947
+ return node.replace(/\\20/g, " ")
948
+ .replace(/\\22/g, '"')
949
+ .replace(/\\26/g, "&")
950
+ .replace(/\\27/g, "'")
951
+ .replace(/\\2f/g, "/")
952
+ .replace(/\\3a/g, ":")
953
+ .replace(/\\3c/g, "<")
954
+ .replace(/\\3e/g, ">")
955
+ .replace(/\\40/g, "@")
956
+ .replace(/\\5c/g, "\\");
957
+ },
958
+
959
+ /** Function: getNodeFromJid
960
+ * Get the node portion of a JID String.
961
+ *
962
+ * Parameters:
963
+ * (String) jid - A JID.
964
+ *
965
+ * Returns:
966
+ * A String containing the node.
967
+ */
968
+ getNodeFromJid: function (jid)
969
+ {
970
+ if (jid.indexOf("@") < 0) { return null; }
971
+ return jid.split("@")[0];
972
+ },
973
+
974
+ /** Function: getDomainFromJid
975
+ * Get the domain portion of a JID String.
976
+ *
977
+ * Parameters:
978
+ * (String) jid - A JID.
979
+ *
980
+ * Returns:
981
+ * A String containing the domain.
982
+ */
983
+ getDomainFromJid: function (jid)
984
+ {
985
+ var bare = Strophe.getBareJidFromJid(jid);
986
+ if (bare.indexOf("@") < 0) {
987
+ return bare;
988
+ } else {
989
+ var parts = bare.split("@");
990
+ parts.splice(0, 1);
991
+ return parts.join('@');
992
+ }
993
+ },
994
+
995
+ /** Function: getResourceFromJid
996
+ * Get the resource portion of a JID String.
997
+ *
998
+ * Parameters:
999
+ * (String) jid - A JID.
1000
+ *
1001
+ * Returns:
1002
+ * A String containing the resource.
1003
+ */
1004
+ getResourceFromJid: function (jid)
1005
+ {
1006
+ var s = jid.split("/");
1007
+ if (s.length < 2) { return null; }
1008
+ s.splice(0, 1);
1009
+ return s.join('/');
1010
+ },
1011
+
1012
+ /** Function: getBareJidFromJid
1013
+ * Get the bare JID from a JID String.
1014
+ *
1015
+ * Parameters:
1016
+ * (String) jid - A JID.
1017
+ *
1018
+ * Returns:
1019
+ * A String containing the bare JID.
1020
+ */
1021
+ getBareJidFromJid: function (jid)
1022
+ {
1023
+ return jid ? jid.split("/")[0] : null;
1024
+ },
1025
+
1026
+ /** Function: log
1027
+ * User overrideable logging function.
1028
+ *
1029
+ * This function is called whenever the Strophe library calls any
1030
+ * of the logging functions. The default implementation of this
1031
+ * function does nothing. If client code wishes to handle the logging
1032
+ * messages, it should override this with
1033
+ * > Strophe.log = function (level, msg) {
1034
+ * > (user code here)
1035
+ * > };
1036
+ *
1037
+ * Please note that data sent and received over the wire is logged
1038
+ * via Strophe.Connection.rawInput() and Strophe.Connection.rawOutput().
1039
+ *
1040
+ * The different levels and their meanings are
1041
+ *
1042
+ * DEBUG - Messages useful for debugging purposes.
1043
+ * INFO - Informational messages. This is mostly information like
1044
+ * 'disconnect was called' or 'SASL auth succeeded'.
1045
+ * WARN - Warnings about potential problems. This is mostly used
1046
+ * to report transient connection errors like request timeouts.
1047
+ * ERROR - Some error occurred.
1048
+ * FATAL - A non-recoverable fatal error occurred.
1049
+ *
1050
+ * Parameters:
1051
+ * (Integer) level - The log level of the log message. This will
1052
+ * be one of the values in Strophe.LogLevel.
1053
+ * (String) msg - The log message.
1054
+ */
1055
+ log: function (level, msg)
1056
+ {
1057
+ return;
1058
+ },
1059
+
1060
+ /** Function: debug
1061
+ * Log a message at the Strophe.LogLevel.DEBUG level.
1062
+ *
1063
+ * Parameters:
1064
+ * (String) msg - The log message.
1065
+ */
1066
+ debug: function(msg)
1067
+ {
1068
+ this.log(this.LogLevel.DEBUG, msg);
1069
+ },
1070
+
1071
+ /** Function: info
1072
+ * Log a message at the Strophe.LogLevel.INFO level.
1073
+ *
1074
+ * Parameters:
1075
+ * (String) msg - The log message.
1076
+ */
1077
+ info: function (msg)
1078
+ {
1079
+ this.log(this.LogLevel.INFO, msg);
1080
+ },
1081
+
1082
+ /** Function: warn
1083
+ * Log a message at the Strophe.LogLevel.WARN level.
1084
+ *
1085
+ * Parameters:
1086
+ * (String) msg - The log message.
1087
+ */
1088
+ warn: function (msg)
1089
+ {
1090
+ this.log(this.LogLevel.WARN, msg);
1091
+ },
1092
+
1093
+ /** Function: error
1094
+ * Log a message at the Strophe.LogLevel.ERROR level.
1095
+ *
1096
+ * Parameters:
1097
+ * (String) msg - The log message.
1098
+ */
1099
+ error: function (msg)
1100
+ {
1101
+ this.log(this.LogLevel.ERROR, msg);
1102
+ },
1103
+
1104
+ /** Function: fatal
1105
+ * Log a message at the Strophe.LogLevel.FATAL level.
1106
+ *
1107
+ * Parameters:
1108
+ * (String) msg - The log message.
1109
+ */
1110
+ fatal: function (msg)
1111
+ {
1112
+ this.log(this.LogLevel.FATAL, msg);
1113
+ },
1114
+
1115
+ /** Function: serialize
1116
+ * Render a DOM element and all descendants to a String.
1117
+ *
1118
+ * Parameters:
1119
+ * (XMLElement) elem - A DOM element.
1120
+ *
1121
+ * Returns:
1122
+ * The serialized element tree as a String.
1123
+ */
1124
+ serialize: function (elem)
1125
+ {
1126
+ var result;
1127
+
1128
+ if (!elem) { return null; }
1129
+
1130
+ if (typeof(elem.tree) === "function") {
1131
+ elem = elem.tree();
1132
+ }
1133
+
1134
+ var nodeName = elem.nodeName;
1135
+ var i, child;
1136
+
1137
+ if (elem.getAttribute("_realname")) {
1138
+ nodeName = elem.getAttribute("_realname");
1139
+ }
1140
+
1141
+ result = "<" + nodeName;
1142
+ for (i = 0; i < elem.attributes.length; i++) {
1143
+ if(elem.attributes[i].nodeName != "_realname") {
1144
+ result += " " + elem.attributes[i].nodeName.toLowerCase() +
1145
+ "='" + elem.attributes[i].value
1146
+ .replace(/&/g, "&amp;")
1147
+ .replace(/\'/g, "&apos;")
1148
+ .replace(/</g, "&lt;") + "'";
1149
+ }
1150
+ }
1151
+
1152
+ if (elem.childNodes.length > 0) {
1153
+ result += ">";
1154
+ for (i = 0; i < elem.childNodes.length; i++) {
1155
+ child = elem.childNodes[i];
1156
+ switch( child.nodeType ){
1157
+ case Strophe.ElementType.NORMAL:
1158
+ // normal element, so recurse
1159
+ result += Strophe.serialize(child);
1160
+ break;
1161
+ case Strophe.ElementType.TEXT:
1162
+ // text element to escape values
1163
+ result += Strophe.xmlescape(child.nodeValue);
1164
+ break;
1165
+ case Strophe.ElementType.CDATA:
1166
+ // cdata section so don't escape values
1167
+ result += "<![CDATA["+child.nodeValue+"]]>";
1168
+ }
1169
+ }
1170
+ result += "</" + nodeName + ">";
1171
+ } else {
1172
+ result += "/>";
1173
+ }
1174
+
1175
+ return result;
1176
+ },
1177
+
1178
+ /** PrivateVariable: _requestId
1179
+ * _Private_ variable that keeps track of the request ids for
1180
+ * connections.
1181
+ */
1182
+ _requestId: 0,
1183
+
1184
+ /** PrivateVariable: Strophe.connectionPlugins
1185
+ * _Private_ variable Used to store plugin names that need
1186
+ * initialization on Strophe.Connection construction.
1187
+ */
1188
+ _connectionPlugins: {},
1189
+
1190
+ /** Function: addConnectionPlugin
1191
+ * Extends the Strophe.Connection object with the given plugin.
1192
+ *
1193
+ * Parameters:
1194
+ * (String) name - The name of the extension.
1195
+ * (Object) ptype - The plugin's prototype.
1196
+ */
1197
+ addConnectionPlugin: function (name, ptype)
1198
+ {
1199
+ Strophe._connectionPlugins[name] = ptype;
1200
+ }
1201
+ };
1202
+
1203
+ /** Class: Strophe.Builder
1204
+ * XML DOM builder.
1205
+ *
1206
+ * This object provides an interface similar to JQuery but for building
1207
+ * DOM element easily and rapidly. All the functions except for toString()
1208
+ * and tree() return the object, so calls can be chained. Here's an
1209
+ * example using the $iq() builder helper.
1210
+ * > $iq({to: 'you', from: 'me', type: 'get', id: '1'})
1211
+ * > .c('query', {xmlns: 'strophe:example'})
1212
+ * > .c('example')
1213
+ * > .toString()
1214
+ * The above generates this XML fragment
1215
+ * > <iq to='you' from='me' type='get' id='1'>
1216
+ * > <query xmlns='strophe:example'>
1217
+ * > <example/>
1218
+ * > </query>
1219
+ * > </iq>
1220
+ * The corresponding DOM manipulations to get a similar fragment would be
1221
+ * a lot more tedious and probably involve several helper variables.
1222
+ *
1223
+ * Since adding children makes new operations operate on the child, up()
1224
+ * is provided to traverse up the tree. To add two children, do
1225
+ * > builder.c('child1', ...).up().c('child2', ...)
1226
+ * The next operation on the Builder will be relative to the second child.
1227
+ */
1228
+
1229
+ /** Constructor: Strophe.Builder
1230
+ * Create a Strophe.Builder object.
1231
+ *
1232
+ * The attributes should be passed in object notation. For example
1233
+ * > var b = new Builder('message', {to: 'you', from: 'me'});
1234
+ * or
1235
+ * > var b = new Builder('messsage', {'xml:lang': 'en'});
1236
+ *
1237
+ * Parameters:
1238
+ * (String) name - The name of the root element.
1239
+ * (Object) attrs - The attributes for the root element in object notation.
1240
+ *
1241
+ * Returns:
1242
+ * A new Strophe.Builder.
1243
+ */
1244
+ Strophe.Builder = function (name, attrs)
1245
+ {
1246
+ // Set correct namespace for jabber:client elements
1247
+ if (name == "presence" || name == "message" || name == "iq") {
1248
+ if (attrs && !attrs.xmlns) {
1249
+ attrs.xmlns = Strophe.NS.CLIENT;
1250
+ } else if (!attrs) {
1251
+ attrs = {xmlns: Strophe.NS.CLIENT};
1252
+ }
1253
+ }
1254
+
1255
+ // Holds the tree being built.
1256
+ this.nodeTree = Strophe.xmlElement(name, attrs);
1257
+
1258
+ // Points to the current operation node.
1259
+ this.node = this.nodeTree;
1260
+ };
1261
+
1262
+ Strophe.Builder.prototype = {
1263
+ /** Function: tree
1264
+ * Return the DOM tree.
1265
+ *
1266
+ * This function returns the current DOM tree as an element object. This
1267
+ * is suitable for passing to functions like Strophe.Connection.send().
1268
+ *
1269
+ * Returns:
1270
+ * The DOM tree as a element object.
1271
+ */
1272
+ tree: function ()
1273
+ {
1274
+ return this.nodeTree;
1275
+ },
1276
+
1277
+ /** Function: toString
1278
+ * Serialize the DOM tree to a String.
1279
+ *
1280
+ * This function returns a string serialization of the current DOM
1281
+ * tree. It is often used internally to pass data to a
1282
+ * Strophe.Request object.
1283
+ *
1284
+ * Returns:
1285
+ * The serialized DOM tree in a String.
1286
+ */
1287
+ toString: function ()
1288
+ {
1289
+ return Strophe.serialize(this.nodeTree);
1290
+ },
1291
+
1292
+ /** Function: up
1293
+ * Make the current parent element the new current element.
1294
+ *
1295
+ * This function is often used after c() to traverse back up the tree.
1296
+ * For example, to add two children to the same element
1297
+ * > builder.c('child1', {}).up().c('child2', {});
1298
+ *
1299
+ * Returns:
1300
+ * The Stophe.Builder object.
1301
+ */
1302
+ up: function ()
1303
+ {
1304
+ this.node = this.node.parentNode;
1305
+ return this;
1306
+ },
1307
+
1308
+ /** Function: attrs
1309
+ * Add or modify attributes of the current element.
1310
+ *
1311
+ * The attributes should be passed in object notation. This function
1312
+ * does not move the current element pointer.
1313
+ *
1314
+ * Parameters:
1315
+ * (Object) moreattrs - The attributes to add/modify in object notation.
1316
+ *
1317
+ * Returns:
1318
+ * The Strophe.Builder object.
1319
+ */
1320
+ attrs: function (moreattrs)
1321
+ {
1322
+ for (var k in moreattrs) {
1323
+ if (moreattrs.hasOwnProperty(k)) {
1324
+ this.node.setAttribute(k, moreattrs[k]);
1325
+ }
1326
+ }
1327
+ return this;
1328
+ },
1329
+
1330
+ /** Function: c
1331
+ * Add a child to the current element and make it the new current
1332
+ * element.
1333
+ *
1334
+ * This function moves the current element pointer to the child,
1335
+ * unless text is provided. If you need to add another child, it
1336
+ * is necessary to use up() to go back to the parent in the tree.
1337
+ *
1338
+ * Parameters:
1339
+ * (String) name - The name of the child.
1340
+ * (Object) attrs - The attributes of the child in object notation.
1341
+ * (String) text - The text to add to the child.
1342
+ *
1343
+ * Returns:
1344
+ * The Strophe.Builder object.
1345
+ */
1346
+ c: function (name, attrs, text)
1347
+ {
1348
+ var child = Strophe.xmlElement(name, attrs, text);
1349
+ this.node.appendChild(child);
1350
+ if (!text) {
1351
+ this.node = child;
1352
+ }
1353
+ return this;
1354
+ },
1355
+
1356
+ /** Function: cnode
1357
+ * Add a child to the current element and make it the new current
1358
+ * element.
1359
+ *
1360
+ * This function is the same as c() except that instead of using a
1361
+ * name and an attributes object to create the child it uses an
1362
+ * existing DOM element object.
1363
+ *
1364
+ * Parameters:
1365
+ * (XMLElement) elem - A DOM element.
1366
+ *
1367
+ * Returns:
1368
+ * The Strophe.Builder object.
1369
+ */
1370
+ cnode: function (elem)
1371
+ {
1372
+ var xmlGen = Strophe.xmlGenerator();
1373
+ try {
1374
+ var impNode = (xmlGen.importNode !== undefined);
1375
+ }
1376
+ catch (e) {
1377
+ var impNode = false;
1378
+ }
1379
+ var newElem = impNode ?
1380
+ xmlGen.importNode(elem, true) :
1381
+ Strophe.copyElement(elem);
1382
+ this.node.appendChild(newElem);
1383
+ this.node = newElem;
1384
+ return this;
1385
+ },
1386
+
1387
+ /** Function: t
1388
+ * Add a child text element.
1389
+ *
1390
+ * This *does not* make the child the new current element since there
1391
+ * are no children of text elements.
1392
+ *
1393
+ * Parameters:
1394
+ * (String) text - The text data to append to the current element.
1395
+ *
1396
+ * Returns:
1397
+ * The Strophe.Builder object.
1398
+ */
1399
+ t: function (text)
1400
+ {
1401
+ var child = Strophe.xmlTextNode(text);
1402
+ this.node.appendChild(child);
1403
+ return this;
1404
+ }
1405
+ };
1406
+
1407
+
1408
+ /** PrivateClass: Strophe.Handler
1409
+ * _Private_ helper class for managing stanza handlers.
1410
+ *
1411
+ * A Strophe.Handler encapsulates a user provided callback function to be
1412
+ * executed when matching stanzas are received by the connection.
1413
+ * Handlers can be either one-off or persistant depending on their
1414
+ * return value. Returning true will cause a Handler to remain active, and
1415
+ * returning false will remove the Handler.
1416
+ *
1417
+ * Users will not use Strophe.Handler objects directly, but instead they
1418
+ * will use Strophe.Connection.addHandler() and
1419
+ * Strophe.Connection.deleteHandler().
1420
+ */
1421
+
1422
+ /** PrivateConstructor: Strophe.Handler
1423
+ * Create and initialize a new Strophe.Handler.
1424
+ *
1425
+ * Parameters:
1426
+ * (Function) handler - A function to be executed when the handler is run.
1427
+ * (String) ns - The namespace to match.
1428
+ * (String) name - The element name to match.
1429
+ * (String) type - The element type to match.
1430
+ * (String) id - The element id attribute to match.
1431
+ * (String) from - The element from attribute to match.
1432
+ * (Object) options - Handler options
1433
+ *
1434
+ * Returns:
1435
+ * A new Strophe.Handler object.
1436
+ */
1437
+ Strophe.Handler = function (handler, ns, name, type, id, from, options)
1438
+ {
1439
+ this.handler = handler;
1440
+ this.ns = ns;
1441
+ this.name = name;
1442
+ this.type = type;
1443
+ this.id = id;
1444
+ this.options = options || {matchbare: false};
1445
+
1446
+ // default matchBare to false if undefined
1447
+ if (!this.options.matchBare) {
1448
+ this.options.matchBare = false;
1449
+ }
1450
+
1451
+ if (this.options.matchBare) {
1452
+ this.from = from ? Strophe.getBareJidFromJid(from) : null;
1453
+ } else {
1454
+ this.from = from;
1455
+ }
1456
+
1457
+ // whether the handler is a user handler or a system handler
1458
+ this.user = true;
1459
+ };
1460
+
1461
+ Strophe.Handler.prototype = {
1462
+ /** PrivateFunction: isMatch
1463
+ * Tests if a stanza matches the Strophe.Handler.
1464
+ *
1465
+ * Parameters:
1466
+ * (XMLElement) elem - The XML element to test.
1467
+ *
1468
+ * Returns:
1469
+ * true if the stanza matches and false otherwise.
1470
+ */
1471
+ isMatch: function (elem)
1472
+ {
1473
+ var nsMatch;
1474
+ var from = null;
1475
+
1476
+ if (this.options.matchBare) {
1477
+ from = Strophe.getBareJidFromJid(elem.getAttribute('from'));
1478
+ } else {
1479
+ from = elem.getAttribute('from');
1480
+ }
1481
+
1482
+ nsMatch = false;
1483
+ if (!this.ns) {
1484
+ nsMatch = true;
1485
+ } else {
1486
+ var that = this;
1487
+ Strophe.forEachChild(elem, null, function (elem) {
1488
+ if (elem.getAttribute("xmlns") == that.ns) {
1489
+ nsMatch = true;
1490
+ }
1491
+ });
1492
+
1493
+ nsMatch = nsMatch || elem.getAttribute("xmlns") == this.ns;
1494
+ }
1495
+
1496
+ if (nsMatch &&
1497
+ (!this.name || Strophe.isTagEqual(elem, this.name)) &&
1498
+ (!this.type || elem.getAttribute("type") == this.type) &&
1499
+ (!this.id || elem.getAttribute("id") == this.id) &&
1500
+ (!this.from || from == this.from)) {
1501
+ return true;
1502
+ }
1503
+
1504
+ return false;
1505
+ },
1506
+
1507
+ /** PrivateFunction: run
1508
+ * Run the callback on a matching stanza.
1509
+ *
1510
+ * Parameters:
1511
+ * (XMLElement) elem - The DOM element that triggered the
1512
+ * Strophe.Handler.
1513
+ *
1514
+ * Returns:
1515
+ * A boolean indicating if the handler should remain active.
1516
+ */
1517
+ run: function (elem)
1518
+ {
1519
+ var result = null;
1520
+ try {
1521
+ result = this.handler(elem);
1522
+ } catch (e) {
1523
+ if (e.sourceURL) {
1524
+ Strophe.fatal("error: " + this.handler +
1525
+ " " + e.sourceURL + ":" +
1526
+ e.line + " - " + e.name + ": " + e.message);
1527
+ } else if (e.fileName) {
1528
+ if (typeof(console) != "undefined") {
1529
+ console.trace();
1530
+ console.error(this.handler, " - error - ", e, e.message);
1531
+ }
1532
+ Strophe.fatal("error: " + this.handler + " " +
1533
+ e.fileName + ":" + e.lineNumber + " - " +
1534
+ e.name + ": " + e.message);
1535
+ } else {
1536
+ Strophe.fatal("error: " + this.handler);
1537
+ }
1538
+
1539
+ throw e;
1540
+ }
1541
+
1542
+ return result;
1543
+ },
1544
+
1545
+ /** PrivateFunction: toString
1546
+ * Get a String representation of the Strophe.Handler object.
1547
+ *
1548
+ * Returns:
1549
+ * A String.
1550
+ */
1551
+ toString: function ()
1552
+ {
1553
+ return "{Handler: " + this.handler + "(" + this.name + "," +
1554
+ this.id + "," + this.ns + ")}";
1555
+ }
1556
+ };
1557
+
1558
+ /** PrivateClass: Strophe.TimedHandler
1559
+ * _Private_ helper class for managing timed handlers.
1560
+ *
1561
+ * A Strophe.TimedHandler encapsulates a user provided callback that
1562
+ * should be called after a certain period of time or at regular
1563
+ * intervals. The return value of the callback determines whether the
1564
+ * Strophe.TimedHandler will continue to fire.
1565
+ *
1566
+ * Users will not use Strophe.TimedHandler objects directly, but instead
1567
+ * they will use Strophe.Connection.addTimedHandler() and
1568
+ * Strophe.Connection.deleteTimedHandler().
1569
+ */
1570
+
1571
+ /** PrivateConstructor: Strophe.TimedHandler
1572
+ * Create and initialize a new Strophe.TimedHandler object.
1573
+ *
1574
+ * Parameters:
1575
+ * (Integer) period - The number of milliseconds to wait before the
1576
+ * handler is called.
1577
+ * (Function) handler - The callback to run when the handler fires. This
1578
+ * function should take no arguments.
1579
+ *
1580
+ * Returns:
1581
+ * A new Strophe.TimedHandler object.
1582
+ */
1583
+ Strophe.TimedHandler = function (period, handler)
1584
+ {
1585
+ this.period = period;
1586
+ this.handler = handler;
1587
+
1588
+ this.lastCalled = new Date().getTime();
1589
+ this.user = true;
1590
+ };
1591
+
1592
+ Strophe.TimedHandler.prototype = {
1593
+ /** PrivateFunction: run
1594
+ * Run the callback for the Strophe.TimedHandler.
1595
+ *
1596
+ * Returns:
1597
+ * true if the Strophe.TimedHandler should be called again, and false
1598
+ * otherwise.
1599
+ */
1600
+ run: function ()
1601
+ {
1602
+ this.lastCalled = new Date().getTime();
1603
+ return this.handler();
1604
+ },
1605
+
1606
+ /** PrivateFunction: reset
1607
+ * Reset the last called time for the Strophe.TimedHandler.
1608
+ */
1609
+ reset: function ()
1610
+ {
1611
+ this.lastCalled = new Date().getTime();
1612
+ },
1613
+
1614
+ /** PrivateFunction: toString
1615
+ * Get a string representation of the Strophe.TimedHandler object.
1616
+ *
1617
+ * Returns:
1618
+ * The string representation.
1619
+ */
1620
+ toString: function ()
1621
+ {
1622
+ return "{TimedHandler: " + this.handler + "(" + this.period +")}";
1623
+ }
1624
+ };
1625
+
1626
+ /** PrivateClass: Strophe.Request
1627
+ * _Private_ helper class that provides a cross implementation abstraction
1628
+ * for a BOSH related XMLHttpRequest.
1629
+ *
1630
+ * The Strophe.Request class is used internally to encapsulate BOSH request
1631
+ * information. It is not meant to be used from user's code.
1632
+ */
1633
+
1634
+ /** PrivateConstructor: Strophe.Request
1635
+ * Create and initialize a new Strophe.Request object.
1636
+ *
1637
+ * Parameters:
1638
+ * (XMLElement) elem - The XML data to be sent in the request.
1639
+ * (Function) func - The function that will be called when the
1640
+ * XMLHttpRequest readyState changes.
1641
+ * (Integer) rid - The BOSH rid attribute associated with this request.
1642
+ * (Integer) sends - The number of times this same request has been
1643
+ * sent.
1644
+ */
1645
+ Strophe.Request = function (elem, func, rid, sends)
1646
+ {
1647
+ this.id = ++Strophe._requestId;
1648
+ this.xmlData = elem;
1649
+ this.data = Strophe.serialize(elem);
1650
+ // save original function in case we need to make a new request
1651
+ // from this one.
1652
+ this.origFunc = func;
1653
+ this.func = func;
1654
+ this.rid = rid;
1655
+ this.date = NaN;
1656
+ this.sends = sends || 0;
1657
+ this.abort = false;
1658
+ this.dead = null;
1659
+ this.age = function () {
1660
+ if (!this.date) { return 0; }
1661
+ var now = new Date();
1662
+ return (now - this.date) / 1000;
1663
+ };
1664
+ this.timeDead = function () {
1665
+ if (!this.dead) { return 0; }
1666
+ var now = new Date();
1667
+ return (now - this.dead) / 1000;
1668
+ };
1669
+ this.xhr = this._newXHR();
1670
+ };
1671
+
1672
+ Strophe.Request.prototype = {
1673
+ /** PrivateFunction: getResponse
1674
+ * Get a response from the underlying XMLHttpRequest.
1675
+ *
1676
+ * This function attempts to get a response from the request and checks
1677
+ * for errors.
1678
+ *
1679
+ * Throws:
1680
+ * "parsererror" - A parser error occured.
1681
+ *
1682
+ * Returns:
1683
+ * The DOM element tree of the response.
1684
+ */
1685
+ getResponse: function ()
1686
+ {
1687
+ var node = null;
1688
+ if (this.xhr.responseXML && this.xhr.responseXML.documentElement) {
1689
+ node = this.xhr.responseXML.documentElement;
1690
+ if (node.tagName == "parsererror") {
1691
+ Strophe.error("invalid response received");
1692
+ Strophe.error("responseText: " + this.xhr.responseText);
1693
+ Strophe.error("responseXML: " +
1694
+ Strophe.serialize(this.xhr.responseXML));
1695
+ throw "parsererror";
1696
+ }
1697
+ } else if (this.xhr.responseText) {
1698
+ Strophe.error("invalid response received");
1699
+ Strophe.error("responseText: " + this.xhr.responseText);
1700
+ Strophe.error("responseXML: " +
1701
+ Strophe.serialize(this.xhr.responseXML));
1702
+ }
1703
+
1704
+ return node;
1705
+ },
1706
+
1707
+ /** PrivateFunction: _newXHR
1708
+ * _Private_ helper function to create XMLHttpRequests.
1709
+ *
1710
+ * This function creates XMLHttpRequests across all implementations.
1711
+ *
1712
+ * Returns:
1713
+ * A new XMLHttpRequest.
1714
+ */
1715
+ _newXHR: function ()
1716
+ {
1717
+ var xhr = null;
1718
+ if (window.XMLHttpRequest) {
1719
+ xhr = new XMLHttpRequest();
1720
+ if (xhr.overrideMimeType) {
1721
+ xhr.overrideMimeType("text/xml");
1722
+ }
1723
+ } else if (window.ActiveXObject) {
1724
+ xhr = new ActiveXObject("Microsoft.XMLHTTP");
1725
+ }
1726
+
1727
+ // use Function.bind() to prepend ourselves as an argument
1728
+ xhr.onreadystatechange = this.func.bind(null, this);
1729
+
1730
+ return xhr;
1731
+ }
1732
+ };
1733
+
1734
+ /** Class: Strophe.Connection
1735
+ * XMPP Connection manager.
1736
+ *
1737
+ * Thie class is the main part of Strophe. It manages a BOSH connection
1738
+ * to an XMPP server and dispatches events to the user callbacks as
1739
+ * data arrives. It supports SASL PLAIN, SASL DIGEST-MD5, and legacy
1740
+ * authentication.
1741
+ *
1742
+ * After creating a Strophe.Connection object, the user will typically
1743
+ * call connect() with a user supplied callback to handle connection level
1744
+ * events like authentication failure, disconnection, or connection
1745
+ * complete.
1746
+ *
1747
+ * The user will also have several event handlers defined by using
1748
+ * addHandler() and addTimedHandler(). These will allow the user code to
1749
+ * respond to interesting stanzas or do something periodically with the
1750
+ * connection. These handlers will be active once authentication is
1751
+ * finished.
1752
+ *
1753
+ * To send data to the connection, use send().
1754
+ */
1755
+
1756
+ /** Constructor: Strophe.Connection
1757
+ * Create and initialize a Strophe.Connection object.
1758
+ *
1759
+ * Parameters:
1760
+ * (String) service - The BOSH service URL.
1761
+ *
1762
+ * Returns:
1763
+ * A new Strophe.Connection object.
1764
+ */
1765
+ Strophe.Connection = function (service)
1766
+ {
1767
+ /* The path to the httpbind service. */
1768
+ this.service = service;
1769
+ /* The connected JID. */
1770
+ this.jid = "";
1771
+ /* request id for body tags */
1772
+ this.rid = Math.floor(Math.random() * 4294967295);
1773
+ /* The current session ID. */
1774
+ this.sid = null;
1775
+ this.streamId = null;
1776
+ /* stream:features */
1777
+ this.features = null;
1778
+
1779
+ // SASL
1780
+ this.do_session = false;
1781
+ this.do_bind = false;
1782
+
1783
+ // handler lists
1784
+ this.timedHandlers = [];
1785
+ this.handlers = [];
1786
+ this.removeTimeds = [];
1787
+ this.removeHandlers = [];
1788
+ this.addTimeds = [];
1789
+ this.addHandlers = [];
1790
+
1791
+ this._idleTimeout = null;
1792
+ this._disconnectTimeout = null;
1793
+
1794
+ this.authenticated = false;
1795
+ this.disconnecting = false;
1796
+ this.connected = false;
1797
+
1798
+ this.errors = 0;
1799
+
1800
+ this.paused = false;
1801
+
1802
+ // default BOSH values
1803
+ this.hold = 1;
1804
+ this.wait = 60;
1805
+ this.window = 5;
1806
+
1807
+ this._data = [];
1808
+ this._requests = [];
1809
+ this._uniqueId = Math.round(Math.random() * 10000);
1810
+
1811
+ this._sasl_success_handler = null;
1812
+ this._sasl_failure_handler = null;
1813
+ this._sasl_challenge_handler = null;
1814
+
1815
+ // setup onIdle callback every 1/10th of a second
1816
+ this._idleTimeout = setTimeout(this._onIdle.bind(this), 100);
1817
+
1818
+ // initialize plugins
1819
+ for (var k in Strophe._connectionPlugins) {
1820
+ if (Strophe._connectionPlugins.hasOwnProperty(k)) {
1821
+ var ptype = Strophe._connectionPlugins[k];
1822
+ // jslint complaints about the below line, but this is fine
1823
+ var F = function () {};
1824
+ F.prototype = ptype;
1825
+ this[k] = new F();
1826
+ this[k].init(this);
1827
+ }
1828
+ }
1829
+ };
1830
+
1831
+ Strophe.Connection.prototype = {
1832
+ /** Function: reset
1833
+ * Reset the connection.
1834
+ *
1835
+ * This function should be called after a connection is disconnected
1836
+ * before that connection is reused.
1837
+ */
1838
+ reset: function ()
1839
+ {
1840
+ this.rid = Math.floor(Math.random() * 4294967295);
1841
+
1842
+ this.sid = null;
1843
+ this.streamId = null;
1844
+
1845
+ // SASL
1846
+ this.do_session = false;
1847
+ this.do_bind = false;
1848
+
1849
+ // handler lists
1850
+ this.timedHandlers = [];
1851
+ this.handlers = [];
1852
+ this.removeTimeds = [];
1853
+ this.removeHandlers = [];
1854
+ this.addTimeds = [];
1855
+ this.addHandlers = [];
1856
+
1857
+ this.authenticated = false;
1858
+ this.disconnecting = false;
1859
+ this.connected = false;
1860
+
1861
+ this.errors = 0;
1862
+
1863
+ this._requests = [];
1864
+ this._uniqueId = Math.round(Math.random()*10000);
1865
+ },
1866
+
1867
+ /** Function: pause
1868
+ * Pause the request manager.
1869
+ *
1870
+ * This will prevent Strophe from sending any more requests to the
1871
+ * server. This is very useful for temporarily pausing while a lot
1872
+ * of send() calls are happening quickly. This causes Strophe to
1873
+ * send the data in a single request, saving many request trips.
1874
+ */
1875
+ pause: function ()
1876
+ {
1877
+ this.paused = true;
1878
+ },
1879
+
1880
+ /** Function: resume
1881
+ * Resume the request manager.
1882
+ *
1883
+ * This resumes after pause() has been called.
1884
+ */
1885
+ resume: function ()
1886
+ {
1887
+ this.paused = false;
1888
+ },
1889
+
1890
+ /** Function: getUniqueId
1891
+ * Generate a unique ID for use in <iq/> elements.
1892
+ *
1893
+ * All <iq/> stanzas are required to have unique id attributes. This
1894
+ * function makes creating these easy. Each connection instance has
1895
+ * a counter which starts from zero, and the value of this counter
1896
+ * plus a colon followed by the suffix becomes the unique id. If no
1897
+ * suffix is supplied, the counter is used as the unique id.
1898
+ *
1899
+ * Suffixes are used to make debugging easier when reading the stream
1900
+ * data, and their use is recommended. The counter resets to 0 for
1901
+ * every new connection for the same reason. For connections to the
1902
+ * same server that authenticate the same way, all the ids should be
1903
+ * the same, which makes it easy to see changes. This is useful for
1904
+ * automated testing as well.
1905
+ *
1906
+ * Parameters:
1907
+ * (String) suffix - A optional suffix to append to the id.
1908
+ *
1909
+ * Returns:
1910
+ * A unique string to be used for the id attribute.
1911
+ */
1912
+ getUniqueId: function (suffix)
1913
+ {
1914
+ if (typeof(suffix) == "string" || typeof(suffix) == "number") {
1915
+ return ++this._uniqueId + ":" + suffix;
1916
+ } else {
1917
+ return ++this._uniqueId + "";
1918
+ }
1919
+ },
1920
+
1921
+ /** Function: connect
1922
+ * Starts the connection process.
1923
+ *
1924
+ * As the connection process proceeds, the user supplied callback will
1925
+ * be triggered multiple times with status updates. The callback
1926
+ * should take two arguments - the status code and the error condition.
1927
+ *
1928
+ * The status code will be one of the values in the Strophe.Status
1929
+ * constants. The error condition will be one of the conditions
1930
+ * defined in RFC 3920 or the condition 'strophe-parsererror'.
1931
+ *
1932
+ * Please see XEP 124 for a more detailed explanation of the optional
1933
+ * parameters below.
1934
+ *
1935
+ * Parameters:
1936
+ * (String) jid - The user's JID. This may be a bare JID,
1937
+ * or a full JID. If a node is not supplied, SASL ANONYMOUS
1938
+ * authentication will be attempted.
1939
+ * (String) pass - The user's password.
1940
+ * (Function) callback - The connect callback function.
1941
+ * (Integer) wait - The optional HTTPBIND wait value. This is the
1942
+ * time the server will wait before returning an empty result for
1943
+ * a request. The default setting of 60 seconds is recommended.
1944
+ * Other settings will require tweaks to the Strophe.TIMEOUT value.
1945
+ * (Integer) hold - The optional HTTPBIND hold value. This is the
1946
+ * number of connections the server will hold at one time. This
1947
+ * should almost always be set to 1 (the default).
1948
+ */
1949
+ connect: function (jid, pass, callback, wait, hold)
1950
+ {
1951
+ this.jid = jid;
1952
+ this.pass = pass;
1953
+ this.connect_callback = callback;
1954
+ this.disconnecting = false;
1955
+ this.connected = false;
1956
+ this.authenticated = false;
1957
+ this.errors = 0;
1958
+
1959
+ this.wait = wait || this.wait;
1960
+ this.hold = hold || this.hold;
1961
+
1962
+ // parse jid for domain and resource
1963
+ this.domain = Strophe.getDomainFromJid(this.jid);
1964
+
1965
+ // build the body tag
1966
+ var body = this._buildBody().attrs({
1967
+ to: this.domain,
1968
+ "xml:lang": "en",
1969
+ wait: this.wait,
1970
+ hold: this.hold,
1971
+ content: "text/xml; charset=utf-8",
1972
+ ver: "1.6",
1973
+ "xmpp:version": "1.0",
1974
+ "xmlns:xmpp": Strophe.NS.BOSH
1975
+ });
1976
+
1977
+ this._changeConnectStatus(Strophe.Status.CONNECTING, null);
1978
+
1979
+ this._requests.push(
1980
+ new Strophe.Request(body.tree(),
1981
+ this._onRequestStateChange.bind(
1982
+ this, this._connect_cb.bind(this)),
1983
+ body.tree().getAttribute("rid")));
1984
+ this._throttledRequestHandler();
1985
+ },
1986
+
1987
+ /** Function: attach
1988
+ * Attach to an already created and authenticated BOSH session.
1989
+ *
1990
+ * This function is provided to allow Strophe to attach to BOSH
1991
+ * sessions which have been created externally, perhaps by a Web
1992
+ * application. This is often used to support auto-login type features
1993
+ * without putting user credentials into the page.
1994
+ *
1995
+ * Parameters:
1996
+ * (String) jid - The full JID that is bound by the session.
1997
+ * (String) sid - The SID of the BOSH session.
1998
+ * (String) rid - The current RID of the BOSH session. This RID
1999
+ * will be used by the next request.
2000
+ * (Function) callback The connect callback function.
2001
+ * (Integer) wait - The optional HTTPBIND wait value. This is the
2002
+ * time the server will wait before returning an empty result for
2003
+ * a request. The default setting of 60 seconds is recommended.
2004
+ * Other settings will require tweaks to the Strophe.TIMEOUT value.
2005
+ * (Integer) hold - The optional HTTPBIND hold value. This is the
2006
+ * number of connections the server will hold at one time. This
2007
+ * should almost always be set to 1 (the default).
2008
+ * (Integer) wind - The optional HTTBIND window value. This is the
2009
+ * allowed range of request ids that are valid. The default is 5.
2010
+ */
2011
+ attach: function (jid, sid, rid, callback, wait, hold, wind)
2012
+ {
2013
+ this.jid = jid;
2014
+ this.sid = sid;
2015
+ this.rid = rid;
2016
+ this.connect_callback = callback;
2017
+
2018
+ this.domain = Strophe.getDomainFromJid(this.jid);
2019
+
2020
+ this.authenticated = true;
2021
+ this.connected = true;
2022
+
2023
+ this.wait = wait || this.wait;
2024
+ this.hold = hold || this.hold;
2025
+ this.window = wind || this.window;
2026
+
2027
+ this._changeConnectStatus(Strophe.Status.ATTACHED, null);
2028
+ },
2029
+
2030
+ /** Function: xmlInput
2031
+ * User overrideable function that receives XML data coming into the
2032
+ * connection.
2033
+ *
2034
+ * The default function does nothing. User code can override this with
2035
+ * > Strophe.Connection.xmlInput = function (elem) {
2036
+ * > (user code)
2037
+ * > };
2038
+ *
2039
+ * Parameters:
2040
+ * (XMLElement) elem - The XML data received by the connection.
2041
+ */
2042
+ xmlInput: function (elem)
2043
+ {
2044
+ return;
2045
+ },
2046
+
2047
+ /** Function: xmlOutput
2048
+ * User overrideable function that receives XML data sent to the
2049
+ * connection.
2050
+ *
2051
+ * The default function does nothing. User code can override this with
2052
+ * > Strophe.Connection.xmlOutput = function (elem) {
2053
+ * > (user code)
2054
+ * > };
2055
+ *
2056
+ * Parameters:
2057
+ * (XMLElement) elem - The XMLdata sent by the connection.
2058
+ */
2059
+ xmlOutput: function (elem)
2060
+ {
2061
+ return;
2062
+ },
2063
+
2064
+ /** Function: rawInput
2065
+ * User overrideable function that receives raw data coming into the
2066
+ * connection.
2067
+ *
2068
+ * The default function does nothing. User code can override this with
2069
+ * > Strophe.Connection.rawInput = function (data) {
2070
+ * > (user code)
2071
+ * > };
2072
+ *
2073
+ * Parameters:
2074
+ * (String) data - The data received by the connection.
2075
+ */
2076
+ rawInput: function (data)
2077
+ {
2078
+ return;
2079
+ },
2080
+
2081
+ /** Function: rawOutput
2082
+ * User overrideable function that receives raw data sent to the
2083
+ * connection.
2084
+ *
2085
+ * The default function does nothing. User code can override this with
2086
+ * > Strophe.Connection.rawOutput = function (data) {
2087
+ * > (user code)
2088
+ * > };
2089
+ *
2090
+ * Parameters:
2091
+ * (String) data - The data sent by the connection.
2092
+ */
2093
+ rawOutput: function (data)
2094
+ {
2095
+ return;
2096
+ },
2097
+
2098
+ /** Function: send
2099
+ * Send a stanza.
2100
+ *
2101
+ * This function is called to push data onto the send queue to
2102
+ * go out over the wire. Whenever a request is sent to the BOSH
2103
+ * server, all pending data is sent and the queue is flushed.
2104
+ *
2105
+ * Parameters:
2106
+ * (XMLElement |
2107
+ * [XMLElement] |
2108
+ * Strophe.Builder) elem - The stanza to send.
2109
+ */
2110
+ send: function (elem)
2111
+ {
2112
+ if (elem === null) { return ; }
2113
+ if (typeof(elem.sort) === "function") {
2114
+ for (var i = 0; i < elem.length; i++) {
2115
+ this._queueData(elem[i]);
2116
+ }
2117
+ } else if (typeof(elem.tree) === "function") {
2118
+ this._queueData(elem.tree());
2119
+ } else {
2120
+ this._queueData(elem);
2121
+ }
2122
+
2123
+ this._throttledRequestHandler();
2124
+ clearTimeout(this._idleTimeout);
2125
+ this._idleTimeout = setTimeout(this._onIdle.bind(this), 100);
2126
+ },
2127
+
2128
+ /** Function: flush
2129
+ * Immediately send any pending outgoing data.
2130
+ *
2131
+ * Normally send() queues outgoing data until the next idle period
2132
+ * (100ms), which optimizes network use in the common cases when
2133
+ * several send()s are called in succession. flush() can be used to
2134
+ * immediately send all pending data.
2135
+ */
2136
+ flush: function ()
2137
+ {
2138
+ // cancel the pending idle period and run the idle function
2139
+ // immediately
2140
+ clearTimeout(this._idleTimeout);
2141
+ this._onIdle();
2142
+ },
2143
+
2144
+ /** Function: sendIQ
2145
+ * Helper function to send IQ stanzas.
2146
+ *
2147
+ * Parameters:
2148
+ * (XMLElement) elem - The stanza to send.
2149
+ * (Function) callback - The callback function for a successful request.
2150
+ * (Function) errback - The callback function for a failed or timed
2151
+ * out request. On timeout, the stanza will be null.
2152
+ * (Integer) timeout - The time specified in milliseconds for a
2153
+ * timeout to occur.
2154
+ *
2155
+ * Returns:
2156
+ * The id used to send the IQ.
2157
+ */
2158
+ sendIQ: function(elem, callback, errback, timeout) {
2159
+ var timeoutHandler = null;
2160
+ var that = this;
2161
+
2162
+ if (typeof(elem.tree) === "function") {
2163
+ elem = elem.tree();
2164
+ }
2165
+ var id = elem.getAttribute('id');
2166
+
2167
+ // inject id if not found
2168
+ if (!id) {
2169
+ id = this.getUniqueId("sendIQ");
2170
+ elem.setAttribute("id", id);
2171
+ }
2172
+
2173
+ var handler = this.addHandler(function (stanza) {
2174
+ // remove timeout handler if there is one
2175
+ if (timeoutHandler) {
2176
+ that.deleteTimedHandler(timeoutHandler);
2177
+ }
2178
+
2179
+ var iqtype = stanza.getAttribute('type');
2180
+ if (iqtype == 'result') {
2181
+ if (callback) {
2182
+ callback(stanza);
2183
+ }
2184
+ } else if (iqtype == 'error') {
2185
+ if (errback) {
2186
+ errback(stanza);
2187
+ }
2188
+ } else {
2189
+ throw {
2190
+ name: "StropheError",
2191
+ message: "Got bad IQ type of " + iqtype
2192
+ };
2193
+ }
2194
+ }, null, 'iq', null, id);
2195
+
2196
+ // if timeout specified, setup timeout handler.
2197
+ if (timeout) {
2198
+ timeoutHandler = this.addTimedHandler(timeout, function () {
2199
+ // get rid of normal handler
2200
+ that.deleteHandler(handler);
2201
+
2202
+ // call errback on timeout with null stanza
2203
+ if (errback) {
2204
+ errback(null);
2205
+ }
2206
+ return false;
2207
+ });
2208
+ }
2209
+
2210
+ this.send(elem);
2211
+
2212
+ return id;
2213
+ },
2214
+
2215
+ /** PrivateFunction: _queueData
2216
+ * Queue outgoing data for later sending. Also ensures that the data
2217
+ * is a DOMElement.
2218
+ */
2219
+ _queueData: function (element) {
2220
+ if (element === null ||
2221
+ !element.tagName ||
2222
+ !element.childNodes) {
2223
+ throw {
2224
+ name: "StropheError",
2225
+ message: "Cannot queue non-DOMElement."
2226
+ };
2227
+ }
2228
+
2229
+ this._data.push(element);
2230
+ },
2231
+
2232
+ /** PrivateFunction: _sendRestart
2233
+ * Send an xmpp:restart stanza.
2234
+ */
2235
+ _sendRestart: function ()
2236
+ {
2237
+ this._data.push("restart");
2238
+
2239
+ this._throttledRequestHandler();
2240
+ clearTimeout(this._idleTimeout);
2241
+ this._idleTimeout = setTimeout(this._onIdle.bind(this), 100);
2242
+ },
2243
+
2244
+ /** Function: addTimedHandler
2245
+ * Add a timed handler to the connection.
2246
+ *
2247
+ * This function adds a timed handler. The provided handler will
2248
+ * be called every period milliseconds until it returns false,
2249
+ * the connection is terminated, or the handler is removed. Handlers
2250
+ * that wish to continue being invoked should return true.
2251
+ *
2252
+ * Because of method binding it is necessary to save the result of
2253
+ * this function if you wish to remove a handler with
2254
+ * deleteTimedHandler().
2255
+ *
2256
+ * Note that user handlers are not active until authentication is
2257
+ * successful.
2258
+ *
2259
+ * Parameters:
2260
+ * (Integer) period - The period of the handler.
2261
+ * (Function) handler - The callback function.
2262
+ *
2263
+ * Returns:
2264
+ * A reference to the handler that can be used to remove it.
2265
+ */
2266
+ addTimedHandler: function (period, handler)
2267
+ {
2268
+ var thand = new Strophe.TimedHandler(period, handler);
2269
+ this.addTimeds.push(thand);
2270
+ return thand;
2271
+ },
2272
+
2273
+ /** Function: deleteTimedHandler
2274
+ * Delete a timed handler for a connection.
2275
+ *
2276
+ * This function removes a timed handler from the connection. The
2277
+ * handRef parameter is *not* the function passed to addTimedHandler(),
2278
+ * but is the reference returned from addTimedHandler().
2279
+ *
2280
+ * Parameters:
2281
+ * (Strophe.TimedHandler) handRef - The handler reference.
2282
+ */
2283
+ deleteTimedHandler: function (handRef)
2284
+ {
2285
+ // this must be done in the Idle loop so that we don't change
2286
+ // the handlers during iteration
2287
+ this.removeTimeds.push(handRef);
2288
+ },
2289
+
2290
+ /** Function: addHandler
2291
+ * Add a stanza handler for the connection.
2292
+ *
2293
+ * This function adds a stanza handler to the connection. The
2294
+ * handler callback will be called for any stanza that matches
2295
+ * the parameters. Note that if multiple parameters are supplied,
2296
+ * they must all match for the handler to be invoked.
2297
+ *
2298
+ * The handler will receive the stanza that triggered it as its argument.
2299
+ * The handler should return true if it is to be invoked again;
2300
+ * returning false will remove the handler after it returns.
2301
+ *
2302
+ * As a convenience, the ns parameters applies to the top level element
2303
+ * and also any of its immediate children. This is primarily to make
2304
+ * matching /iq/query elements easy.
2305
+ *
2306
+ * The options argument contains handler matching flags that affect how
2307
+ * matches are determined. Currently the only flag is matchBare (a
2308
+ * boolean). When matchBare is true, the from parameter and the from
2309
+ * attribute on the stanza will be matched as bare JIDs instead of
2310
+ * full JIDs. To use this, pass {matchBare: true} as the value of
2311
+ * options. The default value for matchBare is false.
2312
+ *
2313
+ * The return value should be saved if you wish to remove the handler
2314
+ * with deleteHandler().
2315
+ *
2316
+ * Parameters:
2317
+ * (Function) handler - The user callback.
2318
+ * (String) ns - The namespace to match.
2319
+ * (String) name - The stanza name to match.
2320
+ * (String) type - The stanza type attribute to match.
2321
+ * (String) id - The stanza id attribute to match.
2322
+ * (String) from - The stanza from attribute to match.
2323
+ * (String) options - The handler options
2324
+ *
2325
+ * Returns:
2326
+ * A reference to the handler that can be used to remove it.
2327
+ */
2328
+ addHandler: function (handler, ns, name, type, id, from, options)
2329
+ {
2330
+ var hand = new Strophe.Handler(handler, ns, name, type, id, from, options);
2331
+ this.addHandlers.push(hand);
2332
+ return hand;
2333
+ },
2334
+
2335
+ /** Function: deleteHandler
2336
+ * Delete a stanza handler for a connection.
2337
+ *
2338
+ * This function removes a stanza handler from the connection. The
2339
+ * handRef parameter is *not* the function passed to addHandler(),
2340
+ * but is the reference returned from addHandler().
2341
+ *
2342
+ * Parameters:
2343
+ * (Strophe.Handler) handRef - The handler reference.
2344
+ */
2345
+ deleteHandler: function (handRef)
2346
+ {
2347
+ // this must be done in the Idle loop so that we don't change
2348
+ // the handlers during iteration
2349
+ this.removeHandlers.push(handRef);
2350
+ },
2351
+
2352
+ /** Function: disconnect
2353
+ * Start the graceful disconnection process.
2354
+ *
2355
+ * This function starts the disconnection process. This process starts
2356
+ * by sending unavailable presence and sending BOSH body of type
2357
+ * terminate. A timeout handler makes sure that disconnection happens
2358
+ * even if the BOSH server does not respond.
2359
+ *
2360
+ * The user supplied connection callback will be notified of the
2361
+ * progress as this process happens.
2362
+ *
2363
+ * Parameters:
2364
+ * (String) reason - The reason the disconnect is occuring.
2365
+ */
2366
+ disconnect: function (reason)
2367
+ {
2368
+ this._changeConnectStatus(Strophe.Status.DISCONNECTING, reason);
2369
+
2370
+ Strophe.info("Disconnect was called because: " + reason);
2371
+ if (this.connected) {
2372
+ // setup timeout handler
2373
+ this._disconnectTimeout = this._addSysTimedHandler(
2374
+ 3000, this._onDisconnectTimeout.bind(this));
2375
+ this._sendTerminate();
2376
+ }
2377
+ },
2378
+
2379
+ /** PrivateFunction: _changeConnectStatus
2380
+ * _Private_ helper function that makes sure plugins and the user's
2381
+ * callback are notified of connection status changes.
2382
+ *
2383
+ * Parameters:
2384
+ * (Integer) status - the new connection status, one of the values
2385
+ * in Strophe.Status
2386
+ * (String) condition - the error condition or null
2387
+ */
2388
+ _changeConnectStatus: function (status, condition)
2389
+ {
2390
+ // notify all plugins listening for status changes
2391
+ for (var k in Strophe._connectionPlugins) {
2392
+ if (Strophe._connectionPlugins.hasOwnProperty(k)) {
2393
+ var plugin = this[k];
2394
+ if (plugin.statusChanged) {
2395
+ try {
2396
+ plugin.statusChanged(status, condition);
2397
+ } catch (err) {
2398
+ Strophe.error("" + k + " plugin caused an exception " +
2399
+ "changing status: " + err);
2400
+ }
2401
+ }
2402
+ }
2403
+ }
2404
+
2405
+ // notify the user's callback
2406
+ if (this.connect_callback) {
2407
+ try {
2408
+ this.connect_callback(status, condition);
2409
+ } catch (e) {
2410
+ Strophe.error("User connection callback caused an " +
2411
+ "exception: " + e);
2412
+ }
2413
+ }
2414
+ },
2415
+
2416
+ /** PrivateFunction: _buildBody
2417
+ * _Private_ helper function to generate the <body/> wrapper for BOSH.
2418
+ *
2419
+ * Returns:
2420
+ * A Strophe.Builder with a <body/> element.
2421
+ */
2422
+ _buildBody: function ()
2423
+ {
2424
+ var bodyWrap = $build('body', {
2425
+ rid: this.rid++,
2426
+ xmlns: Strophe.NS.HTTPBIND
2427
+ });
2428
+
2429
+ if (this.sid !== null) {
2430
+ bodyWrap.attrs({sid: this.sid});
2431
+ }
2432
+
2433
+ return bodyWrap;
2434
+ },
2435
+
2436
+ /** PrivateFunction: _removeRequest
2437
+ * _Private_ function to remove a request from the queue.
2438
+ *
2439
+ * Parameters:
2440
+ * (Strophe.Request) req - The request to remove.
2441
+ */
2442
+ _removeRequest: function (req)
2443
+ {
2444
+ Strophe.debug("removing request");
2445
+
2446
+ var i;
2447
+ for (i = this._requests.length - 1; i >= 0; i--) {
2448
+ if (req == this._requests[i]) {
2449
+ this._requests.splice(i, 1);
2450
+ }
2451
+ }
2452
+
2453
+ // IE6 fails on setting to null, so set to empty function
2454
+ req.xhr.onreadystatechange = function () {};
2455
+
2456
+ this._throttledRequestHandler();
2457
+ },
2458
+
2459
+ /** PrivateFunction: _restartRequest
2460
+ * _Private_ function to restart a request that is presumed dead.
2461
+ *
2462
+ * Parameters:
2463
+ * (Integer) i - The index of the request in the queue.
2464
+ */
2465
+ _restartRequest: function (i)
2466
+ {
2467
+ var req = this._requests[i];
2468
+ if (req.dead === null) {
2469
+ req.dead = new Date();
2470
+ }
2471
+
2472
+ this._processRequest(i);
2473
+ },
2474
+
2475
+ /** PrivateFunction: _processRequest
2476
+ * _Private_ function to process a request in the queue.
2477
+ *
2478
+ * This function takes requests off the queue and sends them and
2479
+ * restarts dead requests.
2480
+ *
2481
+ * Parameters:
2482
+ * (Integer) i - The index of the request in the queue.
2483
+ */
2484
+ _processRequest: function (i)
2485
+ {
2486
+ var req = this._requests[i];
2487
+ var reqStatus = -1;
2488
+
2489
+ try {
2490
+ if (req.xhr.readyState == 4) {
2491
+ reqStatus = req.xhr.status;
2492
+ }
2493
+ } catch (e) {
2494
+ Strophe.error("caught an error in _requests[" + i +
2495
+ "], reqStatus: " + reqStatus);
2496
+ }
2497
+
2498
+ if (typeof(reqStatus) == "undefined") {
2499
+ reqStatus = -1;
2500
+ }
2501
+
2502
+ // make sure we limit the number of retries
2503
+ if (req.sends > 5) {
2504
+ this._onDisconnectTimeout();
2505
+ return;
2506
+ }
2507
+
2508
+ var time_elapsed = req.age();
2509
+ var primaryTimeout = (!isNaN(time_elapsed) &&
2510
+ time_elapsed > Math.floor(Strophe.TIMEOUT * this.wait));
2511
+ var secondaryTimeout = (req.dead !== null &&
2512
+ req.timeDead() > Math.floor(Strophe.SECONDARY_TIMEOUT * this.wait));
2513
+ var requestCompletedWithServerError = (req.xhr.readyState == 4 &&
2514
+ (reqStatus < 1 ||
2515
+ reqStatus >= 500));
2516
+ if (primaryTimeout || secondaryTimeout ||
2517
+ requestCompletedWithServerError) {
2518
+ if (secondaryTimeout) {
2519
+ Strophe.error("Request " +
2520
+ this._requests[i].id +
2521
+ " timed out (secondary), restarting");
2522
+ }
2523
+ req.abort = true;
2524
+ req.xhr.abort();
2525
+ // setting to null fails on IE6, so set to empty function
2526
+ req.xhr.onreadystatechange = function () {};
2527
+ this._requests[i] = new Strophe.Request(req.xmlData,
2528
+ req.origFunc,
2529
+ req.rid,
2530
+ req.sends);
2531
+ req = this._requests[i];
2532
+ }
2533
+
2534
+ if (req.xhr.readyState === 0) {
2535
+ Strophe.debug("request id " + req.id +
2536
+ "." + req.sends + " posting");
2537
+
2538
+ try {
2539
+ req.xhr.open("POST", this.service, true);
2540
+ } catch (e2) {
2541
+ Strophe.error("XHR open failed.");
2542
+ if (!this.connected) {
2543
+ this._changeConnectStatus(Strophe.Status.CONNFAIL,
2544
+ "bad-service");
2545
+ }
2546
+ this.disconnect();
2547
+ return;
2548
+ }
2549
+
2550
+ // Fires the XHR request -- may be invoked immediately
2551
+ // or on a gradually expanding retry window for reconnects
2552
+ var sendFunc = function () {
2553
+ req.date = new Date();
2554
+ req.xhr.send(req.data);
2555
+ };
2556
+
2557
+ // Implement progressive backoff for reconnects --
2558
+ // First retry (send == 1) should also be instantaneous
2559
+ if (req.sends > 1) {
2560
+ // Using a cube of the retry number creates a nicely
2561
+ // expanding retry window
2562
+ var backoff = Math.min(Math.floor(Strophe.TIMEOUT * this.wait),
2563
+ Math.pow(req.sends, 3)) * 1000;
2564
+ setTimeout(sendFunc, backoff);
2565
+ } else {
2566
+ sendFunc();
2567
+ }
2568
+
2569
+ req.sends++;
2570
+
2571
+ if (this.xmlOutput !== Strophe.Connection.prototype.xmlOutput) {
2572
+ this.xmlOutput(req.xmlData);
2573
+ }
2574
+ if (this.rawOutput !== Strophe.Connection.prototype.rawOutput) {
2575
+ this.rawOutput(req.data);
2576
+ }
2577
+ } else {
2578
+ Strophe.debug("_processRequest: " +
2579
+ (i === 0 ? "first" : "second") +
2580
+ " request has readyState of " +
2581
+ req.xhr.readyState);
2582
+ }
2583
+ },
2584
+
2585
+ /** PrivateFunction: _throttledRequestHandler
2586
+ * _Private_ function to throttle requests to the connection window.
2587
+ *
2588
+ * This function makes sure we don't send requests so fast that the
2589
+ * request ids overflow the connection window in the case that one
2590
+ * request died.
2591
+ */
2592
+ _throttledRequestHandler: function ()
2593
+ {
2594
+ if (!this._requests) {
2595
+ Strophe.debug("_throttledRequestHandler called with " +
2596
+ "undefined requests");
2597
+ } else {
2598
+ Strophe.debug("_throttledRequestHandler called with " +
2599
+ this._requests.length + " requests");
2600
+ }
2601
+
2602
+ if (!this._requests || this._requests.length === 0) {
2603
+ return;
2604
+ }
2605
+
2606
+ if (this._requests.length > 0) {
2607
+ this._processRequest(0);
2608
+ }
2609
+
2610
+ if (this._requests.length > 1 &&
2611
+ Math.abs(this._requests[0].rid -
2612
+ this._requests[1].rid) < this.window) {
2613
+ this._processRequest(1);
2614
+ }
2615
+ },
2616
+
2617
+ /** PrivateFunction: _onRequestStateChange
2618
+ * _Private_ handler for Strophe.Request state changes.
2619
+ *
2620
+ * This function is called when the XMLHttpRequest readyState changes.
2621
+ * It contains a lot of error handling logic for the many ways that
2622
+ * requests can fail, and calls the request callback when requests
2623
+ * succeed.
2624
+ *
2625
+ * Parameters:
2626
+ * (Function) func - The handler for the request.
2627
+ * (Strophe.Request) req - The request that is changing readyState.
2628
+ */
2629
+ _onRequestStateChange: function (func, req)
2630
+ {
2631
+ Strophe.debug("request id " + req.id +
2632
+ "." + req.sends + " state changed to " +
2633
+ req.xhr.readyState);
2634
+
2635
+ if (req.abort) {
2636
+ req.abort = false;
2637
+ return;
2638
+ }
2639
+
2640
+ // request complete
2641
+ var reqStatus;
2642
+ if (req.xhr.readyState == 4) {
2643
+ reqStatus = 0;
2644
+ try {
2645
+ reqStatus = req.xhr.status;
2646
+ } catch (e) {
2647
+ // ignore errors from undefined status attribute. works
2648
+ // around a browser bug
2649
+ }
2650
+
2651
+ if (typeof(reqStatus) == "undefined") {
2652
+ reqStatus = 0;
2653
+ }
2654
+
2655
+ if (this.disconnecting) {
2656
+ if (reqStatus >= 400) {
2657
+ this._hitError(reqStatus);
2658
+ return;
2659
+ }
2660
+ }
2661
+
2662
+ var reqIs0 = (this._requests[0] == req);
2663
+ var reqIs1 = (this._requests[1] == req);
2664
+
2665
+ if ((reqStatus > 0 && reqStatus < 500) || req.sends > 5) {
2666
+ // remove from internal queue
2667
+ this._removeRequest(req);
2668
+ Strophe.debug("request id " +
2669
+ req.id +
2670
+ " should now be removed");
2671
+ }
2672
+
2673
+ // request succeeded
2674
+ if (reqStatus == 200) {
2675
+ // if request 1 finished, or request 0 finished and request
2676
+ // 1 is over Strophe.SECONDARY_TIMEOUT seconds old, we need to
2677
+ // restart the other - both will be in the first spot, as the
2678
+ // completed request has been removed from the queue already
2679
+ if (reqIs1 ||
2680
+ (reqIs0 && this._requests.length > 0 &&
2681
+ this._requests[0].age() > Math.floor(Strophe.SECONDARY_TIMEOUT * this.wait))) {
2682
+ this._restartRequest(0);
2683
+ }
2684
+ // call handler
2685
+ Strophe.debug("request id " +
2686
+ req.id + "." +
2687
+ req.sends + " got 200");
2688
+ func(req);
2689
+ this.errors = 0;
2690
+ } else {
2691
+ Strophe.error("request id " +
2692
+ req.id + "." +
2693
+ req.sends + " error " + reqStatus +
2694
+ " happened");
2695
+ if (reqStatus === 0 ||
2696
+ (reqStatus >= 400 && reqStatus < 600) ||
2697
+ reqStatus >= 12000) {
2698
+ this._hitError(reqStatus);
2699
+ if (reqStatus >= 400 && reqStatus < 500) {
2700
+ this._changeConnectStatus(Strophe.Status.DISCONNECTING,
2701
+ null);
2702
+ this._doDisconnect();
2703
+ }
2704
+ }
2705
+ }
2706
+
2707
+ if (!((reqStatus > 0 && reqStatus < 500) ||
2708
+ req.sends > 5)) {
2709
+ this._throttledRequestHandler();
2710
+ }
2711
+ }
2712
+ },
2713
+
2714
+ /** PrivateFunction: _hitError
2715
+ * _Private_ function to handle the error count.
2716
+ *
2717
+ * Requests are resent automatically until their error count reaches
2718
+ * 5. Each time an error is encountered, this function is called to
2719
+ * increment the count and disconnect if the count is too high.
2720
+ *
2721
+ * Parameters:
2722
+ * (Integer) reqStatus - The request status.
2723
+ */
2724
+ _hitError: function (reqStatus)
2725
+ {
2726
+ this.errors++;
2727
+ Strophe.warn("request errored, status: " + reqStatus +
2728
+ ", number of errors: " + this.errors);
2729
+ if (this.errors > 4) {
2730
+ this._onDisconnectTimeout();
2731
+ }
2732
+ },
2733
+
2734
+ /** PrivateFunction: _doDisconnect
2735
+ * _Private_ function to disconnect.
2736
+ *
2737
+ * This is the last piece of the disconnection logic. This resets the
2738
+ * connection and alerts the user's connection callback.
2739
+ */
2740
+ _doDisconnect: function ()
2741
+ {
2742
+ Strophe.info("_doDisconnect was called");
2743
+ this.authenticated = false;
2744
+ this.disconnecting = false;
2745
+ this.sid = null;
2746
+ this.streamId = null;
2747
+ this.rid = Math.floor(Math.random() * 4294967295);
2748
+
2749
+ // tell the parent we disconnected
2750
+ if (this.connected) {
2751
+ this._changeConnectStatus(Strophe.Status.DISCONNECTED, null);
2752
+ this.connected = false;
2753
+ }
2754
+
2755
+ // delete handlers
2756
+ this.handlers = [];
2757
+ this.timedHandlers = [];
2758
+ this.removeTimeds = [];
2759
+ this.removeHandlers = [];
2760
+ this.addTimeds = [];
2761
+ this.addHandlers = [];
2762
+ },
2763
+
2764
+ /** PrivateFunction: _dataRecv
2765
+ * _Private_ handler to processes incoming data from the the connection.
2766
+ *
2767
+ * Except for _connect_cb handling the initial connection request,
2768
+ * this function handles the incoming data for all requests. This
2769
+ * function also fires stanza handlers that match each incoming
2770
+ * stanza.
2771
+ *
2772
+ * Parameters:
2773
+ * (Strophe.Request) req - The request that has data ready.
2774
+ */
2775
+ _dataRecv: function (req)
2776
+ {
2777
+ try {
2778
+ var elem = req.getResponse();
2779
+ } catch (e) {
2780
+ if (e != "parsererror") { throw e; }
2781
+ this.disconnect("strophe-parsererror");
2782
+ }
2783
+ if (elem === null) { return; }
2784
+
2785
+ if (this.xmlInput !== Strophe.Connection.prototype.xmlInput) {
2786
+ this.xmlInput(elem);
2787
+ }
2788
+ if (this.rawInput !== Strophe.Connection.prototype.rawInput) {
2789
+ this.rawInput(Strophe.serialize(elem));
2790
+ }
2791
+
2792
+ // remove handlers scheduled for deletion
2793
+ var i, hand;
2794
+ while (this.removeHandlers.length > 0) {
2795
+ hand = this.removeHandlers.pop();
2796
+ i = this.handlers.indexOf(hand);
2797
+ if (i >= 0) {
2798
+ this.handlers.splice(i, 1);
2799
+ }
2800
+ }
2801
+
2802
+ // add handlers scheduled for addition
2803
+ while (this.addHandlers.length > 0) {
2804
+ this.handlers.push(this.addHandlers.pop());
2805
+ }
2806
+
2807
+ // handle graceful disconnect
2808
+ if (this.disconnecting && this._requests.length === 0) {
2809
+ this.deleteTimedHandler(this._disconnectTimeout);
2810
+ this._disconnectTimeout = null;
2811
+ this._doDisconnect();
2812
+ return;
2813
+ }
2814
+
2815
+ var typ = elem.getAttribute("type");
2816
+ var cond, conflict;
2817
+ if (typ !== null && typ == "terminate") {
2818
+ // Don't process stanzas that come in after disconnect
2819
+ if (this.disconnecting) {
2820
+ return;
2821
+ }
2822
+
2823
+ // an error occurred
2824
+ cond = elem.getAttribute("condition");
2825
+ conflict = elem.getElementsByTagName("conflict");
2826
+ if (cond !== null) {
2827
+ if (cond == "remote-stream-error" && conflict.length > 0) {
2828
+ cond = "conflict";
2829
+ }
2830
+ this._changeConnectStatus(Strophe.Status.CONNFAIL, cond);
2831
+ } else {
2832
+ this._changeConnectStatus(Strophe.Status.CONNFAIL, "unknown");
2833
+ }
2834
+ this.disconnect();
2835
+ return;
2836
+ }
2837
+
2838
+ // send each incoming stanza through the handler chain
2839
+ var that = this;
2840
+ Strophe.forEachChild(elem, null, function (child) {
2841
+ var i, newList;
2842
+ // process handlers
2843
+ newList = that.handlers;
2844
+ that.handlers = [];
2845
+ for (i = 0; i < newList.length; i++) {
2846
+ var hand = newList[i];
2847
+ // encapsulate 'handler.run' not to lose the whole handler list if
2848
+ // one of the handlers throws an exception
2849
+ try {
2850
+ if (hand.isMatch(child) &&
2851
+ (that.authenticated || !hand.user)) {
2852
+ if (hand.run(child)) {
2853
+ that.handlers.push(hand);
2854
+ }
2855
+ } else {
2856
+ that.handlers.push(hand);
2857
+ }
2858
+ } catch(e) {
2859
+ //if the handler throws an exception, we consider it as false
2860
+ }
2861
+ }
2862
+ });
2863
+ },
2864
+
2865
+ /** PrivateFunction: _sendTerminate
2866
+ * _Private_ function to send initial disconnect sequence.
2867
+ *
2868
+ * This is the first step in a graceful disconnect. It sends
2869
+ * the BOSH server a terminate body and includes an unavailable
2870
+ * presence if authentication has completed.
2871
+ */
2872
+ _sendTerminate: function ()
2873
+ {
2874
+ Strophe.info("_sendTerminate was called");
2875
+ var body = this._buildBody().attrs({type: "terminate"});
2876
+
2877
+ if (this.authenticated) {
2878
+ body.c('presence', {
2879
+ xmlns: Strophe.NS.CLIENT,
2880
+ type: 'unavailable'
2881
+ });
2882
+ }
2883
+
2884
+ this.disconnecting = true;
2885
+
2886
+ var req = new Strophe.Request(body.tree(),
2887
+ this._onRequestStateChange.bind(
2888
+ this, this._dataRecv.bind(this)),
2889
+ body.tree().getAttribute("rid"));
2890
+
2891
+ this._requests.push(req);
2892
+ this._throttledRequestHandler();
2893
+ },
2894
+
2895
+ /** PrivateFunction: _connect_cb
2896
+ * _Private_ handler for initial connection request.
2897
+ *
2898
+ * This handler is used to process the initial connection request
2899
+ * response from the BOSH server. It is used to set up authentication
2900
+ * handlers and start the authentication process.
2901
+ *
2902
+ * SASL authentication will be attempted if available, otherwise
2903
+ * the code will fall back to legacy authentication.
2904
+ *
2905
+ * Parameters:
2906
+ * (Strophe.Request) req - The current request.
2907
+ */
2908
+ _connect_cb: function (req)
2909
+ {
2910
+ Strophe.info("_connect_cb was called");
2911
+
2912
+ this.connected = true;
2913
+ var bodyWrap = req.getResponse();
2914
+ if (!bodyWrap) { return; }
2915
+
2916
+ if (this.xmlInput !== Strophe.Connection.prototype.xmlInput) {
2917
+ this.xmlInput(bodyWrap);
2918
+ }
2919
+ if (this.rawInput !== Strophe.Connection.prototype.rawInput) {
2920
+ this.rawInput(Strophe.serialize(bodyWrap));
2921
+ }
2922
+
2923
+ var typ = bodyWrap.getAttribute("type");
2924
+ var cond, conflict;
2925
+ if (typ !== null && typ == "terminate") {
2926
+ // an error occurred
2927
+ cond = bodyWrap.getAttribute("condition");
2928
+ conflict = bodyWrap.getElementsByTagName("conflict");
2929
+ if (cond !== null) {
2930
+ if (cond == "remote-stream-error" && conflict.length > 0) {
2931
+ cond = "conflict";
2932
+ }
2933
+ this._changeConnectStatus(Strophe.Status.CONNFAIL, cond);
2934
+ } else {
2935
+ this._changeConnectStatus(Strophe.Status.CONNFAIL, "unknown");
2936
+ }
2937
+ return;
2938
+ }
2939
+
2940
+ // check to make sure we don't overwrite these if _connect_cb is
2941
+ // called multiple times in the case of missing stream:features
2942
+ if (!this.sid) {
2943
+ this.sid = bodyWrap.getAttribute("sid");
2944
+ }
2945
+ if (!this.stream_id) {
2946
+ this.stream_id = bodyWrap.getAttribute("authid");
2947
+ }
2948
+ var wind = bodyWrap.getAttribute('requests');
2949
+ if (wind) { this.window = parseInt(wind, 10); }
2950
+ var hold = bodyWrap.getAttribute('hold');
2951
+ if (hold) { this.hold = parseInt(hold, 10); }
2952
+ var wait = bodyWrap.getAttribute('wait');
2953
+ if (wait) { this.wait = parseInt(wait, 10); }
2954
+
2955
+
2956
+ var do_sasl_plain = false;
2957
+ var do_sasl_digest_md5 = false;
2958
+ var do_sasl_anonymous = false;
2959
+
2960
+ var mechanisms = bodyWrap.getElementsByTagName("mechanism");
2961
+ var i, mech, auth_str, hashed_auth_str;
2962
+ if (mechanisms.length > 0) {
2963
+ for (i = 0; i < mechanisms.length; i++) {
2964
+ mech = Strophe.getText(mechanisms[i]);
2965
+ if (mech == 'DIGEST-MD5') {
2966
+ do_sasl_digest_md5 = true;
2967
+ } else if (mech == 'PLAIN') {
2968
+ do_sasl_plain = true;
2969
+ } else if (mech == 'ANONYMOUS') {
2970
+ do_sasl_anonymous = true;
2971
+ }
2972
+ }
2973
+ } else {
2974
+ // we didn't get stream:features yet, so we need wait for it
2975
+ // by sending a blank poll request
2976
+ var body = this._buildBody();
2977
+ this._requests.push(
2978
+ new Strophe.Request(body.tree(),
2979
+ this._onRequestStateChange.bind(
2980
+ this, this._connect_cb.bind(this)),
2981
+ body.tree().getAttribute("rid")));
2982
+ this._throttledRequestHandler();
2983
+ return;
2984
+ }
2985
+
2986
+ if (Strophe.getNodeFromJid(this.jid) === null &&
2987
+ do_sasl_anonymous) {
2988
+ this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null);
2989
+ this._sasl_success_handler = this._addSysHandler(
2990
+ this._sasl_success_cb.bind(this), null,
2991
+ "success", null, null);
2992
+ this._sasl_failure_handler = this._addSysHandler(
2993
+ this._sasl_failure_cb.bind(this), null,
2994
+ "failure", null, null);
2995
+
2996
+ this.send($build("auth", {
2997
+ xmlns: Strophe.NS.SASL,
2998
+ mechanism: "ANONYMOUS"
2999
+ }).tree());
3000
+ } else if (Strophe.getNodeFromJid(this.jid) === null) {
3001
+ // we don't have a node, which is required for non-anonymous
3002
+ // client connections
3003
+ this._changeConnectStatus(Strophe.Status.CONNFAIL,
3004
+ 'x-strophe-bad-non-anon-jid');
3005
+ this.disconnect();
3006
+ } else if (do_sasl_digest_md5) {
3007
+ this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null);
3008
+ this._sasl_challenge_handler = this._addSysHandler(
3009
+ this._sasl_challenge1_cb.bind(this), null,
3010
+ "challenge", null, null);
3011
+ this._sasl_failure_handler = this._addSysHandler(
3012
+ this._sasl_failure_cb.bind(this), null,
3013
+ "failure", null, null);
3014
+
3015
+ this.send($build("auth", {
3016
+ xmlns: Strophe.NS.SASL,
3017
+ mechanism: "DIGEST-MD5"
3018
+ }).tree());
3019
+ } else if (do_sasl_plain) {
3020
+ // Build the plain auth string (barejid null
3021
+ // username null password) and base 64 encoded.
3022
+ auth_str = Strophe.getBareJidFromJid(this.jid);
3023
+ auth_str = auth_str + "\u0000";
3024
+ auth_str = auth_str + Strophe.getNodeFromJid(this.jid);
3025
+ auth_str = auth_str + "\u0000";
3026
+ auth_str = auth_str + this.pass;
3027
+
3028
+ this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null);
3029
+ this._sasl_success_handler = this._addSysHandler(
3030
+ this._sasl_success_cb.bind(this), null,
3031
+ "success", null, null);
3032
+ this._sasl_failure_handler = this._addSysHandler(
3033
+ this._sasl_failure_cb.bind(this), null,
3034
+ "failure", null, null);
3035
+
3036
+ hashed_auth_str = Base64.encode(auth_str);
3037
+ this.send($build("auth", {
3038
+ xmlns: Strophe.NS.SASL,
3039
+ mechanism: "PLAIN"
3040
+ }).t(hashed_auth_str).tree());
3041
+ } else {
3042
+ this._changeConnectStatus(Strophe.Status.AUTHENTICATING, null);
3043
+ this._addSysHandler(this._auth1_cb.bind(this), null, null,
3044
+ null, "_auth_1");
3045
+
3046
+ this.send($iq({
3047
+ type: "get",
3048
+ to: this.domain,
3049
+ id: "_auth_1"
3050
+ }).c("query", {
3051
+ xmlns: Strophe.NS.AUTH
3052
+ }).c("username", {}).t(Strophe.getNodeFromJid(this.jid)).tree());
3053
+ }
3054
+ },
3055
+
3056
+ /** PrivateFunction: _sasl_challenge1_cb
3057
+ * _Private_ handler for DIGEST-MD5 SASL authentication.
3058
+ *
3059
+ * Parameters:
3060
+ * (XMLElement) elem - The challenge stanza.
3061
+ *
3062
+ * Returns:
3063
+ * false to remove the handler.
3064
+ */
3065
+ _sasl_challenge1_cb: function (elem)
3066
+ {
3067
+ var attribMatch = /([a-z]+)=("[^"]+"|[^,"]+)(?:,|$)/;
3068
+
3069
+ var challenge = Base64.decode(Strophe.getText(elem));
3070
+ var cnonce = MD5.hexdigest("" + (Math.random() * 1234567890));
3071
+ var realm = "";
3072
+ var host = null;
3073
+ var nonce = "";
3074
+ var qop = "";
3075
+ var matches;
3076
+
3077
+ // remove unneeded handlers
3078
+ this.deleteHandler(this._sasl_failure_handler);
3079
+
3080
+ while (challenge.match(attribMatch)) {
3081
+ matches = challenge.match(attribMatch);
3082
+ challenge = challenge.replace(matches[0], "");
3083
+ matches[2] = matches[2].replace(/^"(.+)"$/, "$1");
3084
+ switch (matches[1]) {
3085
+ case "realm":
3086
+ realm = matches[2];
3087
+ break;
3088
+ case "nonce":
3089
+ nonce = matches[2];
3090
+ break;
3091
+ case "qop":
3092
+ qop = matches[2];
3093
+ break;
3094
+ case "host":
3095
+ host = matches[2];
3096
+ break;
3097
+ }
3098
+ }
3099
+
3100
+ var digest_uri = "xmpp/" + this.domain;
3101
+ if (host !== null) {
3102
+ digest_uri = digest_uri + "/" + host;
3103
+ }
3104
+
3105
+ var A1 = MD5.hash(Strophe.getNodeFromJid(this.jid) +
3106
+ ":" + realm + ":" + this.pass) +
3107
+ ":" + nonce + ":" + cnonce;
3108
+ var A2 = 'AUTHENTICATE:' + digest_uri;
3109
+
3110
+ var responseText = "";
3111
+ responseText += 'username=' +
3112
+ this._quote(Strophe.getNodeFromJid(this.jid)) + ',';
3113
+ responseText += 'realm=' + this._quote(realm) + ',';
3114
+ responseText += 'nonce=' + this._quote(nonce) + ',';
3115
+ responseText += 'cnonce=' + this._quote(cnonce) + ',';
3116
+ responseText += 'nc="00000001",';
3117
+ responseText += 'qop="auth",';
3118
+ responseText += 'digest-uri=' + this._quote(digest_uri) + ',';
3119
+ responseText += 'response=' + this._quote(
3120
+ MD5.hexdigest(MD5.hexdigest(A1) + ":" +
3121
+ nonce + ":00000001:" +
3122
+ cnonce + ":auth:" +
3123
+ MD5.hexdigest(A2))) + ',';
3124
+ responseText += 'charset="utf-8"';
3125
+
3126
+ this._sasl_challenge_handler = this._addSysHandler(
3127
+ this._sasl_challenge2_cb.bind(this), null,
3128
+ "challenge", null, null);
3129
+ this._sasl_success_handler = this._addSysHandler(
3130
+ this._sasl_success_cb.bind(this), null,
3131
+ "success", null, null);
3132
+ this._sasl_failure_handler = this._addSysHandler(
3133
+ this._sasl_failure_cb.bind(this), null,
3134
+ "failure", null, null);
3135
+
3136
+ this.send($build('response', {
3137
+ xmlns: Strophe.NS.SASL
3138
+ }).t(Base64.encode(responseText)).tree());
3139
+
3140
+ return false;
3141
+ },
3142
+
3143
+ /** PrivateFunction: _quote
3144
+ * _Private_ utility function to backslash escape and quote strings.
3145
+ *
3146
+ * Parameters:
3147
+ * (String) str - The string to be quoted.
3148
+ *
3149
+ * Returns:
3150
+ * quoted string
3151
+ */
3152
+ _quote: function (str)
3153
+ {
3154
+ return '"' + str.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
3155
+ //" end string workaround for emacs
3156
+ },
3157
+
3158
+
3159
+ /** PrivateFunction: _sasl_challenge2_cb
3160
+ * _Private_ handler for second step of DIGEST-MD5 SASL authentication.
3161
+ *
3162
+ * Parameters:
3163
+ * (XMLElement) elem - The challenge stanza.
3164
+ *
3165
+ * Returns:
3166
+ * false to remove the handler.
3167
+ */
3168
+ _sasl_challenge2_cb: function (elem)
3169
+ {
3170
+ // remove unneeded handlers
3171
+ this.deleteHandler(this._sasl_success_handler);
3172
+ this.deleteHandler(this._sasl_failure_handler);
3173
+
3174
+ this._sasl_success_handler = this._addSysHandler(
3175
+ this._sasl_success_cb.bind(this), null,
3176
+ "success", null, null);
3177
+ this._sasl_failure_handler = this._addSysHandler(
3178
+ this._sasl_failure_cb.bind(this), null,
3179
+ "failure", null, null);
3180
+ this.send($build('response', {xmlns: Strophe.NS.SASL}).tree());
3181
+ return false;
3182
+ },
3183
+
3184
+ /** PrivateFunction: _auth1_cb
3185
+ * _Private_ handler for legacy authentication.
3186
+ *
3187
+ * This handler is called in response to the initial <iq type='get'/>
3188
+ * for legacy authentication. It builds an authentication <iq/> and
3189
+ * sends it, creating a handler (calling back to _auth2_cb()) to
3190
+ * handle the result
3191
+ *
3192
+ * Parameters:
3193
+ * (XMLElement) elem - The stanza that triggered the callback.
3194
+ *
3195
+ * Returns:
3196
+ * false to remove the handler.
3197
+ */
3198
+ _auth1_cb: function (elem)
3199
+ {
3200
+ // build plaintext auth iq
3201
+ var iq = $iq({type: "set", id: "_auth_2"})
3202
+ .c('query', {xmlns: Strophe.NS.AUTH})
3203
+ .c('username', {}).t(Strophe.getNodeFromJid(this.jid))
3204
+ .up()
3205
+ .c('password').t(this.pass);
3206
+
3207
+ if (!Strophe.getResourceFromJid(this.jid)) {
3208
+ // since the user has not supplied a resource, we pick
3209
+ // a default one here. unlike other auth methods, the server
3210
+ // cannot do this for us.
3211
+ this.jid = Strophe.getBareJidFromJid(this.jid) + '/strophe';
3212
+ }
3213
+ iq.up().c('resource', {}).t(Strophe.getResourceFromJid(this.jid));
3214
+
3215
+ this._addSysHandler(this._auth2_cb.bind(this), null,
3216
+ null, null, "_auth_2");
3217
+
3218
+ this.send(iq.tree());
3219
+
3220
+ return false;
3221
+ },
3222
+
3223
+ /** PrivateFunction: _sasl_success_cb
3224
+ * _Private_ handler for succesful SASL authentication.
3225
+ *
3226
+ * Parameters:
3227
+ * (XMLElement) elem - The matching stanza.
3228
+ *
3229
+ * Returns:
3230
+ * false to remove the handler.
3231
+ */
3232
+ _sasl_success_cb: function (elem)
3233
+ {
3234
+ Strophe.info("SASL authentication succeeded.");
3235
+
3236
+ // remove old handlers
3237
+ this.deleteHandler(this._sasl_failure_handler);
3238
+ this._sasl_failure_handler = null;
3239
+ if (this._sasl_challenge_handler) {
3240
+ this.deleteHandler(this._sasl_challenge_handler);
3241
+ this._sasl_challenge_handler = null;
3242
+ }
3243
+
3244
+ this._addSysHandler(this._sasl_auth1_cb.bind(this), null,
3245
+ "stream:features", null, null);
3246
+
3247
+ // we must send an xmpp:restart now
3248
+ this._sendRestart();
3249
+
3250
+ return false;
3251
+ },
3252
+
3253
+ /** PrivateFunction: _sasl_auth1_cb
3254
+ * _Private_ handler to start stream binding.
3255
+ *
3256
+ * Parameters:
3257
+ * (XMLElement) elem - The matching stanza.
3258
+ *
3259
+ * Returns:
3260
+ * false to remove the handler.
3261
+ */
3262
+ _sasl_auth1_cb: function (elem)
3263
+ {
3264
+ // save stream:features for future usage
3265
+ this.features = elem;
3266
+
3267
+ var i, child;
3268
+
3269
+ for (i = 0; i < elem.childNodes.length; i++) {
3270
+ child = elem.childNodes[i];
3271
+ if (child.nodeName == 'bind') {
3272
+ this.do_bind = true;
3273
+ }
3274
+
3275
+ if (child.nodeName == 'session') {
3276
+ this.do_session = true;
3277
+ }
3278
+ }
3279
+
3280
+ if (!this.do_bind) {
3281
+ this._changeConnectStatus(Strophe.Status.AUTHFAIL, null);
3282
+ return false;
3283
+ } else {
3284
+ this._addSysHandler(this._sasl_bind_cb.bind(this), null, null,
3285
+ null, "_bind_auth_2");
3286
+
3287
+ var resource = Strophe.getResourceFromJid(this.jid);
3288
+ if (resource) {
3289
+ this.send($iq({type: "set", id: "_bind_auth_2"})
3290
+ .c('bind', {xmlns: Strophe.NS.BIND})
3291
+ .c('resource', {}).t(resource).tree());
3292
+ } else {
3293
+ this.send($iq({type: "set", id: "_bind_auth_2"})
3294
+ .c('bind', {xmlns: Strophe.NS.BIND})
3295
+ .tree());
3296
+ }
3297
+ }
3298
+
3299
+ return false;
3300
+ },
3301
+
3302
+ /** PrivateFunction: _sasl_bind_cb
3303
+ * _Private_ handler for binding result and session start.
3304
+ *
3305
+ * Parameters:
3306
+ * (XMLElement) elem - The matching stanza.
3307
+ *
3308
+ * Returns:
3309
+ * false to remove the handler.
3310
+ */
3311
+ _sasl_bind_cb: function (elem)
3312
+ {
3313
+ if (elem.getAttribute("type") == "error") {
3314
+ Strophe.info("SASL binding failed.");
3315
+ this._changeConnectStatus(Strophe.Status.AUTHFAIL, null);
3316
+ return false;
3317
+ }
3318
+
3319
+ // TODO - need to grab errors
3320
+ var bind = elem.getElementsByTagName("bind");
3321
+ var jidNode;
3322
+ if (bind.length > 0) {
3323
+ // Grab jid
3324
+ jidNode = bind[0].getElementsByTagName("jid");
3325
+ if (jidNode.length > 0) {
3326
+ this.jid = Strophe.getText(jidNode[0]);
3327
+
3328
+ if (this.do_session) {
3329
+ this._addSysHandler(this._sasl_session_cb.bind(this),
3330
+ null, null, null, "_session_auth_2");
3331
+
3332
+ this.send($iq({type: "set", id: "_session_auth_2"})
3333
+ .c('session', {xmlns: Strophe.NS.SESSION})
3334
+ .tree());
3335
+ } else {
3336
+ this.authenticated = true;
3337
+ this._changeConnectStatus(Strophe.Status.CONNECTED, null);
3338
+ }
3339
+ }
3340
+ } else {
3341
+ Strophe.info("SASL binding failed.");
3342
+ this._changeConnectStatus(Strophe.Status.AUTHFAIL, null);
3343
+ return false;
3344
+ }
3345
+ },
3346
+
3347
+ /** PrivateFunction: _sasl_session_cb
3348
+ * _Private_ handler to finish successful SASL connection.
3349
+ *
3350
+ * This sets Connection.authenticated to true on success, which
3351
+ * starts the processing of user handlers.
3352
+ *
3353
+ * Parameters:
3354
+ * (XMLElement) elem - The matching stanza.
3355
+ *
3356
+ * Returns:
3357
+ * false to remove the handler.
3358
+ */
3359
+ _sasl_session_cb: function (elem)
3360
+ {
3361
+ if (elem.getAttribute("type") == "result") {
3362
+ this.authenticated = true;
3363
+ this._changeConnectStatus(Strophe.Status.CONNECTED, null);
3364
+ } else if (elem.getAttribute("type") == "error") {
3365
+ Strophe.info("Session creation failed.");
3366
+ this._changeConnectStatus(Strophe.Status.AUTHFAIL, null);
3367
+ return false;
3368
+ }
3369
+
3370
+ return false;
3371
+ },
3372
+
3373
+ /** PrivateFunction: _sasl_failure_cb
3374
+ * _Private_ handler for SASL authentication failure.
3375
+ *
3376
+ * Parameters:
3377
+ * (XMLElement) elem - The matching stanza.
3378
+ *
3379
+ * Returns:
3380
+ * false to remove the handler.
3381
+ */
3382
+ _sasl_failure_cb: function (elem)
3383
+ {
3384
+ // delete unneeded handlers
3385
+ if (this._sasl_success_handler) {
3386
+ this.deleteHandler(this._sasl_success_handler);
3387
+ this._sasl_success_handler = null;
3388
+ }
3389
+ if (this._sasl_challenge_handler) {
3390
+ this.deleteHandler(this._sasl_challenge_handler);
3391
+ this._sasl_challenge_handler = null;
3392
+ }
3393
+
3394
+ this._changeConnectStatus(Strophe.Status.AUTHFAIL, null);
3395
+ return false;
3396
+ },
3397
+
3398
+ /** PrivateFunction: _auth2_cb
3399
+ * _Private_ handler to finish legacy authentication.
3400
+ *
3401
+ * This handler is called when the result from the jabber:iq:auth
3402
+ * <iq/> stanza is returned.
3403
+ *
3404
+ * Parameters:
3405
+ * (XMLElement) elem - The stanza that triggered the callback.
3406
+ *
3407
+ * Returns:
3408
+ * false to remove the handler.
3409
+ */
3410
+ _auth2_cb: function (elem)
3411
+ {
3412
+ if (elem.getAttribute("type") == "result") {
3413
+ this.authenticated = true;
3414
+ this._changeConnectStatus(Strophe.Status.CONNECTED, null);
3415
+ } else if (elem.getAttribute("type") == "error") {
3416
+ this._changeConnectStatus(Strophe.Status.AUTHFAIL, null);
3417
+ this.disconnect();
3418
+ }
3419
+
3420
+ return false;
3421
+ },
3422
+
3423
+ /** PrivateFunction: _addSysTimedHandler
3424
+ * _Private_ function to add a system level timed handler.
3425
+ *
3426
+ * This function is used to add a Strophe.TimedHandler for the
3427
+ * library code. System timed handlers are allowed to run before
3428
+ * authentication is complete.
3429
+ *
3430
+ * Parameters:
3431
+ * (Integer) period - The period of the handler.
3432
+ * (Function) handler - The callback function.
3433
+ */
3434
+ _addSysTimedHandler: function (period, handler)
3435
+ {
3436
+ var thand = new Strophe.TimedHandler(period, handler);
3437
+ thand.user = false;
3438
+ this.addTimeds.push(thand);
3439
+ return thand;
3440
+ },
3441
+
3442
+ /** PrivateFunction: _addSysHandler
3443
+ * _Private_ function to add a system level stanza handler.
3444
+ *
3445
+ * This function is used to add a Strophe.Handler for the
3446
+ * library code. System stanza handlers are allowed to run before
3447
+ * authentication is complete.
3448
+ *
3449
+ * Parameters:
3450
+ * (Function) handler - The callback function.
3451
+ * (String) ns - The namespace to match.
3452
+ * (String) name - The stanza name to match.
3453
+ * (String) type - The stanza type attribute to match.
3454
+ * (String) id - The stanza id attribute to match.
3455
+ */
3456
+ _addSysHandler: function (handler, ns, name, type, id)
3457
+ {
3458
+ var hand = new Strophe.Handler(handler, ns, name, type, id);
3459
+ hand.user = false;
3460
+ this.addHandlers.push(hand);
3461
+ return hand;
3462
+ },
3463
+
3464
+ /** PrivateFunction: _onDisconnectTimeout
3465
+ * _Private_ timeout handler for handling non-graceful disconnection.
3466
+ *
3467
+ * If the graceful disconnect process does not complete within the
3468
+ * time allotted, this handler finishes the disconnect anyway.
3469
+ *
3470
+ * Returns:
3471
+ * false to remove the handler.
3472
+ */
3473
+ _onDisconnectTimeout: function ()
3474
+ {
3475
+ Strophe.info("_onDisconnectTimeout was called");
3476
+
3477
+ // cancel all remaining requests and clear the queue
3478
+ var req;
3479
+ while (this._requests.length > 0) {
3480
+ req = this._requests.pop();
3481
+ req.abort = true;
3482
+ req.xhr.abort();
3483
+ // jslint complains, but this is fine. setting to empty func
3484
+ // is necessary for IE6
3485
+ req.xhr.onreadystatechange = function () {};
3486
+ }
3487
+
3488
+ // actually disconnect
3489
+ this._doDisconnect();
3490
+
3491
+ return false;
3492
+ },
3493
+
3494
+ /** PrivateFunction: _onIdle
3495
+ * _Private_ handler to process events during idle cycle.
3496
+ *
3497
+ * This handler is called every 100ms to fire timed handlers that
3498
+ * are ready and keep poll requests going.
3499
+ */
3500
+ _onIdle: function ()
3501
+ {
3502
+ var i, thand, since, newList;
3503
+
3504
+ // add timed handlers scheduled for addition
3505
+ // NOTE: we add before remove in the case a timed handler is
3506
+ // added and then deleted before the next _onIdle() call.
3507
+ while (this.addTimeds.length > 0) {
3508
+ this.timedHandlers.push(this.addTimeds.pop());
3509
+ }
3510
+
3511
+ // remove timed handlers that have been scheduled for deletion
3512
+ while (this.removeTimeds.length > 0) {
3513
+ thand = this.removeTimeds.pop();
3514
+ i = this.timedHandlers.indexOf(thand);
3515
+ if (i >= 0) {
3516
+ this.timedHandlers.splice(i, 1);
3517
+ }
3518
+ }
3519
+
3520
+ // call ready timed handlers
3521
+ var now = new Date().getTime();
3522
+ newList = [];
3523
+ for (i = 0; i < this.timedHandlers.length; i++) {
3524
+ thand = this.timedHandlers[i];
3525
+ if (this.authenticated || !thand.user) {
3526
+ since = thand.lastCalled + thand.period;
3527
+ if (since - now <= 0) {
3528
+ if (thand.run()) {
3529
+ newList.push(thand);
3530
+ }
3531
+ } else {
3532
+ newList.push(thand);
3533
+ }
3534
+ }
3535
+ }
3536
+ this.timedHandlers = newList;
3537
+
3538
+ var body, time_elapsed;
3539
+
3540
+ // if no requests are in progress, poll
3541
+ if (this.authenticated && this._requests.length === 0 &&
3542
+ this._data.length === 0 && !this.disconnecting) {
3543
+ Strophe.info("no requests during idle cycle, sending " +
3544
+ "blank request");
3545
+ this._data.push(null);
3546
+ }
3547
+
3548
+ if (this._requests.length < 2 && this._data.length > 0 &&
3549
+ !this.paused) {
3550
+ body = this._buildBody();
3551
+ for (i = 0; i < this._data.length; i++) {
3552
+ if (this._data[i] !== null) {
3553
+ if (this._data[i] === "restart") {
3554
+ body.attrs({
3555
+ to: this.domain,
3556
+ "xml:lang": "en",
3557
+ "xmpp:restart": "true",
3558
+ "xmlns:xmpp": Strophe.NS.BOSH
3559
+ });
3560
+ } else {
3561
+ body.cnode(this._data[i]).up();
3562
+ }
3563
+ }
3564
+ }
3565
+ delete this._data;
3566
+ this._data = [];
3567
+ this._requests.push(
3568
+ new Strophe.Request(body.tree(),
3569
+ this._onRequestStateChange.bind(
3570
+ this, this._dataRecv.bind(this)),
3571
+ body.tree().getAttribute("rid")));
3572
+ this._processRequest(this._requests.length - 1);
3573
+ }
3574
+
3575
+ if (this._requests.length > 0) {
3576
+ time_elapsed = this._requests[0].age();
3577
+ if (this._requests[0].dead !== null) {
3578
+ if (this._requests[0].timeDead() >
3579
+ Math.floor(Strophe.SECONDARY_TIMEOUT * this.wait)) {
3580
+ this._throttledRequestHandler();
3581
+ }
3582
+ }
3583
+
3584
+ if (time_elapsed > Math.floor(Strophe.TIMEOUT * this.wait)) {
3585
+ Strophe.warn("Request " +
3586
+ this._requests[0].id +
3587
+ " timed out, over " + Math.floor(Strophe.TIMEOUT * this.wait) +
3588
+ " seconds since last activity");
3589
+ this._throttledRequestHandler();
3590
+ }
3591
+ }
3592
+
3593
+ clearTimeout(this._idleTimeout);
3594
+
3595
+ // reactivate the timer only if connected
3596
+ if (this.connected) {
3597
+ this._idleTimeout = setTimeout(this._onIdle.bind(this), 100);
3598
+ }
3599
+ }
3600
+ };
3601
+
3602
+ if (callback) {
3603
+ callback(Strophe, $build, $msg, $iq, $pres);
3604
+ }
3605
+
3606
+ })(function () {
3607
+ window.Strophe = arguments[0];
3608
+ window.$build = arguments[1];
3609
+ window.$msg = arguments[2];
3610
+ window.$iq = arguments[3];
3611
+ window.$pres = arguments[4];
3612
+ });