Prosody muc chat history is not complete - lua

I try to make conference chat using prosody, and for the client I use strophe.js. Everything works great except one thing that the chat history shown to user when they just join in to the room is not complete. For example:
One client has already sent messages to the room like this:
1
2
3
4
5
6
7
8
9
10
But when new client join in to the room, they only get messages like this:
1
3
5
7
9
I try to set max_history_messages = 10 in prosody config, and set maxstanzas = 10 from client. But still the same.
Here is my config file
admins = { "agent#localhost" }
modules_enabled = {
"message_logging";
"roster";
"saslauth";
"tls";
"dialback";
"disco";
"private";
"vcard";
"version";
"uptime";
"time";
"ping";
"pep";
"register";
"admin_adhoc";
"admin_telnet";
"bosh";
"posix";
};
bosh_ports = { 5280 }
bosh_max_inactivity = 60
consider_bosh_secure = true
cross_domain_bosh = true
http_paths = {
bosh = "/http-bind"; -- Serve BOSH at /http-bind
files = "/"; -- Serve files from the base URL
}
allow_registration = true;
daemonize = true;
pidfile = "/var/run/prosody/prosody.pid";
ssl = {
key = "/etc/prosody/certs/localhost.key";
certificate = "/etc/prosody/certs/localhost.crt";
}
c2s_require_encryption = false
s2s_secure_auth = false
authentication = "internal_plain"
log = {
info = "/var/log/prosody/prosody.log";
error = "/var/log/prosody/prosody.err";
{ levels = { "error" }; to = "syslog"; };
}
VirtualHost "localhost"
enabled = true -- Remove this line to enable this host
ssl = {
key = "/etc/prosody/certs/localhost.key";
certificate = "/etc/prosody/certs/localhost.crt";
}
Component "conference.localhost" "muc"
restrict_room_creation = true
max_history_messages = 10
Include "conf.d/*.cfg.lua"
Is there something need to set in config?
Here's how I handle message in Strophe.js:
function onLoginComplete(status) {
console.log(status);
if (status == Strophe.Status.CONNECTING) {
console.log('Strophe is connecting.');
} else if (status == Strophe.Status.CONNFAIL) {
console.log('Strophe failed to connect.');
} else if (status == Strophe.Status.DISCONNECTING) {
console.log('Strophe is disconnecting.');
} else if (status == Strophe.Status.DISCONNECTED) {
console.log('Strophe is disconnected.');
} else if (status == Strophe.Status.CONNECTED) {
console.log('Strophe is connected.');
connection.addHandler(onMessage, null, 'message', null, null, null);
if (!chat_room) {
// join to chatroom
}
}
/**
* on new message handler
**/
function onMessage(message) {
console.log(message);
var type = $(message).attr('type');
var body = $(message).find('body').text();
switch (type) {
case 'groupchat':
console.log(body);
// todo append message to the list
appendMessage(message);
break;
}
return true;
}
Here's one message of the history when user just join the room:
<message xmlns="jabber:client" type="groupchat" to="subkhan#localhost/edff55f2-2980-4d01-bf65-0d2c0b011845" from="test#conference.localhost/subkhan"><body>8</body><delay xmlns="urn:xmpp:delay" stamp="2017-04-12T02:54:48Z"></delay><x xmlns="jabber:x:delay" stamp="20170412T02:54:48"></x></message>
Is there something to do with the delay?
Thank you in advance.

Turns out, all this time client already gets all the complete messages history, except it goes to rawInput(data), not to onMessage() handler. So I just remove the handler and handle the incoming message through rawInput(data).

Related

Scorm files, Ruby on Rails

I have implemented a scorm api in my platform (LMS), for this I have used Ruby on rails, the Scorm gem and the javascript api.
Everything works correctly and the scorm contents are displayed with satisfaction. I do not have much experience in Scorm content, but there is a zip file that they sent me of type scorm, which when it is uploaded to the platform that I am using, it takes a long time to load and execute. when I test this file on Scorm cloud, the content runs normally. The problem is that the platform does not generate any error.
why can this happen?
bugs in my code? or optimization of the Scorm zip file?
The other scorm contents work normally, but this specific one, I have no idea why. I can not think of anything
any ideas? Thank you
this is de api js:
<html>
<head>
<title>VS SCORM - RTE API</title>
<script language="javascript">
function createRequest() {
// this is the object that we're going to (try to) create
var request;
// does the browser have native support for
// the XMLHttpRequest object
try {
request = new XMLHttpRequest();
}
// it failed so it's likely to be Internet Explorer which
// uses a different way to do this
catch (tryIE) {
// try to see if it's a newer version of Internet Explorer
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
}
// that didn't work so ...
catch (tryOlderIE) {
// maybe it's an older version of Internet Explorer
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
// even that didn't work (sigh)
catch (failed) {
alert("Error creating XMLHttpRequest");
}
}
}
return request;
}
//var debug = true;
var debug = false;
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
// ------------------------------------------
// SCORM RTE Functions - Initialization
// ------------------------------------------
function LMSInitialize(dummyString) {
// create request object
var req = createRequest();
// code to prevent caching
var d = new Date();
// set up request parameters - uses GET method
req.open('GET','/scorm/initializesco?code='+d.getTime(),false);
// submit to the server for processing
req.send(null);
// process returned data - error condition
if (req.status != 200) {
alert('Problem with Request');
return "";
}
// process returned data - OK
else {
return "true";
}
}
// ------------------------------------------
// SCORM RTE Functions - Getting and Setting Values
// ------------------------------------------
//function LMSGetValue(varname) {
// if (debug) {
// alert('*** LMSGetValue varname='+varname
// +' varvalue=value ***');
// }
// return "value";
//}
function LMSGetValue(varname) {
// create request object
var req = createRequest();
// set up request parameters - uses GET method
req.open('GET','/scorm/getValue?varname='+urlencode(varname)
+'&code='+Math.random(),false);
// submit to the server for processing
req.send(null);
//alert('LMSGetValue() - ' + req.responseText);
// process returned data - error condition
if (req.status != 200) {
alert('LMSGetValue() - Problem with Request');
return "";
}
// process returned data - OK
else {
return req.responseText.replace("\n","");
}
}
/*
function LMSSetValue(varname,varvalue) {
if (debug) {
alert('*** LMSSetValue varname='+varname
+' varvalue='+varvalue+' ***');
}
return "true";
}
*/
function LMSSetValue(varname,varvalue) {
// create request object
var req = createRequest();
// set up request parameters - uses combined GET and POST
//req.open('POST','nav/setValue?varname='+urlencode(varname)
// +'&code='+Math.random(),false);
// set up request parameters - uses combined GET and POST
req.open('POST','/scorm/setValue?varname='+urlencode(varname)
+'&code='+Math.random(),false);
// send header information along with the POST data
var params = 'varvalue='+urlencode(varvalue);
req.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
//req.setRequestHeader("Content-length", params.length);
//req.setRequestHeader("Connection", "close");
// submit to the server for processing
req.send(params);
// process returned data - error condition
if (req.status != 200) {
alert('LMSSetValue() - Problem with Request');
return "false";
}
// process returned data - OK
else {
return "true";
}
}
function LMSCommit(dummyString) {
LMSGetValue('');
if (debug)
{
//alert('*** LMSCommit ***');
}
return "true";
}
function LMSFinish(dummyString) {
// create request object
var req = createRequest();
// code to prevent caching
var d = new Date();
// set up request parameters - uses GET method
req.open('GET','/scorm/finishsco?code='+d.getTime(),false);
// submit to the server for processing
req.send(null);
// process returned data - error condition
if (req.status != 200) {
alert('Problem with Request');
return "";
}
// process returned data - OK
else {
return "true";
}
}
// ------------------------------------------
// SCORM RTE Functions - Error Handling
// ------------------------------------------
function LMSGetLastError() {
if (debug) { alert('*** LMSGetLastError ***'); }
sleep(1000);
return 0;
}
function LMSGetDiagnostic(errorCode) {
if (debug) {
alert('*** LMSGetDiagnostic errorCode='+errorCode+' ***');
}
return "diagnostic string";
}
function LMSGetErrorString(errorCode) {
if (debug) {
alert('*** LMSGetErrorString errorCode='+errorCode+' ***');
}
return "error string";
}
function urlencode( str ) {
//
// Ref: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urlencode/
//
var histogram = {}, unicodeStr='', hexEscStr='';
var ret = (str+'').toString();
var replacer = function(search, replace, str) {
var tmp_arr = [];
tmp_arr = str.split(search);
return tmp_arr.join(replace);
};
// The histogram is identical to the one in urldecode.
histogram["'"] = '%27';
histogram['('] = '%28';
histogram[')'] = '%29';
histogram['*'] = '%2A';
histogram['~'] = '%7E';
histogram['!'] = '%21';
histogram['%20'] = '+';
histogram['\u00DC'] = '%DC';
histogram['\u00FC'] = '%FC';
histogram['\u00C4'] = '%D4';
histogram['\u00E4'] = '%E4';
histogram['\u00D6'] = '%D6';
histogram['\u00F6'] = '%F6';
histogram['\u00DF'] = '%DF';
histogram['\u20AC'] = '%80';
histogram['\u0081'] = '%81';
histogram['\u201A'] = '%82';
histogram['\u0192'] = '%83';
histogram['\u201E'] = '%84';
histogram['\u2026'] = '%85';
histogram['\u2020'] = '%86';
histogram['\u2021'] = '%87';
histogram['\u02C6'] = '%88';
histogram['\u2030'] = '%89';
histogram['\u0160'] = '%8A';
histogram['\u2039'] = '%8B';
histogram['\u0152'] = '%8C';
histogram['\u008D'] = '%8D';
histogram['\u017D'] = '%8E';
histogram['\u008F'] = '%8F';
histogram['\u0090'] = '%90';
histogram['\u2018'] = '%91';
histogram['\u2019'] = '%92';
histogram['\u201C'] = '%93';
histogram['\u201D'] = '%94';
histogram['\u2022'] = '%95';
histogram['\u2013'] = '%96';
histogram['\u2014'] = '%97';
histogram['\u02DC'] = '%98';
histogram['\u2122'] = '%99';
histogram['\u0161'] = '%9A';
histogram['\u203A'] = '%9B';
histogram['\u0153'] = '%9C';
histogram['\u009D'] = '%9D';
histogram['\u017E'] = '%9E';
histogram['\u0178'] = '%9F';
// Begin with encodeURIComponent, which most resembles PHP's encoding functions
ret = encodeURIComponent(ret);
for (unicodeStr in histogram) {
hexEscStr = histogram[unicodeStr];
ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
}
// Uppercase for full PHP compatibility
return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
return "%"+m2.toUpperCase();
});
}
</script>
</head>
<body>
<p>
</body>
</html>
You're using blocking GET/SET requests (XHR async=false) to your backend for every LMSGetValue call. Some courses are much more aggressive about how many things they get and set at launch/initialization time. Most SCORM implementations do the heavy lifting in JS (all GET value processing never touches a server, most commonly) and only go to the backend for user state storage, often at a commit or some storage frequency. If that's the issue, there's no way to fix it that doesn't involve rewriting your interface to do all the SCORM logic client-side instead of server-side, as you can't switch to using async GET calls since LMSGetValue expects the return to be the value needed.

How to create an ad-hoc email and send it using Acumatica

In Acumatica you can use notifications to automate some emails.
In my scenario, we are creating a process that will at non-specific (non-set) times need to send an email when a specific condition is triggered, such as an employee needs to know they need to do something.
We are building this logic into the system and I am looking for a code sample of how to send the email when this happens.
We will be using an email template, but need to accomplish the feat in code.
I would hope there should be some kind of acumatica email class where we could just call it and pass the required info something like:
PX.Common.email.Send(params)...
Any example code would be appreciated.
It turns out that there is a KB article that gives an example of how to do this.
for our scenario, Here is a more recent version of the code that has been verified to send an email using either of 2 email templates.
private void mSendEmail(string toEmail, int? emailTemplateID, long? noteid, string source, string toDisplayName)
{
bool sent = false;
string sError = "Failed to send E-mail.";
POOrder porec = poOrder.Select(noteid);
EPExpenseClaim eprec = epExpense.Select(noteid);
try
{
Notification rowNotification = PXSelect<Notification,
Where<Notification.notificationID, Equal<Required<Notification.notificationID>>>>.Select(this, emailTemplateID);
if (rowNotification == null)
throw new PXException(PXMessages.Localize("Notification Template for Escalation is not specified."));
if (String.IsNullOrEmpty(toEmail))
throw new PXException(PXMessages.Localize("E-mail is not specified for Escalation Employee. Name=[" + toDisplayName +"]"));
if (source == "PO")
{
var sender = TemplateNotificationGenerator.Create(porec, rowNotification.NotificationID.Value);
sender.MailAccountId = rowNotification.NFrom.HasValue ?
rowNotification.NFrom.Value :
PX.Data.EP.MailAccountManager.DefaultMailAccountID;
sender.To = toEmail;
IEnumerable<EPActivity> epActivityArray = sender.Send();
if (epActivityArray.Count() > 0)
{ sent = true; }
}
if (source == "EP")
{
var sender = TemplateNotificationGenerator.Create(eprec, rowNotification.NotificationID.Value);
sender.MailAccountId = rowNotification.NFrom.HasValue ?
rowNotification.NFrom.Value :
PX.Data.EP.MailAccountManager.DefaultMailAccountID;
sender.To = toEmail;
IEnumerable<EPActivity> epActivityArray = sender.Send();
if (epActivityArray.Count() > 0)
{ sent = true; }
}
}
catch (Exception Err)
{
sent = false;
sError = Err.Message;
}
if (!sent)
throw new PXException(PXMessages.Localize(sError));
}
Here I want to present shorter version of sending email:
using PX.Objects.EP;
using PX.Data.EP;
**...**
var sender = new NotificationGenerator
{
To = "someone#example.com",
Subject = $"Subject information {DateTime.Now:d}",
Body = "Body of message",
BodyFormat = EmailFormatListAttribute.Text
};
sender.Send();

Google Dart HTTP Error Checking

I'm attempting to detect whether a connection refused error is taking place with the following tutorial: https://www.dartlang.org/dart-by-example/#http-requests-and-responses ; However, I continue to receive the method not found exception and cannot receive any feedback whether my HTTP Response was working or not. Any ideas would be appreciated. Please let me know if you need more information. --ignore "shroot".
handleFailure(error) {
print('Something went wrong.');
print(error.message);
}
void loadData(String url) {
//url = "${baseRestfulUrl}"+ QUERY_ALL_TARGET_ASSETS_BASE_URL;
print(url);
//call the web server asynchronously
var request = HttpRequest.getString(url).then(onDataLoaded);
request.catchError(handleFailure);
if (request == null) {
var warn = (shroot.querySelector('#warning')
..text = "No records could be found to match the search criteria."
..style.color = "Red");
ButtonElement resetBtn = shroot.querySelector("#reset-btn");
resetBtn.disabled = true;
}
else if(request == 404)
{
var warn = (shroot.querySelector('#warning')
..text = "Error serving data. Please restart server."
..style.color = "Red");
}
else if(request == "ERR_CONNECTION_REFUSED")
{
var warn = (shroot.querySelector('#warning')
..text = "Error serving data. Please restart server."
..style.color = "Red");
}
else if(request != null)
{
var warn = (shroot.querySelector('#warning')
..text = ""
..style.color = "#fff");
ButtonElement resetBtn = shroot.querySelector("#reset-btn");
resetBtn.disabled = false;
}
else {
var warn = (shroot.querySelector('#warning')
..text = "Error serving data. Please restart server."
..style.color = "Red");
ButtonElement resetBtn = shroot.querySelector("#reset-btn");
resetBtn.disabled = false;
}
}
The link you added is about Dart I/O and Command Line Apps. This doesn't apply to Dart in the browser.
Dart has to delegate to the browser API with limited capabilities and therefore there are differences.
In the case of an error an instance of ProgressEvent is passed to this method
handleFailure(error) {
print('Something went wrong.');
// print(error.message); // ProgressEvent doesn't have a `message` getter
// the progress event doesn't provide any further information
if(error is ProgressEvent && (error as ProgressEvent).type == 'error') {
print('An error has occured'); // as we already know because `handleFailure()` was called
}
}
this code
if (request == null) {
is actually called before the request was sent because it is not inside a .then
var request = HttpRequest.getString(url).then(onDataLoaded);
request.catchError(handleFailure)
.then((e) {
if(request == null) { // doesn't make sense because you just assigned a value to request
...
}
});

Flash NetStream.seek method works in local tests but not on server

I have a 20 minute FLV which streams just fine on server. Client would like to preserve user's locations between sessions so time() is saved to mySQL and passed back in as a FlashVar and is (if set) fed to seek() and to a text field for testing. Thing is the seek() works fine locally but on the server I always get a NetStream.Seek.InvalidTime error no matter what the seek() is set to. Docs are here; it's a dead simple function.
// EDIT Just added keyframes to FLV using http://www.buraks.com/flvmdi/ but this did not resolve issue
src = "videos/LivingProof.flv";
nc = new NetConnection();
nc.connect(null);
nets = new NetStream(nc);
mc_flv.attachVideo(nets);
//Attach your netstream audio to a movielcip:
snd.attachAudio(nets);
// create a sound object
my_snd = new Sound(snd);
// to adjust the volume
my_snd.setVolume(50);
nets.play(src);
if (starttime) {
var dest:Number = Math.floor(starttime);
nets.seek(dest);
this.test.text = 'target time = ' + dest;
}
nets.onStatus = function(infoObject:Object) {
if( infoObject.level == "status" && infoObject.code == "NetStream.Play.Stop" ) {
getURL("javascript:setTime('9999999999');", "_self");
nets.seek(0);
nets.pause();
mc_play.gotoAndStop(1);
trace('onStatus listener fired');
} else if (infoObject.code == "NetStream.Seek.InvalidTime") {
_root.test.text = "NetStream.Seek.InvalidTime";
nets.seek(infoObject.details);
}
_root.status.text = infoObject.code;
};
Anyone ever seen this before?
Try adding an if statement to your onStatus handler to check for the NetStream.Play.Start code and move the seek logic to that:
src = "videos/LivingProof.flv";
nc = new NetConnection();
nc.connect(null);
nets = new NetStream(nc);
mc_flv.attachVideo(nets);
//Attach your netstream audio to a movielcip:
snd.attachAudio(nets);
// create a sound object
my_snd = new Sound(snd);
// to adjust the volume
my_snd.setVolume(50);
nets.play(src);
nets.onStatus = function(infoObject:Object) {
if( infoObject.level == "status" && infoObject.code == "NetStream.Play.Stop" ) {
getURL("javascript:setTime('9999999999');", "_self");
nets.seek(0);
nets.pause();
mc_play.gotoAndStop(1);
trace('onStatus listener fired');
} else if (infoObject.code == "NetStream.Play.Start) {
if (starttime) {
var dest:Number = Math.floor(starttime);
nets.seek(dest);
this.test.text = 'target time = ' + dest;
}
} else if (infoObject.code == "NetStream.Seek.InvalidTime") {
_root.test.text = "NetStream.Seek.InvalidTime";
nets.seek(infoObject.details);
}
_root.status.text = infoObject.code;
};

Grails Issue Dealing With Tcp Client & Tcp Server

I created a Tcp Client & Tcp Server in Groovy awhile back and had no issues with it. I was only connecting to one machine at the time to gather data. This time I am attempting to connect to the script on multiple hosts and it is only saving one of the hosts information in my grails app.
My Grails application is simple, it has a domain class for Machines (basically the computers and the information on them that I seek) and it will use my TcpClient.groovy script to connect and gather information from the TcpServer.groovy on the other computers. For each host, it should save the information gathered, however, it seems to skip right over saving any host aside from the last one.
Tcp Client :
//TCP CLIENT
public void queryData(def hosts) {
for(int aHost = 0; aHost < hosts.size; aHost++) {
cristalClient(hosts[aHost]);
}
}
public void cristalClient(String host) {
commands = ["dateScan", "computerName", "ip", "quit"]
answers = [commands.size]
requestSocket = new Socket(host, 2000)
r = new BufferedReader(new InputStreamReader(requestSocket.getInputStream()));
w = new BufferedWriter(new OutputStreamWriter(requestSocket.getOutputStream()));
String message = "Connection was successful"
message = readAvailable(r)
println("Sever>" + message)
for(int n = 0; n < commands.size; n++) {
sendMessage(commands[n]);
answers[n] = readAvailable(r)
}
lastRead = answers[0]
machineName = answers[1]
ipAddress = answers[3]
w.flush()
w.close()
}
public String readAvailable(r) {
String out = ""
String dum = null
while((dum = r.readLine()) !=null) {
if(dum == ">>EOF<<") return out
if(out.length() > 0) out += "\r\n"
out += dum
}
return out
}
public void sendMessage(msg) {
w.write(msg+"\r\n");
w.flush();
println("Client>" + msg);
}
public void printData(abc) {
abc.eachWithIndex { it, index ->
println "Drive $index"
it.each { k, v ->
println "\t$k = $v"
}
}
}
Tcp Server :
//TCP Server
def server = new ServerSocket(2000)
println("Waiting for connection")
server.accept() { socket ->
socket.withStreams { input, output ->
w = new BufferedWriter(new OutputStreamWriter(output))
String message = "Connection was successful"
r = new BufferedReader(new InputStreamReader(input))
while(true) {
if(message != null) {
sendMessage(message)
message = null
}
String a = r.readLine()
if(a == "dateScan") {
message = new Date
} else if(a == "computerName") {
message = InetAddress.getLocalHost().hostName
} else if(a == "ip") {
message = InetAddress.getLocalHost().getHostAddress()
} else if(a == "quit") {
server.close()
return
} else {
message = "$a command unknown."
println message
}
}
}
}
def sendMessage(String msg) {
println( "sending: >" + msg + "<" )
w.writeLine(msg)
w.writeLine(">>EOF<<")
w.flush();
}
Grails Controller :
//Grails Controller
CollectMachines {
def w = new tcpClient()
def hosts = ["winXp", "Win7"]
w.queryData(hosts)
def abc = w.hardDrive
abc.each { println it }
int numberOfDrives = abc.size()
//add new machine
numberOfDrives.times {
def machineName = abc.computerName[it]
def machineInstance = Machine.findByMachineName(machineName)
if (!machineInstance) {
machineInstance = new Machine(machineName)
}
def lastScan = abc.lastScan[it]
def scanDate = new Date().parse("E MMM dd H:m:s z yyyy", lastScan)
def ipAddress = abc.ipAddress[it]
machineInstance.setIpAddress(ipAddress)
machineInstance.setDateScanned(scanDate)
machineInstance.save()
}
redirect(action: "list")
}
Do I need to put a pause in so that the server has time to send a response? My Tcp Client does send out all the commands but only gets responses for the last set of commands.
Also, sorry for the indentation issues with my code snippets, I'm not sure why they are messed up.
.
There are a few problems with your code. tcpClient never assigns to hardDrive, for example. Assuming this is an oversight, I think the real problem is that tcpClient is querying data for multiple hosts, and storing all the results in the same instance variables answers, and ultimately lastRead, machineName, and ipAddress.
You need to store the results for each host separately. One way would be to have answers be a map of lists. For example, answers[host][0] would be the first answer for a given host.
I don't think any kind of pause is necessary.

Resources