These are chat archives for fanout/pushpin

13th
Jul 2018
ayurveda
@ayurved_twitter
Jul 13 2018 08:21
Thanks @jkarneges
ayurveda
@ayurved_twitter
Jul 13 2018 08:26
On the client side, when I use the PHP for client side it doesnt return the response, i.e.
<?php

header('Content-Type: text/plain');
header('Grip-Hold: stream');
header('Grip-Channel: mychannel');

?>
Stream opened, prepare yourself!
When I check the same in the terminal using curl, it shows the response, but not in the browser, should there be a html with some javascript to return the response?
ayurveda
@ayurved_twitter
Jul 13 2018 11:38
I am unable to get any response.. is this the right way to implement the front visiting facing html?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
    <script src="eventsource.min.js"></script>

</head>

<body>
    <script>
        var es = new EventSource('subscribe.php');
es.addEventListener('test', function (event) {
    console.log(event.data);
}, true);
    </script>
</body>
</html>
akash
@tHeMaskedMan981_gitlab
Jul 13 2018 12:39
@jkarneges can u please answer the question. I am trying to use the test backend. i changed my route file to * test and then used the following curl command : curl http://localhost:7999/stream. the moment i do this, i get No route for host: localhost as the response. where am i missing?
akash
@tHeMaskedMan981_gitlab
Jul 13 2018 12:46
actually I am trying to build a chat application using django event stream and pushpin. while working on localhost, i used the route as localhost:8000, and now my all the requests, rest apis, and event streams work fine through pushpin. ie, all the requests i used to make with localhost:8000/api/chat/... also work with localhost:7999/api/chat... Now what i want is use pushpin as a proxy server for my production, where i have set up my backend django server on an ec2 instance, and installed and running pushpin on another ec2 instance. Now I changed the route file on that server to address of backend server:8000. what i expect is if i make a request to pushpin_server_address:7999, it should forward the request to backend_server:8000 but i get Connection refused as the response. can u help me out on this
ayurveda
@ayurved_twitter
Jul 13 2018 13:58
@tHeMaskedMan981_gitlab have you tried changing the route to localhost:8080 ?
akash
@tHeMaskedMan981_gitlab
Jul 13 2018 17:13
@ayurved_twitter route of where? localhost on my machine or ec2? also, what difference does it make?
and any idea why the test example is not working?
Justin Karneges
@jkarneges
Jul 13 2018 17:48
@picarsite are you calling expressGrip.configure() anywhere?
@tHeMaskedMan981_gitlab how are you running pushpin? if you run with --route it might conflict with the routes file
@ayurved_twitter EventSource expects the response content to be text/event-stream, which is specially formatted text, not arbitrary plaintext
Justin Karneges
@jkarneges
Jul 13 2018 17:54
@tHeMaskedMan981_gitlab if you netstat -tln on the pushpin ec2 instance, do you see port 7999 being listened on?
ayurveda
@ayurved_twitter
Jul 13 2018 18:12
@jkarneges basically what I am looking for is, send a json data to the client only when it happens, so I guess event-stream is not good idea.. and if we use text/plain OR application/json... is there any sample html/javascript code for frontend to get, process/show the published response in the browser? Sorry.. but I am not experienced with websockets / server side stuff
ayurveda
@ayurved_twitter
Jul 13 2018 18:42
How can we "subscribe" to a channel from HTML? and then show the "Published" data on HTML
Justin Karneges
@jkarneges
Jul 13 2018 22:08
@ayurved_twitter text/event-stream is great for sending to the client. the format is not very complicated
event: test
data: Stream opened, prepare yourself!
if you return that data in the body, with an extra newline at the end, then your javascript callback should get invoked
actual chars (with newlines escaped) would look like this: event: test\ndata: Stream opened, prepare yourself!\n\n
Justin Karneges
@jkarneges
Jul 13 2018 22:16
this is known as the server-sent events protocol, or "SSE". essentially, the server returns an HTTP response using text/event-stream content type, and the response body is trickled out whenever data needs to be sent to the client. the EventSource JavaScript API makes consuming this type of HTTP endpoint very easy