Client sub/unsub mount topic

This commit is contained in:
turtled 2018-04-21 10:43:43 +08:00
parent 58e3555e9b
commit 92f3036f1f
1 changed files with 6 additions and 4 deletions

View File

@ -162,11 +162,12 @@ received(Packet = ?PACKET(Type), State = #proto_state{stats_data = Stats}) ->
subscribe(RawTopicTable, ProtoState = #proto_state{client_id = ClientId, subscribe(RawTopicTable, ProtoState = #proto_state{client_id = ClientId,
username = Username, username = Username,
session = Session}) -> session = Session,
mountpoint = MountPoint}) ->
TopicTable = parse_topic_table(RawTopicTable), TopicTable = parse_topic_table(RawTopicTable),
case emqttd_hooks:run('client.subscribe', [ClientId, Username], TopicTable) of case emqttd_hooks:run('client.subscribe', [ClientId, Username], TopicTable) of
{ok, TopicTable1} -> {ok, TopicTable1} ->
emqttd_session:subscribe(Session, TopicTable1); emqttd_session:subscribe(Session, mount(MountPoint, TopicTable1));
{stop, _} -> {stop, _} ->
ok ok
end, end,
@ -174,10 +175,11 @@ subscribe(RawTopicTable, ProtoState = #proto_state{client_id = ClientId,
unsubscribe(RawTopics, ProtoState = #proto_state{client_id = ClientId, unsubscribe(RawTopics, ProtoState = #proto_state{client_id = ClientId,
username = Username, username = Username,
session = Session}) -> session = Session,
mountpoint = MountPoint}) ->
case emqttd_hooks:run('client.unsubscribe', [ClientId, Username], parse_topics(RawTopics)) of case emqttd_hooks:run('client.unsubscribe', [ClientId, Username], parse_topics(RawTopics)) of
{ok, TopicTable} -> {ok, TopicTable} ->
emqttd_session:unsubscribe(Session, TopicTable); emqttd_session:unsubscribe(Session, mount(MountPoint, TopicTable));
{stop, _} -> {stop, _} ->
ok ok
end, end,