These are chat archives for synrc/n2o

27th
May 2017
Namdak Tonpa
@5HT
May 27 2017 05:55
смотри какая система топиков
%% Topics Format:
%% Client:
%% actions/init/emqttd_198234215548221
%% Server:
%% events/index/maxim@synrc.com/emqttd_198234215548221
%% events/login/anon/emqttd_198234215548221
actions — event в стиле Nitrogen
кстати init нада удалить — просто actions/emqttd_198234215548221
Namdak Tonpa
@5HT
May 27 2017 06:40
весь N2O свелся к такой функции
on_message_publish(Message = #mqtt_message{topic = <<"events/",
                   RestTopic/binary>> = Topic,
                   from={ClientId,_},
                   payload = Payload}, _Env) ->
    Address = emqttd_topic:words(RestTopic),
    BERT    = binary_to_term(Payload),
    io:format("on_message_publish: ~p~n", [{events, Topic, ClientId}]),
    io:format("BERT: ~p~n",[{BERT,Address}]),
    case Address of
         [Mod, U, JavaScriptId] ->
         RTopic = iolist_to_binary(["actions/",ClientId]),
         Module     = erlang:binary_to_atom(Mod, utf8),
         Cx         = #cx{module=Module,session=ClientId,formatter=bert},
         put(context,Cx),
         n2o:cache(ClientId,Cx),
         case n2o_proto:info(BERT,[],Cx) of
              {reply, {binary, M}, _, _} ->
                      emqttd:publish(emqttd_message:make(ClientId, RTopic, M));
            Return -> io:format("ERR: Invalid Return ~p~n",[Return]),   ok end;
           Address -> io:format("ERR: Unknown Address ~p~n",[Address]), ok end,
    {ok, Message};
{init,<<>>} теперь шлется из JavaScript
    onSuccess: function ()  { console.log("N2O Connected");
                              ws.send(enc(tuple(atom('init'),bin('')))); }
и попадает в {init,_} в n2o_nitro
Reply топик определяется по ClientId, то что с циферками вконце топиков