Django. Websockets. Replace repalce part websocket URL - javascript

I have page with chat. There is list which consist of started dialogues and current dialog.
Example
Current dialog work by using webscoket connection and Django channels.
I want then when click then jump in other dialog without refresh page. At the same time, URL changes, but websocket connection not changes - it is problem.
How change websocket connetion?
Example: .../chat/Joseph change to .../chat/Tyler
If this can be implemented in some other way, I will be glad to have a couple of words. Thank you!

Related

Updating ruby on rails app with jQuery every time there is a change

I Want to make an app with ruby on rails and Jquery that will allow multiple users to have the same page open at the same time, and if any of them makes a change to the page, adds a post, or deletes a post it will show all other users that change without having to reload the page.
Here in stack-overflow, whenever another user comes and gives me a point or removes a point on the post, it will show me without having to refresh the page.
Same with the comments, if someone posts, I will see it without having to refresh.
Can anyone tell me here to get started with this?
I would rather not have to have the page reload every 30 seconds.
Any help would be appreciated.
Thank you in advance.
There are a few ways to go about this:
Websockets
Server Sent Events via ActionController::Live (Rails 4+)
Long Polling (outdated method at this point)
Between websockets and SSE I would go with the former. Higher browser compatibility and the more mature technology of the two. If you're willing to pay for convenience, check our Pusher (solid free tier). Otherwise you might want to check out something like Faye (good intro at http://railscasts.com/episodes/260-messaging-with-faye).

How do I code facebook-like browser notifications using AppEngine Channel API?

I am writing a Python AppEngine app, and need to deliver notifications to browser clients when certain backend events happen. I am using the channel API. I have two issues: multiple page loads within the same tabs and multiple tabs.
Multiple Page Loads
I seem to be unable to reuse the same channel across multiple page loads. An attempt to reconnect to the channel on the new page results in an error with code 0 and no description. I am currently storing the channel token in the datastore and injecting the token into the page. How can I reuse the same channel for multiple page loads within the same tab? This answer suggests iframes are the way. Is recoding the site with iframe my best option here?
Tabs
My understanding is that I need to generate a client ID for each tab the user opens. How should I generate a client ID that will be different for each opened tab? I could just increment an ID on the server, is that the best way?
Thanks in advance,
Aaron
I have been investigating strange channel disconnections in DEV, and it looks like Channel API is much more stable in the live environment than in the development environment.
I created a (somewhat) minimal AppEngine application that creates a channel that persists across page loads. The app reuses a channel token from the datastore.
The code for the app is here: https://github.com/aaronlifshin/channeltest
The app itself is live at http://channeltestaaron.appspot.com/
How to use it?
When you go to http://channeltestaaron.appspot.com/ANYSTRING the app will create a channel and then reuse this channel for any other URLs you open of the form http://channeltestaaron.appspot.com/ANYTHING
Then you can go to http://channeltestaaron.appspot.com/broadcast to cause a message to be sent to all the other pages you've opened.
All pages have a 1-second delay to test the persistence of the channel. This 1-second delay would cause the channel to disappear in dev.
Hope this is helpful.
Aaron
Multiple page loads: according to the answer here you can reuse the token, however need to make sure to use it on one page at a time (it might also be a good idea to avoid page reloads and to have a single-page app that uses hash fragments).
Tabs: the most straightforward way to generate client ID is create a random string, e.g. like this.

div popup when there is new updates available

I've implemented RSS Feed for my application . But , I want that there should be a new updates like Facebook new notification arrives while you are logging on, I mean it depends on user he/she want to see that notification or not.
So , I just want that kind of div appearance . Is there any plugin for that in javascript/jquery?
What you are looking for is called long polling.
Basically, your client javascript requests the update from the server, but the server keeps the connection open and answers not until update data is available.
This is the most gentle way of doing this, but the implementation depends on your server side framework/language.
See this link for a good introdcution: http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery
The other option you have is setting a timer in javascript and poll every once in a while the server for updates.

Running a jquery mobile web app in a disconnected state?

I've been toying with writing a web app using jquery mobile which makes use of forms (cehckboxes, text fields, combo boxes). The tasks the app requires are fairly trivial but the information needs to be updated and sent to a server.
So my question is, say someone uses the app, gets a bunch of data from a server, then loses connection. Will the browser still remember the form fields input and could the user still navigate between pages? From my understanding jquery mobile places all its pages in the same 'webpage' so it's not like it will have to be constantly loading up new data from the server.
My idea is that I'll run some script in the background to check for a connection to a server and when it gets this connection it can go ahead and sync data with the server.
Is this possible or is it a pipe dream?
for jquery mobile it append all the data it had in same page so user can use only those links which are already clicked for the links that user have not touch yet will create problem

GMail like try-again behaviour for my website

Disclaimer: I am living at some place where my net connection gets cut off at least ten times a day. I am not sure if my question makes much sense to guys with stable connection.
Question: Suppose that I am checking GMail when the connection gets cut off. Then, if I unknowingly press my Inbox link, instead of a browser specific error page, I just get a warning div displayed at the top of my page like, "Unable to Connect. Please try in ___ seconds / minutes".
How can I replicate this feature in my web app?
This happens because Gmail uses AJAX requests instead of hyperlinks to new pages.
When you make an AJAX request, you can add an error handler that does whatever you want.
It is impossible to add error handling to normal page navigation.
When you press the link to inbox, you start an ajax request (easy to do using jQuery).
It it succeed, then insert the content and change the url.
If it fails, give the user an error.
Remeber to use a plugin like jQuery BBQ to make back/forward buttons work.

Categories

Resources