<commit_before>-module(xgate_websocket_handler).
-include("lager.hrl").


%% API


%% websocket handler
-export([init/3]).
-export([websocket_init/3]).
-export([websocket_handle/3]).
-export([websocket_info/3]).
-export([websocket_terminate/3]).


-record(state, {
	nickname	= <<>> :: binary(),
	xnest_name	= <<>> :: binary(),
	xnest_pid	= <<>> :: pid()
}).


%% type()
-type req() :: cowboy_http:req().
-type json() :: jsx:json_text().


%% @private
init({tcp, http}, _Req, _Opts) ->
	{upgrade, protocol, cowboy_websocket};

%% @private
init({ssl, http}, _Req, _Opts) ->
	{upgrade, protocol, cowboy_websocket}.



%% @private
websocket_init(_TransportName, Req, _Opts) ->
	{XNestName, Req1} = parse_xnest_name(Req),
	{NickName, Req2} = parse_nickname(Req1),
	self() ! {'self'},		%% send a command to self 
	{ok, XNestPid} = join_xnest(XNestName, NickName),
	State = #state{
		nickname	= NickName,
		xnest_name	= XNestName,
		xnest_pid	= XNestPid
	},
	Req3 = cowboy_req:set_resp_header(<<"access-control-allow-origin">>, <<"*">>, Req2),
	self() ! {'member_count'},		%% send a command to self 
	self() ! {'members'},		%% send a command to self 
	self() ! {'history'},		%% send a command to self 
	{ok, Req3, State}.



%% @private
%% @doc Receive Message from client and send it to XNest
websocket_handle({text, Msg}, Req, State ) ->
	lager:info("xnestpid: ~p , selfpid: ~p , ip: ~p send a message:~ts", [State#state.xnest_pid, self(), element(8, Req), Msg]),
	parse_msg(Msg, State),			%%parse  message and do it with type
	{ok, Req, State};<commit_msg>log origin url<commit_after>-module(xgate_websocket_handler).
-include("lager.hrl").


%% API


%% websocket handler
-export([init/3]).
-export([websocket_init/3]).
-export([websocket_handle/3]).
-export([websocket_info/3]).
-export([websocket_terminate/3]).


-record(state, {
	nickname	= <<>> :: binary(),
	xnest_name	= <<>> :: binary(),
	xnest_pid	= <<>> :: pid()
}).


%% type()
-type req() :: cowboy_http:req().
-type json() :: jsx:json_text().


%% @private
init({tcp, http}, _Req, _Opts) ->
	{upgrade, protocol, cowboy_websocket};

%% @private
init({ssl, http}, _Req, _Opts) ->
	{upgrade, protocol, cowboy_websocket}.



%% @private
websocket_init(_TransportName, Req, _Opts) ->
	{XNestName, Req1} = parse_xnest_name(Req),
	{NickName, Req2} = parse_nickname(Req1),
	self() ! {'self'},		%% send a command to self 
	{ok, XNestPid} = join_xnest(XNestName, NickName),
	State = #state{
		nickname	= NickName,
		xnest_name	= XNestName,
		xnest_pid	= XNestPid
	},
	Req3 = cowboy_req:set_resp_header(<<"access-control-allow-origin">>, <<"*">>, Req2),
	self() ! {'member_count'},		%% send a command to self 
	self() ! {'members'},		%% send a command to self 
	self() ! {'history'},		%% send a command to self 
	{ok, Req3, State}.



%% @private
%% @doc Receive Message from client and send it to XNest
websocket_handle({text, Msg}, Req, State ) ->
	{OriginUrl, Req} = cowboy_req:header(<<"origin">>, Req),
	lager:info("xnestpid:~p(~p), selfpid: ~p, ip: ~p send a message:~ts", [State#state.xnest_pid, OriginUrl, self(), element(8, Req), Msg]),
	parse_msg(Msg, State),			%%parse  message and do it with type
	{ok, Req, State};
{'fraction_non_alphanumeric': 0.20062992125984253, 'fraction_numerical': 0.007559055118110236, 'mean_word_length': 4.785063752276867, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '103097', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1239, 'n_words': 279}