<commit_before>//Server side of the ChatApplication
//Server shows the ChatWidget, but it's not able to use it to send own messages
function ServerControl ()
{
	me.Action("ClientSendMessage").Triggered.connect(this, this.ClientMessage);
	me.Action("ServerSendMessage").Triggered.connect(empty); //Need to register action on Server, but Client is the only one to handle this action
}

//Receive incoming messages from client 
//and pass it to all clients
ServerControl.prototype.ClientMessage = function(sender, msg)
{
	var message = (sender + " : " + msg);
	chatLog.append(message);
	me.Exec(4, "ServerSendMessage", message);
}


//Client side of the ChatApplication
function ClientControl (userName)
{
	this.name = userName;
	lineEdit.returnPressed.connect(this, this.SendMessage);
	me.Action("ServerSendMessage").Triggered.connect(this, this.ReceiveServerMessage);
	me.Exec(2, "ClientSendMessage", this.name, "Joined Chat");	

}

ClientControl.prototype.SendMessage = function()
{
	var msg = lineEdit.text;
	me.Exec(2, "ClientSendMessage", this.name, msg);	
	lineEdit.text = "";
}

ClientControl.prototype.ReceiveServerMessage = function(msg)
{
	chatLog.append(msg);
}

function empty()
{
}

print("Loading ChatApplication");

var widget = ui.LoadFromFile(".\\scenes\\ChatApplication\\ChatWidget.ui", false);	
var chatLog = widget.findChild("chatLog");
var lineEdit = widget.findChild("lineEdit");
var proxy = new UiProxyWidget(widget);
ui.AddWidgetToScene(proxy);
proxy.x = 10;
proxy.y = 10;
proxy.visible = false;
proxy.windowFlags = 0;

var chatControl;
server = me.GetComponentRaw("EC_DynamicComponent", "server");

if (server)
{
	print("Starting Chat Server");
	chatControl = new ServerControl();
	proxy.visible = true;
}
else
{	
	print("Starting Chat Client");
	
	//Insert Username from widget. In future this is replaced
	var joinWidget = ui.LoadFromFile(".\\scenes\\ChatApplication\\JoinWidget.ui", false);	
	var btn = joinWidget.findChild("pushJoin");
	var lineUser = joinWidget.findChild("lineUserName");

	var joinProxy = new UiProxyWidget(joinWidget);
	ui.AddWidgetToScene(joinProxy);
	joinProxy.x = 50;
	joinProxy.y = 50;
	joinProxy.visible = true;<commit_msg>Fixed old code in ChatApplication.js to refer to uiservice. instead of ui.<commit_after>//Server side of the ChatApplication
//Server shows the ChatWidget, but it's not able to use it to send own messages
function ServerControl ()
{
	me.Action("ClientSendMessage").Triggered.connect(this, this.ClientMessage);
	me.Action("ServerSendMessage").Triggered.connect(empty); //Need to register action on Server, but Client is the only one to handle this action
}

//Receive incoming messages from client 
//and pass it to all clients
ServerControl.prototype.ClientMessage = function(sender, msg)
{
	var message = (sender + " : " + msg);
	chatLog.append(message);
	me.Exec(4, "ServerSendMessage", message);
}


//Client side of the ChatApplication
function ClientControl (userName)
{
	this.name = userName;
	lineEdit.returnPressed.connect(this, this.SendMessage);
	me.Action("ServerSendMessage").Triggered.connect(this, this.ReceiveServerMessage);
	me.Exec(2, "ClientSendMessage", this.name, "Joined Chat");	

}

ClientControl.prototype.SendMessage = function()
{
	var msg = lineEdit.text;
	me.Exec(2, "ClientSendMessage", this.name, msg);	
	lineEdit.text = "";
}

ClientControl.prototype.ReceiveServerMessage = function(msg)
{
	chatLog.append(msg);
}

function empty()
{
}

print("Loading ChatApplication");

var widget = uiservice.LoadFromFile(".\\scenes\\ChatApplication\\ChatWidget.ui", false);	
var chatLog = widget.findChild("chatLog");
var lineEdit = widget.findChild("lineEdit");
var proxy = new UiProxyWidget(widget);
uiservice.AddWidgetToScene(proxy);
proxy.x = 10;
proxy.y = 10;
proxy.visible = false;
proxy.windowFlags = 0;

var chatControl;
server = me.GetComponentRaw("EC_DynamicComponent", "server");

if (server)
{
	print("Starting Chat Server");
	chatControl = new ServerControl();
	proxy.visible = true;
}
else
{	
	print("Starting Chat Client");
	
	//Insert Username from widget. In future this is replaced
	var joinWidget = uiservice.LoadFromFile(".\\scenes\\ChatApplication\\JoinWidget.ui", false);	
	var btn = joinWidget.findChild("pushJoin");
	var lineUser = joinWidget.findChild("lineUserName");

	var joinProxy = new UiProxyWidget(joinWidget);
	uiservice.AddWidgetToScene(joinProxy);
	joinProxy.x = 50;
	joinProxy.y = 50;
	joinProxy.visible = true;
{'fraction_non_alphanumeric': 0.13088533453480514, 'fraction_numerical': 0.005406623113313809, 'mean_word_length': 5.370157819225251, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '361145', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1364, 'n_words': 352}