-module(ephraim_event). -compile([debug_info, export_all]). -include_lib("exmpp/include/exmpp.hrl"). -spec init() -> ok. init() -> loop(). -spec handleEvent(binary(), #xmlel{}) -> ok. handleEvent(From, Item) -> % HasAvatarData = exmpp_xml:has_element(Item, 'urn:xmpp:avatar:data', data), % HasAvatarMetaData = exmpp_xml:has_element(Item, 'urn:xmpp:avatar:metadata', metadata), if %HasAvatarData -> % Element = exmpp_xml:get_element(Item, 'urn:xmpp:avatar:data', data), % Data = base64:decode(exmpp_xml:get_cdata_from_list(Element#xmlel.children)), % ephraim ! {roster, {avatar, From, Data}}, % ok; %HasAvatarMetaData -> % ok; true -> io:format("Received unhandled event from ~p:~n~p~n", [From, Item]) end. -spec handleEvents(binary(), [#xmlel{}]) -> ok. handleEvents(_, []) -> ok; handleEvents(From, [Item|Rest]) -> handleEvent(From, Item), handleEvents(From, Rest). -spec loop() -> ok. loop() -> receive stop -> ok; {receive_event, From, Packet} -> Event = exmpp_xml:get_element(Packet, 'http://jabber.org/protocol/pubsub#event', event), Items = exmpp_xml:get_element(Event, 'http://jabber.org/protocol/pubsub#event', items), handleEvents(From, Items#xmlel.children), loop(); Msg -> io:format("ephraim_event: ~p~n", [Msg]), loop() end.