These are chat archives for fanout/pushpin

10th
May 2018
Justin Karneges
@jkarneges
May 10 2018 04:11
@wizeup if you're using JS, the publish call is async. be sure your lambda function isn't terminating before the work finishes. consider having the publish() callback call the lambda function completion callback
wizeup
@wizeup
May 10 2018 06:03
@jkarneges here is my sample code that publishes using fass-grip library.
faas_grip.publish('wizechannel',
new grip.HttpStreamFormat('event: started\ndata: ' + JSON.stringify(payload) + '\n\n'),
        null,
        null,

        callback(null, {
            statusCode: 200,
            headers: { 'Content-Type': 'text/plain' },
            body: 'Published sample data\n'
        }))
still not seeing it on my client ui
Justin Karneges
@jkarneges
May 10 2018 06:10
@wizeup I think you mean function() { callback(..) } for that last arg to publish?
wizeup
@wizeup
May 10 2018 06:11
@jkarneges Just realized that .Readjusting the code.let me test it again
wizeup
@wizeup
May 10 2018 06:25
@jkarneges no luck - Here is my publish code
var payload = {
seesionid: 2424234,
userid: 54654645,
status: 'wizeup started a livettalk session 2424234'
}
    faas_grip.publish('wizechannel',
        new grip.HttpStreamFormat('event: started\ndata: ' + JSON.stringify(payload) + '\n\n'),

        function(){

        callback(null, {
            statusCode: 200,
            headers: { 'Content-Type': 'text/plain' },
            body: "Published data to wizechannel - started"
        })
    }
);
and here is my listener /client side code
source.addEventListener('started', function (e) {
console.log(e)
console.log(e.data)
console.log('lastEventID: ' + (e.lastEventId || '--') +
', server time: ' + e.data, 'msg');
        writeToScreen('<span style="color: blue;">RESPONSE: ' + e.data +  ' Recieved at '+ new Date.now() +'</span>');

    }, false);
Justin Karneges
@jkarneges
May 10 2018 06:33
@wizeup publish() sets 3 args on the callback function (success, message, context), try checking those
function(success, message, context) {
    if (success) {
        console.log('Publish successful!');
    }
    else {
        console.log("Publish failed!");
        console.log("Message: " + message);
        console.log("Context: ");
        console.dir(context);
    }
}
wizeup
@wizeup
May 10 2018 06:38
getting success true..not getting it on client ui .

publish endpoint https://api.fanout.io/realm/******?iss=*******&key=base64:********

success true
message null
context null

Justin Karneges
@jkarneges
May 10 2018 06:38
ok that's good. what if you curl the streaming endpoint to see the raw output?
wizeup
@wizeup
May 10 2018 06:39
you mean publish using curl to the same channel/eventtype
Justin Karneges
@jkarneges
May 10 2018 06:40
I mean using curl as a client to listen for data, rather than using JS EventSource
wizeup
@wizeup
May 10 2018 06:40
not sure about that . how can i do it?
Justin Karneges
@jkarneges
May 10 2018 06:41
curl -i http://...
also is it still the case that messages get delivered if you publish locally instead of from lambda?
wizeup
@wizeup
May 10 2018 06:42
nope..now even my local publish is not reaching..so something really messed up .
Justin Karneges
@jkarneges
May 10 2018 06:43
dumb question: subscribing and publishing to the same channel?
wizeup
@wizeup
May 10 2018 06:43
not clear about how to listen using cur .Is it curl -i <mysubscription endpoint>
Justin Karneges
@jkarneges
May 10 2018 06:44
yup just pass the same url you are passing to EventSource
wizeup
@wizeup
May 10 2018 06:44
@jkarneges i think so ?. How to check my active sunscriptions
@jkarneges let me try
Justin Karneges
@jkarneges
May 10 2018 06:46
you can check current subscriptions with a call like this: curl --user {realm-id}:{realm-key} https://api.fanout.io/realm/{realm-id}/subscriptions/items/
wizeup
@wizeup
May 10 2018 06:47
@jkarneges curl getting it. as follows
event: started
data: {"seesionid":2424234,"userid":54654645,"status":"wizeup started a livettalk session 2424234"}
Justin Karneges
@jkarneges
May 10 2018 06:48
ah! good, okay. so must be an issue with eventsource. what browser?
wizeup
@wizeup
May 10 2018 06:49
@jkarneges chrome . here is my eventsource code
var source = new EventSource('https://*******.fanoutcdn.com/common/realt');
    source.addEventListener('livetalk-attending', function (e) {
        console.log(e)
        console.log(e.data)
        console.log('lastEventID: ' + (e.lastEventId || '--') +
            ', server time: ' + e.data, 'msg');

        writeToScreen('<span style="color: blue;">RESPONSE: ' + e.data +  ' Recieved at '+ new Date.now() +'</span>');


    }, false);

    source.addEventListener('livetalkAttending', function (e) {
        console.log(e)
        console.log(e.data)
        console.log('lastEventID: ' + (e.lastEventId || '--') +
            ', server time: ' + e.data, 'msg');

        writeToScreen('<span style="color: blue;">RESPONSE: ' + e.data +  ' Recieved at '+ new Date.now() +'</span>');

    }, false);

     source.addEventListener('started', function (e) {
        console.log(e)
        console.log(e.data)
        console.log('lastEventID: ' + (e.lastEventId || '--') +
            ', server time: ' + e.data, 'msg');

        writeToScreen('<span style="color: blue;">RESPONSE: ' + e.data +  ' Recieved at '+ new Date.now() +'</span>');

    }, false);


    source.addEventListener('message', function (e) {
        console.log(e)
        console.log(e.data)
        console.log('lastEventID: ' + (e.lastEventId || '--') +
            ', server time: ' + e.data, 'msg');

        writeToScreen('<span style="color: blue;">RESPONSE: ' + e.data + ' Recieved at '+ new Date.now() +'</span>');

    }, false);


    source.addEventListener('open', function (e) {
        console.log('> Connection was opened');
        writeToScreen("CONNECTED");
        //updateConnectionStatus('Connected', true);
    }, false);
    source.addEventListener('error', function (e) {

        console.log(e)
        if (e.eventPhase == 2) { //EventSource.CLOSED

            writeToScreen('<span style="color: red;">ERROR:</span> ' + e.data);
            source = new EventSource('https://*****.fanoutcdn.com/users/realt')
            console.log('> Connection was closed');

            // updateConnectionStatus('Disconnected', false);
        }
    }, false);


    function writeToScreen(message) {
        var output = document.getElementById("output");

        var pre = document.createElement("p");
        pre.style.wordWrap = "break-word";
        pre.innerHTML = message;
        output.appendChild(pre);
    }
Justin Karneges
@jkarneges
May 10 2018 06:55
hmm nothing jumping out at me. you were able to receive messages in the browser awhile back though, yeah? I think it has to be some difference between your earlier and current browser JS code
wizeup
@wizeup
May 10 2018 06:56
here is my active subscriptions..{
"items": [
{
"state": "unsubscribed",
"channel": "test"
},
{
"state": "subscribed",
"channel": "wizechannel"
}
],
"last_cursor": "MTUyNTkzNTMzM19lZGdlZGItMl8xNTI1OTM1MzI3XzBfNjc3MjY0NzQ0"
}
let me see if eventSource.onmessage = function(e) {
// Here you get an event without event name!
} works
Justin Karneges
@jkarneges
May 10 2018 06:57
yup that looks right. and fanout pub/sub seems to be working as expected
wizeup
@wizeup
May 10 2018 06:59
Interesting.. tried it on an incognito browser window..seems like the event is reaching EventSource client..
wizeup
@wizeup
May 10 2018 07:34
@jkarneges thanks a lot. I able to continue with my testing. Apparently browser turned out be a trouble maker for a day. Good old restart the computer once in a day would have solved this issue.