2025-08-27 15:19:27 +08:00

34 lines
1.0 KiB
Erlang

%%%-------------------------------------------------------------------
%%% @author anlicheng
%%% @copyright (C) 2025, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 26. 8月 2025 14:28
%%%-------------------------------------------------------------------
-module(ws_server).
-author("anlicheng").
%% API
-export([start_server/0]).
start_server() ->
{ok, Props} = application:get_env(efka, ws_server),
Acceptors = proplists:get_value(acceptors, Props, 50),
MaxConnections = proplists:get_value(max_connections, Props, 10240),
Backlog = proplists:get_value(backlog, Props, 1024),
Port = proplists:get_value(port, Props),
Dispatcher = cowboy_router:compile([
{'_', [{"/ws", ws_channel, []}]}
]),
TransOpts = [
{port, Port},
{num_acceptors, Acceptors},
{backlog, Backlog},
{max_connections, MaxConnections}
],
{ok, Pid} = cowboy:start_clear(ws_listener, TransOpts, #{env => #{dispatch => Dispatcher}}),
lager:debug("[efka_app] websocket server start at: ~p, pid is: ~p", [Port, Pid]).