PageRenderTime 18ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/ucengine/src/controllers/async/uce_async_lp.erl

http://github.com/AF83/ucengine
Erlang | 50 lines | 30 code | 3 blank | 17 comment | 0 complexity | 1fcf73a371a3ea8da66ba57a59a9924d MD5 | raw file
  1. %%
  2. %% U.C.Engine - Unified Collaboration Engine
  3. %% Copyright (C) 2011 af83
  4. %%
  5. %% This program is free software: you can redistribute it and/or modify
  6. %% it under the terms of the GNU Affero General Public License as published by
  7. %% the Free Software Foundation, either version 3 of the License, or
  8. %% (at your option) any later version.
  9. %%
  10. %% This program is distributed in the hope that it will be useful,
  11. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. %% GNU Affero General Public License for more details.
  14. %%
  15. %% You should have received a copy of the GNU Affero General Public License
  16. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. %%
  18. -module(uce_async_lp).
  19. -export([wait/8]).
  20. -include("uce.hrl").
  21. wait(Domain, Uid, Location, Search, From, Types, Parent, []) ->
  22. Self = self(),
  23. spawn(fun() ->
  24. uce_meeting:subscribe(self(), Domain, Uid, Location, From, Types, Parent),
  25. {ok, Event} = uce_async:listen(Domain,
  26. Location,
  27. Search,
  28. From,
  29. Types,
  30. Parent,
  31. (config:get(connection_timeout) * 1000)),
  32. Event2 = case Event of
  33. [] ->
  34. [];
  35. Event ->
  36. [Event]
  37. end,
  38. JSONEvents = mochijson:encode({struct,
  39. [{result,
  40. json_helpers:to_json(Domain, Event2)}]}),
  41. yaws_api:stream_chunk_deliver(Self, list_to_binary(JSONEvents)),
  42. yaws_api:stream_chunk_end(Self),
  43. uce_meeting:unsubscribe(self())
  44. end),
  45. {streamcontent_with_timeout, "application/json", <<>>, infinity};
  46. wait(Domain, _Uid, _Location, _Search, _From, _Types, _Parent, PreviousEvents) ->
  47. json_helpers:json(Domain, PreviousEvents).