Skip to content

Observer functions not getting triggered #10

@navelpluisje

Description

@navelpluisje

The observers are created and the change is also called in the index.js file. Only the functions attached to the observer.change and added are never called. My client looks like this:

var DDPClient = require('ddp-client');
var ddpclient = new DDPClient({
    host : '127.0.0.1',
    port : 3000,
});

/* Connect to the Meteor Server*/
ddpclient.connect(function (error, wasReconnect) {
    if (error) {
        console.log('DDP connection error!');
        return;
    }

    if (wasReconnect) {
        console.log('Reestablishment of a connection.');
    }

    console.log('connected!');
    /* Subscribe to a Meteor Collection */
    ddpclient.subscribe('sensorvalues', [], function() {
        console.log(ddpclient.collections.sensorvalues);
    });

    /* Observe a collection */
    var observer = ddpclient.observe('sensorvalues');
    observer.added = function(id) {
        console.log("[ADDED] to " + observer.name + ":  " + id);
    };
    observer.changed = function(id, oldFields, clearedFields, newFields) {
        if (id == 0) {
            document.getElementById('date').textContent = newFields.value
        }
        if (id == 1) {
            document.getElementById('ping').textContent = newFields.value
        }
        if (id == 2) {
            document.getElementById('cpu').textContent = newFields.value
        }
        if (id == 3) {
            document.getElementById('clicks').textContent = newFields.value
        }
    };

    /* Send a remote procedure call */
    document.getElementById('addclick').addEventListener('click', function() {
        ddpclient.call('click');
    });
});

Beside this I did a check on the message event and this one was triggered.


Update about the used browsers. All on OSX 10.10.5.

  • Chrome Version 45.0.2454.99 (64-bit)
  • Chrome Version 47.0.2519.0 canary (64-bit)
  • Firefox 40.0.3 & 41.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions