AppWarp onPrivateUpdateReceived doesn't work - appwarp

var codestring = this.ball + " " + this.ball.position["x"] + " "
+ this.ball.position["y"];
_warpclient.sendPrivateUpdatePeers(enemy, codestring);
I use this function to send peers to the person with defined name enemy.
function onSendPrivateUpdateDone (result){
console.log('Update done ' + result);
}
onSendPrivateUpdateDone works and write messages to person who send peers, here https://apphq.shephertz.com/appWarp/index#/testManager it's noted that my messages are sent, room is created and players are connected to the room, but the person who must accept message doesn't do that, because function onPrivateUpdateReceived callback does nothing.
onPrivateUpdateReceived(userName, msg){
console.log("Username: "+userName);
console.log("Message: "+msg);
}

onPrivateUpdateReceived recieves msgs from the tosendPrivateUpdate method, you should change sendPrivateUpdatePeers to sendPrivateUpdate to work.

Related

Struggling with flask-socketio rooms

I have a project where I need to build a chat platform using flask-socketio. Everything works until I try to add rooms, I get the following error:
application.py", line 92, in on_join
send({"msg", username + " has joined the " + room + " room."}, room=room) TypeError: unsupported operand type(s) for +: 'NoneType'
and 'str'
I'm not really sure where to look
#socketio.on('join')
def on_join(data):
"""User joins a room"""
username = data["username"]
room = data["room"]
join_room(room)
# Broadcast that new user has joined
send({"msg", username + " has joined the " + room + " room."}, room=room)
function joinRoom(room) {
// Join room
socket.emit('join', {'username': localStorage.getItem('displayname'), 'room': room});
// Clear message area
document.querySelector('#messages').innerHTML = '';
// Autofocus on text box
document.querySelector("#display-messages").focus();
}
Should output "username has joined the 'roomname' room.", clear the message list as the channel changes, and allow you to speak in the new channel.

Incoming Express parameters are not the same as whats passed in

I have a strange issue where I have passed in parameters from a URL, into my Express server,
When I get the req.params.code & req.params.mode variables, they are different than what is passed in through the URL.
Allow me to show you...
Here is the Express code:
router.get('/verify/:user/:mode/:code', function(req,res){
console.log("STARTING VERIFICATION");
var code = req.params.code;
console.log('code: ' + code);
var user = req.params.user;
console.log('user: ' + user);
var mode = req.params.mode;
console.log('mode: ' + mode);
console.log('req.params: ' + JSON.stringify(req.params));
var regex = new RegExp(["^", req.params.user, "$"].join(""), "i");
console.log('REGEX: ' + regex);
var verified = false;
console.log('req.params: ' + req.params);
console.log('req.body: ' + req.body);
console.log("rx: "+ regex);
console.log('req.params.code: ' + req.params.code);
console.log('req.params.user: ' + req.params.user);
etc... etc... etc...
Here is the output in the console:
STARTING VERIFICATION
code: background-cycler.js
user: admin
mode: js
req.params: {"user":"admin","mode":"js","code":"background-cycler.js"}
REGEX: /^admin$/i
req.params: [object Object]
req.body: [object Object]
rx: /^admin$/i
req.params.code: background-cycler.js
req.params.user: admin
Here is the URL that is passed into the browser:
https://examplesite.com/verify/admin/sms/9484
I want to say that this code worked prior to dusting it off and moving an instance to google's cloud compute...
As you can see, the parameters passed in to the verify, code should be 9484 and mode should be sms. Instead i'm getting an unintended js filename, and a js mode instead.
UPDATE: As requested I added this within the Express route function:
console.log(req.originalUrl);
and I get this result:
/verify/admin/js/background-cycler.js
I can verify the URL that sent this was:
https://examplesite.com/verify/admin/sms/9484

Spring AMQP + RabbitMQ RPC How to execute/delegate different methods in a class

I spent the entire day trying to get this to work. I've been following the tutorial 5 & 6 for Spring AMQP in the RabbitMQ tutorials page.
Is it possible for a single class to execute a different method based on some property? E.g. Routing key?
I've tried this so far to no avail:
#RabbitListener(bindings = #QueueBinding(
value = #Queue(value = "requests"),
exchange = #Exchange(value = "ourexchange"),
key = "doFunc1")
)
public String func1(long id) {
System.out.println("func1 " + id);
return "func1 " + id;
}
#RabbitListener(bindings = #QueueBinding(
value = #Queue(value = "requests"),
exchange = #Exchange(value = "ourexchange"),
key = "doFunc2")
)
public String func2(long id) {
System.out.println("func2 " + id);
return "func2 " + id;
}
In my client I did this:
public void send() {
System.out.println(" [x] Get func1( account_id: " + accountId + ")");
String response = (String) template.convertSendAndReceive
("ourexchange", "doFunc1", accountId);
System.out.println(" [.] Got '" + response + "'");
System.out.println(" [x] Get func2( account_id: " + accountId + ")");
String response = (String) template.convertSendAndReceive
(exchange.getName(), "doFunc2", accountId);
System.out.println(" [.] Got '" + response + "'");
}
I've got it "somewhat" to work but it appears to work in a round-robin fashion where the first method is called then the next one.
I've already considered the explanation here: Single Queue, multiple #RabbitListener but different services
But since the signatures of both methods look identical I'm not sure it's possible.
Do note that I'm a beginner to the concepts of AMQP (like I've just read about the basics today). Am I doing this right or am I misunderstanding the usage?
The #RabbitListener infrastructure doesn't perform routing based on the routing key. You should use a different queue for each method and let RabbitMQ do the routing at the exchange level.
Alternatively, if you must use a single queue for some reason, you can pass the RECEIVED_ROUTING_KEY as a #Header parameter to your listener and delegate to different methods from the listener.
I've got it "somewhat" to work but it appears to work in a round-robin fashion where the first method is called then the next one.
That's because RabbitMQ sees 2 consumers and will round-robin the messages. You need to use 2 queues or a single method and do the routing therein.

How to email SalesForce users temporary password by using API?

I am using SOAP Partner API and I have a Developer edition. I am creating users by using API. And upon creation of users I want to email these users temporary password which they can use to login to SalesForce.
This is my code:
SaveResult[] results = connection.create(new SObject[] { user });
if (results[0].isSuccess())
{
out.println("Created user: " + results[0].getId());
//connection.setPassword(results[0].getId(), "password");
ResetPasswordResult rpr = connection.resetPassword(results[0].getId());
String result = rpr.getPassword();
System.out.println("The temporary password for user ID " + results[0].getId()
+ " is " + result);
}
else
{
out.println("Error: " + results[0].getErrors()[0].getStatusCode() +
":" + results[0].getErrors()[0].getMessage());
}
This is the output I am getting in console:
The temporary password for user ID 005E0000000MwkZIAS is ucQD2PADs
However, the user is NOT receiving any password. :-(
Thanks,
Wap Rau
If you build & pass an EmailHeader in your soap request you can control what types of emails will get sent from your request.
It looks like you're using WSC, so you can add this call before calling resetPassword, which will enabled emails being sent to users. This should then send the standard reset password email.
connection.setEmailHeader(false, false, true);
use this class to send out an email. include the pwd variable in the string you want to send the user. there's an example that spells everything out
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound.htm

Using Rx to Geocode an address in Bing Maps

I am learning to use the Rx extensions for a Silverlight 4 app I am working on. I created a sample app to nail down the process and I cannot get it to return anything.
Here is the main code:
private IObservable<Location> GetGPSCoordinates(string Address1)
{
var gsc = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService") as IGeocodeService;
Location returnLocation = new Location();
GeocodeResponse gcResp = new GeocodeResponse();
GeocodeRequest gcr = new GeocodeRequest();
gcr.Credentials = new Credentials();
gcr.Credentials.ApplicationId = APP_ID2;
gcr.Query = Address1;
var myFunc = Observable.FromAsyncPattern<GeocodeRequest, GeocodeResponse>(gsc.BeginGeocode, gsc.EndGeocode);
gcResp = myFunc(gcr) as GeocodeResponse;
if (gcResp.Results.Count > 0 && gcResp.Results[0].Locations.Count > 0)
{
returnLocation = gcResp.Results[0].Locations[0];
}
return returnLocation as IObservable<Location>;
}
gcResp comes back as null. Any thoughts or suggestions would be greatly appreciated.
The observable source you are subscribing to is asynchronous, so you can't access the result immediately after subscribing. You need to access the result in the subscription.
Better yet, don't subscribe at all and simply compose the response:
private IObservable<Location> GetGPSCoordinates(string Address1)
{
IGeocodeService gsc =
new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
Location returnLocation = new Location();
GeocodeResponse gcResp = new GeocodeResponse();
GeocodeRequest gcr = new GeocodeRequest();
gcr.Credentials = new Credentials();
gcr.Credentials.ApplicationId = APP_ID2;
gcr.Query = Address1;
var factory = Observable.FromAsyncPattern<GeocodeRequest, GeocodeResponse>(
gsc.BeginGeocode, gsc.EndGeocode);
return factory(gcr)
.Where(response => response.Results.Count > 0 &&
response.Results[0].Locations.Count > 0)
.Select(response => response.Results[0].Locations[0]);
}
If you only need the first valid value (the location of the address is unlikely to change), then add a .Take(1) between the Where and Select.
Edit: If you want to specifically handle the address not being found, you can either return results and have the consumer deal with it or you can return an Exception and provide an OnError handler when subscribing. If you're thinking of doing the latter, you would use SelectMany:
return factory(gcr)
.SelectMany(response => (response.Results.Count > 0 &&
response.Results[0].Locations.Count > 0)
? Observable.Return(response.Results[0].Locations[0])
: Observable.Throw<Location>(new AddressNotFoundException())
);
If you expand out the type of myFunc you'll see that it is Func<GeocodeRequest, IObservable<GeocodeResponse>>.
Func<GeocodeRequest, IObservable<GeocodeResponse>> myFunc =
Observable.FromAsyncPattern<GeocodeRequest, GeocodeResponse>
(gsc.BeginGeocode, gsc.EndGeocode);
So when you call myFunc(gcr) you have an IObservable<GeocodeResponse> and not a GeocodeResponse. Your code myFunc(gcr) as GeocodeResponse returns null because the cast is invalid.
What you need to do is either get the last value of the observable or just do a subscribe. Calling .Last() will block. If you call .Subscribe(...) your response will come thru on the call back thread.
Try this:
gcResp = myFunc(gcr).Last();
Let me know how you go.
Richard (and others),
So I have the code returning the location and I have the calling code subscribing. Here is (hopefully) the final issue. When I call GetGPSCoordinates, the next statement gets executed immediately without waiting for the subscribe to finish. Here's an example in a button OnClick event handler.
Location newLoc = new Location();
GetGPSCoordinates(this.Input.Text).ObserveOnDispatcher().Subscribe(x =>
{
if (x.Results.Count > 0 && x.Results[0].Locations.Count > 0)
{
newLoc = x.Results[0].Locations[0];
Output.Text = "Latitude: " + newLoc.Latitude.ToString() +
", Longtude: " + newLoc.Longitude.ToString();
}
else
{
Output.Text = "Invalid address";
}
});
Output.Text = " Outside of subscribe --- Latitude: " + newLoc.Latitude.ToString() +
", Longtude: " + newLoc.Longitude.ToString();
The Output.Text assignment that takes place outside of Subscribe executes before the Subscribe has finished and displays zeros and then the one inside the subscribe displays the new location info.
The purpose of this process is to get location info that will then be saved in a database record and I am processing multiple addresses sequentially in a Foreach loop. I chose Rx Extensions as a solution to avoid the problem of the async callback as a coding trap. But it seems I have exchanged one trap for another.
Thoughts, comments, suggestions?