swissmanu / harmonyhubjs-client

A Node.JS library which allows you to interact with your Logitech Harmony Hub.
https://github.com/swissmanu/harmonyhubjs-client
MIT License
155 stars 42 forks source link

startActivity never gets resolved #7

Closed Pmant closed 9 years ago

Pmant commented 9 years ago

If the activity is already started the function will never return because the hub will not send startActivityFinished . I was able to fix it with this function:

function startActivity(activityId) {
    var timestamp_temp = Date.now() - timestamp;
    var body = 'activityId=' + activityId + ':timestamp=' + timestamp_temp;

    return this.request('startactivity', body, 'encoded', function(stanza) {
        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;
    });
};
swissmanu commented 9 years ago

thanks for your investigation. this looks quite obvious actually :-| would you like to fill in a pull request with your addition?