fix(gw_jt808): insert channel info

This commit is contained in:
JimMoen 2023-12-13 09:26:04 +08:00
parent d4e964f633
commit ec83ec7730
No known key found for this signature in database
GPG Key ID: 87A520B4F76BA86D
1 changed files with 7 additions and 11 deletions

View File

@ -115,8 +115,8 @@ info(clientid, #channel{clientinfo = #{clientid := ClientId}}) ->
ClientId; ClientId;
info(clientinfo, #channel{clientinfo = ClientInfo}) -> info(clientinfo, #channel{clientinfo = ClientInfo}) ->
ClientInfo; ClientInfo;
info(session, _) -> info(session, #channel{session = Session}) ->
#{}; Session;
info(conn_state, #channel{conn_state = ConnState}) -> info(conn_state, #channel{conn_state = ConnState}) ->
ConnState; ConnState;
info(authcode, #channel{authcode = AuthCode}) -> info(authcode, #channel{authcode = AuthCode}) ->
@ -254,7 +254,7 @@ do_handle_in(Frame = ?MSG(?MC_AUTH), Channel) ->
) )
of of
{ok, _NFrame, NChannel} -> {ok, _NFrame, NChannel} ->
_NChannel = process_connect(Frame, ensure_connected(NChannel)) _ = process_connect(Frame, ensure_connected(NChannel))
end; end;
do_handle_in(Frame = ?MSG(?MC_HEARTBEAT), Channel) -> do_handle_in(Frame = ?MSG(?MC_HEARTBEAT), Channel) ->
handle_out({?MS_GENERAL_RESPONSE, 0, ?MC_HEARTBEAT}, msgsn(Frame), Channel); handle_out({?MS_GENERAL_RESPONSE, 0, ?MC_HEARTBEAT}, msgsn(Frame), Channel);
@ -614,7 +614,7 @@ process_connect(
Channel = #channel{ Channel = #channel{
ctx = Ctx, ctx = Ctx,
conninfo = ConnInfo, conninfo = ConnInfo,
clientinfo = ClientInfo clientinfo = ClientInfo = #{clientid := ClientId}
} }
) -> ) ->
SessFun = fun(_, _) -> #{} end, SessFun = fun(_, _) -> #{} end,
@ -630,9 +630,10 @@ process_connect(
{ok, #{session := Session}} -> {ok, #{session := Session}} ->
NChannel = Channel#channel{session = Session}, NChannel = Channel#channel{session = Session},
%% Auto subscribe downlink topics %% Auto subscribe downlink topics
autosubcribe(NChannel), ok = autosubcribe(NChannel),
_ = start_keepalive(?DEFAULT_KEEPALIVE, NChannel), _ = start_keepalive(?DEFAULT_KEEPALIVE, NChannel),
_ = run_hooks(Ctx, 'client.connack', [ConnInfo, connection_accepted, #{}]), _ = run_hooks(Ctx, 'client.connack', [ConnInfo, connection_accepted, #{}]),
_ = emqx_gateway_ctx:insert_channel_info(Ctx, ClientId, info(NChannel), undefined),
authack({0, MsgSn, NChannel}); authack({0, MsgSn, NChannel});
{error, Reason} -> {error, Reason} ->
log( log(
@ -655,12 +656,7 @@ ensure_connected(
) -> ) ->
NConnInfo = ConnInfo#{connected_at => erlang:system_time(millisecond)}, NConnInfo = ConnInfo#{connected_at => erlang:system_time(millisecond)},
ok = run_hooks(Ctx, 'client.connected', [ClientInfo, NConnInfo]), ok = run_hooks(Ctx, 'client.connected', [ClientInfo, NConnInfo]),
prepare_adapter_topic( prepare_adapter_topic(Channel#channel{conninfo = NConnInfo, conn_state = connected}).
Channel#channel{
conninfo = NConnInfo,
conn_state = connected
}
).
%% Ensure disconnected %% Ensure disconnected
ensure_disconnected( ensure_disconnected(