This commit is contained in:
anlicheng 2023-09-04 12:24:40 +08:00
parent d412ebe692
commit 6bd2528ad5

View File

@ -228,19 +228,28 @@ handle_call({publish_message, _, _, _}, _From, State) ->
{reply, {error, <<"主机状态错误,发送命令失败"/utf8>>}, State};
%%
handle_call({activate, _}, _From, State = #state{has_session = false}) ->
handle_call({activate, Auth}, _From, State = #state{uuid = UUID, host_id = HostId, has_session = false}) ->
case Auth of
true ->
ok;
false ->
{ok, _} = host_bo:change_status(UUID, ?HOST_OFFLINE),
change_devices_status(HostId, ?DEVICE_UNKNOWN)
end,
{reply, ok, State};
handle_call({activate, true}, _From, State = #state{has_session = true}) ->
{reply, ok, State};
handle_call({activate, false}, _From, State = #state{host_id = HostId, uuid = UUID, monitor_ref = MRef, channel_pid = ChannelPid, has_session = true}) ->
handle_call({activate, Auth}, _From, State = #state{host_id = HostId, uuid = UUID, monitor_ref = MRef, channel_pid = ChannelPid, has_session = true}) ->
case Auth of
true ->
ok;
false ->
%% monitor
erlang:demonitor(MRef),
ws_channel:stop(ChannelPid, closed),
{ok, _} = host_bo:change_status(UUID, ?HOST_OFFLINE),
change_devices_status(HostId, ?DEVICE_UNKNOWN),
change_devices_status(HostId, ?DEVICE_UNKNOWN)
end,
{reply, ok, State#state{monitor_ref = undefined, channel_pid = undefined, has_session = false}};
%% channel