diff --git a/src/efka_app.erl b/src/efka_app.erl index 62c08b4..e90bab1 100644 --- a/src/efka_app.erl +++ b/src/efka_app.erl @@ -31,7 +31,7 @@ start_http_server() -> Dispatcher = cowboy_router:compile([ {'_', [ - {"/ws", ws_channel, []}, + {"/ws", service_channel, []}, {"/files/[...]", cowboy_static, {dir, "/usr/local/code/downloads"}}, {"/upload", upload_channel, []} ]} diff --git a/src/transport/ws_channel.erl b/src/transport/service_channel.erl similarity index 85% rename from src/transport/ws_channel.erl rename to src/transport/service_channel.erl index 7e0291d..28538b6 100644 --- a/src/transport/ws_channel.erl +++ b/src/transport/service_channel.erl @@ -6,7 +6,7 @@ %%% @end %%% Created : 11. 1月 2021 上午12:17 %%%------------------------------------------------------------------- --module(ws_channel). +-module(service_channel). -author("licheng5"). -include("efka_tables.hrl"). -include("service_pb.hrl"). @@ -36,7 +36,7 @@ init(Req, Opts) -> {cowboy_websocket, Req, Opts}. websocket_init(_State) -> - logger:debug("[ws_channel] get a new connection"), + logger:debug("[service_channel] get a new connection"), %% 初始状态为true {ok, #state{}}. @@ -45,15 +45,15 @@ websocket_handle(ping, State) -> websocket_handle({binary, <>}, State) -> Request = service_pb:decode_msg(PacketBin, 'ServiceRequest'), - logger:debug("[ws_channel] get request: ~p", [Request]), + logger:debug("[service_channel] get request: ~p", [Request]), handle_request(Request, State); websocket_handle({binary, <>}, State) -> Cast = service_pb:decode_msg(PacketBin, 'ServiceCast'), - logger:debug("[ws_channel] get cast: ~p", [Cast]), + logger:debug("[service_channel] get cast: ~p", [Cast]), handle_cast(Cast, State); websocket_handle(Info, State) -> - logger:error("[ws_channel] get a unknown message: ~p, channel will closed", [Info]), + logger:error("[service_channel] get a unknown message: ~p, channel will closed", [Info]), {ok, State}. %% 订阅的消息 @@ -61,22 +61,22 @@ websocket_info({topic_broadcast, Topic, Content}, State = #state{}) -> Packet = service_pb:encode_msg(#'ServiceCast'{ body = {topic_event, #'ServiceCast.TopicEvent'{topic = Topic, content = Content}} }), - logger:debug("[ws_channel] will publish topic: ~p", [Topic]), + logger:debug("[service_channel] will publish topic: ~p", [Topic]), {reply, {binary, <>}, State}; %% service进程关闭 websocket_info({'DOWN', _Ref, process, ServicePid, Reason}, State = #state{service_pid = ServicePid}) -> - logger:debug("[ws_channel] container_pid: ~p, exited: ~p", [ServicePid, Reason]), + logger:debug("[service_channel] container_pid: ~p, exited: ~p", [ServicePid, Reason]), {stop, State#state{service_pid = undefined}}; %% 处理关闭信号 websocket_info({stop, Reason}, State) -> - logger:debug("[ws_channel] the channel will be closed with reason: ~p", [Reason]), + logger:debug("[service_channel] the channel will be closed with reason: ~p", [Reason]), {stop, State}; %% 处理其他未知消息 websocket_info(Info, State) -> - logger:debug("[ws_channel] channel get unknown info: ~p", [Info]), + logger:debug("[service_channel] channel get unknown info: ~p", [Info]), {ok, State}. %% 进程关闭事件 @@ -87,7 +87,7 @@ terminate(Reason, _Req, State = #state{service_id = ServiceId, is_registered = I false -> ok end, - logger:debug("[ws_channel] channel close with reason: ~p, state is: ~p", [Reason, State]), + logger:debug("[service_channel] channel close with reason: ~p, state is: ~p", [Reason, State]), ok. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -114,7 +114,7 @@ handle_request(#'ServiceRequest'{packet_id = PacketId, request = {register, #'Se {reply, {binary, result_reply_packet(PacketId, <<"ok">>)}, State#state{service_id = ServiceId, service_pid = ServicePid, is_registered = true}}; {error, Error} -> - logger:warning("[ws_channel] service_id: ~p, attach_channel get error: ~p", [ServiceId, Error]), + logger:warning("[service_channel] service_id: ~p, attach_channel get error: ~p", [ServiceId, Error]), {reply, {binary, error_reply_packet(PacketId, -1, <<"attach channel failed">>)}, State} end; @@ -153,4 +153,4 @@ error_reply_packet(PacketId, Code, Message) when is_integer(PacketId), is_intege packet_id = PacketId, reply = {error, #'ServiceReply.Error'{code = Code, message = Message}} }), - <>. \ No newline at end of file + <>.