These are chat archives for fanout/pushpin

21st
Apr 2018
wizeup
@wizeup
Apr 21 2018 04:30
A justin Jag here
Justin Karneges
@jkarneges
Apr 21 2018 04:42
@wizeup hi there!
wizeup
@wizeup
Apr 21 2018 04:44
Hey thanks for the update on sse stream config through the email.I am still not quite successful in making collect the event on my html test page
My lambda function is successfully responding [200] {"statusCode":200,"headers":{"Content-Type":"text/event-stream","Cache-Control":"no-cache","Grip-Hold":"stream","Grip-Channel":"test","Grip-Keep-Alive":":\n\n; format=cstring; timeout=20"},"body":"stream opened, prepare yourself!\n"}
where as my EventSource page fails with - Failed to load https://27a38560.fanoutcdn.com/realt: The 'Access-Control-Allow-Origin' header has a value 'null' that is not equal to the supplied origin. Origin 'null' is therefore not allowed access.
Justin Karneges
@jkarneges
Apr 21 2018 04:49
"/realt" is the path? or is that truncated
okay for me to make test requests to your configured origin server?
wizeup
@wizeup
Apr 21 2018 04:52
i have 2 paths now 1)https://c44bdbc4.ngrok.io/realt -- this will open up a new channel (subscribe)
2) https://c44bdbc4.ngrok.io/realtp -- publishes a test message into 'test' channel
i separated subscribe & publish into 2 separate endpoints to avoid race condition possibilities
Justin Karneges
@jkarneges
Apr 21 2018 04:54
on /realt, set response body to a blank string
(that "stream opened" string isn't proper SSE format)
wizeup
@wizeup
Apr 21 2018 04:55
done - [200] {"statusCode":200,"headers":{"Content-Type":"text/event-stream","Cache-Control":"no-cache","Grip-Hold":"stream","Grip-Channel":"test","Grip-Keep-Alive":":\n\n; format=cstring; timeout=20"},"body":""}
BTW where can i find more about SSE format..i am not quite clear what a SSE stream is
wizeup
@wizeup
Apr 21 2018 04:57
@jkarneges - yes totally ok to make test request as well as make use any one of these endpoints
Justin Karneges
@jkarneges
Apr 21 2018 04:57
essentially it's payloads separated by double newlines
wizeup
@wizeup
Apr 21 2018 04:57
this is a test/dev set up
Justin Karneges
@jkarneges
Apr 21 2018 04:58
client side looks good now
published data not showing up though. what data are you publishing? and is it to the "test" channel?
wizeup
@wizeup
Apr 21 2018 04:58
hmm token expired..let me recreate the token
seems like published message ('test' channel) comes to SSE test browser window on the fanout console.
Not to my test client page though
@jkarneges Test data that i am publishing ' Hello Jag Here. Ta da '
here is the POST that i am trying - request.post({
headers: {
'content-type': 'application/json',
        'Authorization': 'Bearer ' + token
    },
    url: 'http://api.fanout.io/realm/27a38560/publish/',
    body: JSON.stringify({
        'items': [
            {
                'channel': 'test',
                'formats': {
                    'http-stream': {
                        'content': 'event: message\ndata: Hello Jag Here. Ta da \n\n'
                    }
                }
            }
        ]
    })
Justin Karneges
@jkarneges
Apr 21 2018 05:03
one possibility is the lambda function is quitting before the publish gets a chance to finish
make sure you don't call the function's callback() until the request.post() emits its callback
wizeup
@wizeup
Apr 21 2018 05:04
If that is the case why is it coming the sse test window on the console ?
Justin Karneges
@jkarneges
Apr 21 2018 05:04
the published data is showing up on the test page?
wizeup
@wizeup
Apr 21 2018 05:05
@jkarneges yes
Justin Karneges
@jkarneges
Apr 21 2018 05:05
ah yes, I see it now
wizeup
@wizeup
Apr 21 2018 05:06
here is my test client page, where it is not appearing..

<!DOCTYPE html>

<html>

<head>
<meta charset="utf-8" />
</head>

<body>
<script>
var source = new EventSource('https://27a38560.fanoutcdn.com/realt');
source.onmessage = function (e) {
console.log(e)
document.body.innerHTML += e.data + '<br>';
};

source.addEventListener('message', function (e) {
// if (e.origin != 'http://localhost:8000') {
// alert('Origin was not http://localhost:8000');
// return;
// }
console.log(e)
console.log('lastEventID: ' + (e.lastEventId || '--') +
', server time: ' + e.data, 'msg');
}, false);
source.addEventListener('open', function (e) {
console.log('> Connection was opened');
//updateConnectionStatus('Connected', true);
}, false);
source.addEventListener('error', function (e) {
if (e.eventPhase == 2) { //EventSource.CLOSED
console.log('> Connection was closed');
// updateConnectionStatus('Disconnected', false);
}
}, false);
</script>
</body>

</html>

Justin Karneges
@jkarneges
Apr 21 2018 05:08
test page is working for me
did you refresh it after fixing the endpoint?
wizeup
@wizeup
Apr 21 2018 05:09
Interesting.. it is failing with some kind of CORS error to me. Failed to load https://27a38560.fanoutcdn.com/realt: The 'Access-Control-Allow-Origin' header has a value 'null' that is not equal to the supplied origin. Origin 'null' is therefore not allowed access.
BTW i am not serving the test page from any server.. saved it as a file and opened it on my chrome browser
tried on a incognito widow- same error
Justin Karneges
@jkarneges
Apr 21 2018 05:11
hmm I'm not sure how the file: scheme plays with CORS. i'm serving the test page from a local webserver
wizeup
@wizeup
Apr 21 2018 05:11
did you try my test page or you have a different one
Justin Karneges
@jkarneges
Apr 21 2018 05:11
yours
wizeup
@wizeup
Apr 21 2018 05:12
@jkarneges ..May be that is the reason..let me try it from a local server and see if that makes the difference
wizeup
@wizeup
Apr 21 2018 05:17
Heyyyyyyy.. I served my page from a webserver..and magic happens now. I can see the published message on my test page
Justin Karneges
@jkarneges
Apr 21 2018 05:17
you have me curious about this file scheme and CORS now. for me, it works from a file in firefox but not from a file in chrome
excellent!
wizeup
@wizeup
Apr 21 2018 05:18
How can send a json payload in my publish ..other-words do i need to do specially handle json payload to serve as ssE stream..or it is just json.stringify
Justin Karneges
@jkarneges
Apr 21 2018 05:19
just stringify yup
wizeup
@wizeup
Apr 21 2018 05:24
just stringify yup - thanks that works as welll.
now the next question - what is the time out here 'Grip-Keep-Alive': ':\n\n; format=cstring; timeout=20'
is it the client connection timeout ..something that i need to keep long enough for my requirement
Justin Karneges
@jkarneges
Apr 21 2018 05:27
what that's doing is telling fanout cloud to send a keep alive packet after 20 seconds of inactivity. basically ensures the connection doesn't get timed out by routers or the browser
wizeup
@wizeup
Apr 21 2018 05:29
ok..now i changed the request module to fass-grip..
here is my publish code.. unfortunately this is not reaching my client again
Justin Karneges
@jkarneges
Apr 21 2018 05:30
'event: message\ndata: ' + JSON.stringify(payload) + '\n\n'
btw I deleted your message since it had a secret in it
wizeup
@wizeup
Apr 21 2018 05:32
'event: message\ndata: ' + JSON.stringify(payload) + '\n\n' - You rock.. that works.. Does the message in evet:message is the event name ? .Something i can customize to my own name
@jkarneges - thank you.. anyway i am going to regenerate all security key after this test.
Justin Karneges
@jkarneges
Apr 21 2018 05:33
yep you can use other event names, and have different handlers set with addEventListener
wizeup
@wizeup
Apr 21 2018 05:34
yep you can use other event names, and have different handlers set with addEventListener- we are going to use this is our iOS swift 4. Hope there is a library/pod available to listen to EventSource events
is there a option to attach jwt token instead of realm-key onto faas-grip publish method
Justin Karneges
@jkarneges
Apr 21 2018 05:36
https://github.com/inaka/EventSource works very similar to JS API
wizeup
@wizeup
Apr 21 2018 05:37
https://github.com/inaka/EventSource works very similar to JS API - var eventSource: EventSource = EventSource(url: server, headers: ["Authorization" : basicAuthAuthorization])
i believe the authn - in the above call is real-id/realm-key - base64 encoded
Justin Karneges
@jkarneges
Apr 21 2018 05:38
faas-grip (and all of our publishing libraries) make tokens from the realm and key. not possible to work just from a token
wizeup
@wizeup
Apr 21 2018 05:38
@jkarneges ok
Justin Karneges
@jkarneges
Apr 21 2018 05:39
client side auth is whatever you want. your lambda function validates the client request
realm and key only needed for publishing on server side
wizeup
@wizeup
Apr 21 2018 05:40
client side auth is whatever you want. your lambda function validates the client request ...ok.. so to connect (subscribe into a channel through the proxy) we don't need any auth..any authn need to be further validated inside our service. It make sense and good or our use case as well.
thanks a lot Justin.. i think i am clear now to propose a realtime data push solution based upon fanout/pushpin. Will share my exp/issues if any here as we make some progress.
Justin Karneges
@jkarneges
Apr 21 2018 05:43
no problem. good luck on the project :)
wizeup
@wizeup
Apr 21 2018 05:43
no problem. good luck on the project :) thank you.