Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

fix startActivity #9

Merged
merged 3 commits into from
Sep 21, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 deletions lib/harmonyclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,25 @@ function getActivities() {
* @param activityId
* @returns {Q.Promise}
*/
function startActivity(activityId) {
debug('start activity ' + activityId);

var timestamp = new Date().getTime()
, body = 'activityId=' + activityId + ':timestamp=' + timestamp;

return this.request('startactivity', body, 'encoded', function(stanza) {
// This canHandleStanzaFn waits for a stanza that confirms starting the activity.
// It looks something like this:
//
// <message from="HarmonyOne_Pop@qa1.com" to="ab903454-7bee-4410-9eea-bb5355bb667e">
// <event xmlns="connect.logitech.com" type="harmony.engine?startActivityFinished"><![CDATA[activityId=7596992:errorCode=200:errorString=OK]]></event>
// </message>
var event = stanza.getChild('event')
, canHandleStanza = false;

if(event && event.attr('type') === 'harmony.engine?startActivityFinished') {
var decodedResponse = xmppUtil.decodeColonSeparatedResponse(event.getText());

if(decodedResponse.activityId === activityId) {
debug('got notification that activity ' + activityId + ' started successfully');
canHandleStanza = true;
}
}

return canHandleStanza;
});
}
function startActivity(activityId) {
var timestamp_temp = Date.now() - timestamp;
var body = 'activityId=' + activityId + ':timestamp=' + timestamp_temp;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this timestamp calculation about?


return this.request('startactivity', body, 'encoded', function(stanza) {
// This canHandleStanzaFn waits for a stanza that confirms starting the activity.
var event = stanza.getChild('event')
, canHandleStanza = false;
if(event && event.attr('type') === 'connect.stateDigest?notify') {
var digest = JSON.parse(event.getText());
if (activityId === '-1' && digest.activityId === activityId && digest.activityStatus == 0){
canHandleStanza = true;
}else if(activityId !== '-1' && digest.activityId === activityId && digest.activityStatus == 2) {
canHandleStanza = true;
}
}
return canHandleStanza;
});
};

/**
* Turns the currently running activity off. This is implemented by "starting" an imaginary activity with the id -1.
Expand Down