loopback-example-angular-live-set icon indicating copy to clipboard operation
loopback-example-angular-live-set copied to clipboard

Can't make it work

Open stellanhaglund opened this issue 11 years ago • 14 comments

Hi, I know this is probably not the kind of issue you want over here but I don't know where else to ask it.

I have followed the guide in the readme several times but it seems there is something missing because I can make the finished examples to work but not by installing just the minimum from scratch.

I have installed strongloop globally and the documentation states it now includes loopback angular sdk and that angular loopback sdk supersedes angular loopback which I guess is the same as this "gulp-loopback-angular (the Grunt version would work as well)"?

I'm able to create content but it's only shown when I update the page..

The only thing I can give you that I noticed, is that change-stream says pending for about two minutes in the network tab of the console then says (failed)

skarmavbild 2015-08-28 kl 17 27 19

And aslo that when I try the change-stream endpoint in the explorer I get some response data about readable: true, and writeable: false on the example files but it's empty on my own setup..

I understand this can by a combination of many things, so If it would be possible to just set up a very basic example without the whole grunt and gulp parts just so that I can see exactly what is required or maybe a short updated list of tools.

I'm really hoping on this! :)

stellanhaglund avatar Aug 28 '15 15:08 stellanhaglund

I'm having the same issue! I've spent the whole day trying to get it to work but it just won't... :(

I actually modified the loopback-example-angular todo list example with the hope that I could get it to use the change stream to update the todo list as a starting point for a project.

My todo controller has the following:

var source = new EventSource('/api/todos/change-stream?_format=event-source');
var changes = createChangeStream(source);
var set;

Todo.find().$promise.then(function(results) {
  set = new LiveSet(results, changes);
  $scope.todos = set.toLiveArray();
});

Of course I also installed all the needed dependencies so I don't get any errors. There is just simply no events displayed in the EventStream in Chrome when making changed like adding or removing todo items.

I've checked everything a thousand times and I can't find anything that's missing, please help!

EmileSpecs avatar Sep 14 '15 20:09 EmileSpecs

@ritch ^

/cc @crandmck Probably needs a doc update too.

superkhau avatar Sep 14 '15 21:09 superkhau

@ritch: Any help you could provide on this?

I've just not used it and went on with the rest of my app design but now it's time to start looking at this again and I've quickly spent an hour on it and still no luck.

I really don't know what to do to make this work... It does seem to work on the server side. I added a mixin and attached it to two models to see if it works and I do get console output that I'd expect to also see client side.

/mixins/realtime.js

var eventStream = require('event-stream');

module.exports = function(Model, options) {
    Model.createChangeStream(function(err, changes) {
        changes.pipe(eventStream.stringify()).pipe(process.stdout);
    });
}

So obviously loopback is emitting these change events, the client just isn't getting it!

Client side I've used:

var src = new EventSource('/api/Tasks/change-stream?access_token='+ LoopBackAuth.accessTokenId);
            var changes = createChangeStream(src);
            changes.on('data', function(msg) {
                var data = JSON.parse(msg.data);
                console.log(data); // the change object
            });

I've also tried:

Task.createChangeStream().$promise.then(function(err, changes) {
                changes.on('data', function(msg) {
                var data = JSON.parse(msg.data);
                console.log(data); // the change object
            });
            });

Not sure if that's correct, since the promise never seems to complete and call the then callback function.

Either way, in both cases I do get a successful http request to the change stream end point. Looking in the EventSource tab in Chrome as well as the console, I never get any events.

Please help!

EmileSpecs avatar Oct 13 '15 13:10 EmileSpecs

Okay, so I found the solution to making the example work.

Disable compression middleware in loopback!

So this works:

var src = new EventSource('/api/Tasks/change-stream?access_token='+ LoopBackAuth.accessTokenId);

This however doesn't work:

Task.createChangeStream();

It does make a successful call to /api/Tasks/change-stream but it doesn't seem like there's any code using EventSource in the Angular services created by lb-ng I use to generate the services used with loopback.

Is there any thoughts on why this doesn't seem to do anything usable?

EmileSpecs avatar Oct 13 '15 16:10 EmileSpecs

Sorry no one has responded to this. The docs do say to disable compression. See https://docs.strongloop.com/display/LB/Realtime+server-sent+events#Realtimeserver-sentevents-Disablecompression. I'm going to add something to the README here, as well.

crandmck avatar Oct 13 '15 20:10 crandmck

Thanks @crandmck, pretty sure it wasn't in there on 14 September when I first encountered the issue, could be wrong.

Any thoughts however on why the lb-ng service's Task.createChangeStream(); doesn't actually seem to create any EventSource but seems to just make a GET/POST call to the API endpoint?

EmileSpecs avatar Oct 14 '15 19:10 EmileSpecs

@bajtos ^^ ?

crandmck avatar Oct 14 '15 20:10 crandmck

The code generator does not support the change-stream feature yet. Let's keep track of that feature request here: https://github.com/strongloop/loopback-sdk-angular/issues/183

bajtos avatar Oct 15 '15 06:10 bajtos

@bajtos okay thanks!

EmileSpecs avatar Oct 15 '15 07:10 EmileSpecs

@EmileSpecs Give the above, I'll close this. If you have further doc suggestions, please let me know.

crandmck avatar Oct 15 '15 17:10 crandmck

Go in middleware.json and set this:

"compression": { "enabled":false },

fcasarsa avatar Oct 30 '15 16:10 fcasarsa

could you please add this to the readme.

gshireesh avatar Dec 08 '15 20:12 gshireesh

Added to https://github.com/strongloop/angular-live-set-example/blob/master/README.md#run-the-examples.

crandmck avatar Dec 11 '15 23:12 crandmck

thank you

gshireesh avatar Dec 12 '15 15:12 gshireesh