processone / xmpp

Erlang/Elixir XMPP parsing and serialization library on top of Fast XML

Home Page:http://process-one.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use in Elixir client

Freyskeyd opened this issue · comments

Hello,

I'm trying to use this library on an Elixir client but I can't find any examples or documentation on how to setup it and use it...

Can someone help me on this?

There is no documentation on how to use it (and will never be for Elixir). But existent code can be used as an example (it's not in Elixir though):

We will add the documentation for writing clients when we clean up the API: it's currently a bit cumbersome and we only started to export it, i.e. you should use the development master branch.

This is a minimum working example (in Erlang):

-module(ex).
-behaviour(xmpp_stream_out).

-include("xmpp.hrl").

%% API
-export([start/0]).
-export([init/1,
	 tls_options/1,
	 tls_verify/1,
	 sasl_mechanisms/1,
	 handle_stream_established/1,
	 handle_stream_end/2,
	 handle_packet/2]).

start() ->
    application:ensure_all_started(xmpp),
    JID = jid:decode(<<"user@server/resource">>),
    Password = <<"pass">>,
    Cert = <<"cert.pem">>,
    Server = JID#jid.lserver,
    xmpp_stream_out:start(?MODULE, [Server, Server, {JID, Password, Cert}], []).

init([State, {JID, Password, Certfile}]) ->
    xmpp_stream_out:connect(self()),
    {ok, State#{user => JID#jid.luser,
		resource => JID#jid.lresource,
		password => Password,
		xmlns => ?NS_CLIENT,
		certfile => Certfile}}.

tls_options(#{certfile := Cert}) ->
    [{certfile, Cert}].

tls_verify(_) ->
    false.

sasl_mechanisms(_State) ->
    [<<"PLAIN">>].

handle_stream_end(Reason, State) ->
    error_logger:error_msg("XMPP stream failure: ~s",
			   [xmpp_stream_out:format_error(Reason)]),
    State.

handle_stream_established(State) ->
    error_logger:info_msg("Session established, sending initial presence"),
    xmpp_stream_out:send(State, #presence{}).

handle_packet(Pkt, State) ->
    error_logger:info_msg("Got pkt:~n~s", [xmpp:pp(Pkt)]),
    State.

Hello @zinid and thank's.

I can't make xmpp compile on master, I think I've made a mistake in my mix.exs... I need to figure out why.

I cannot help you with Elixir.