-module(ephraim_conn). -compile([debug_info, export_all]). -include_lib("exmpp/include/exmpp_client.hrl"). -record(conn_state, { session :: any() }). -spec init() -> ok. init() -> application:start(exmpp), Session = exmpp_session:start(), JID = exmpp_jid:make("ephraim-test", "jabber.ccc.de", "Bar"), exmpp_session:auth_basic_digest(Session, JID, "foobarbla"), io:format("Connecting...~n"), exmpp_session:connect_TCP(Session, "jabber.ccc.de", 5222), io:format("Connected.~n"), session(#conn_state{session=Session}). -spec session(#conn_state{}) -> ok. session(State) -> io:format("Logging in...~n"), exmpp_session:login(State#conn_state.session), io:format("Setting presence...~n"), exmpp_session:send_packet(State#conn_state.session, exmpp_presence:set_status(exmpp_presence:available(), "Foo/Test\\Bar")), io:format("Getting roster...~n"), exmpp_session:send_packet(State#conn_state.session, exmpp_client_roster:get_roster("foo")), io:format("Ok.~n"), loop(State). -spec loop(#conn_state{}) -> ok. loop(State) -> receive stop -> exmpp_session:stop(State#conn_state.session); #received_packet{packet_type=presence, raw_packet=Packet} -> ephraim ! {roster, {presence, Packet}}, loop(State); #received_packet{packet_type=message, raw_packet=Packet} -> From = exmpp_xml:get_attribute(Packet, from, <<"unknown">>), ephraim ! {receive_message, From, Packet}, loop(State); #received_packet{packet_type=iq, raw_packet=Packet} -> IQ = exmpp_iq:xmlel_to_iq(Packet), ephraim ! {receive_iq, IQ}, loop(State); Msg -> io:format("ephraim_conn: ~p~n", [Msg]), loop(State) end.