Offline symfony2 application - javascript

Situation
I'm building a little chat using Symfony2. I'm wondering if there are possibilities to make the chat usable in offline mode. I'm not expecting to actively chat with connected user. I'm planning to make the user able to write message in offline mode (in the metro for instance), and then send it when connection is back again. Important: I would like to compute in the fact that connection can be gone for a long time. I remember beeing with people working in the Eurostar (Paris - London) and using their computers/phone while in a submarine tunnel for an hour or so. There was no connection at all. So in this case, how can you store a message for such a long time before sending it?
Problem
I found some interesting tutorial defining the HTML 5 offline mode. They define the capabilities of this offline mode with sending message but doesn't give example. Moreover, it seems that the only stuff we can put in the manifest are static files (css, javascript, html, pictures...)
My question is then, how do you store the written message from the user after she/he pressed the "send" button and is offline? Is it a javascript variable? Or is there html 5 features that exist?
Cheers!

You can do this via HTML5 local storage:
http://www.redrobotzoo.com/posts/html5-local-storage-and-local-databases-tutorial/
This example has very nice examples so it should not be a problem for you to make it work.

Related

How to manupulate external Javascript processing

We are creating a simulator to test our new system. The simulator will be used for performance testing using varying payloads. But we are stuck while trying to create multi-user scenario due to an embedded functionality of our new system. Given below is the workflow of the new system under question:
User logs in the system
When page is loaded, a hidden iFrame is rendered with url to User Authentication Service via HTTP Post
User Authentication Service executes a javascipt in the user browser and gets the following - (A) User ID, (B) IP Address, (C) Browser details
User is authenticated and next page is loaded
The javascript mentioned above is maintained by external group and we don’t have access to it (don’t have the source code yet but we may get it).
Our Scenario: We have to simulate multi user condition for varying pay load. We have created a simulator for this purpose. We want to simulate for different concurrent users connecting from different machines (different IP, browser). Since we are talking about simulated condition, the simulator is expected to generate it from the server machine only.
Challenge: How wan we suppress the execution of the javascript mentioned in the Step#3 above? Is it possible at all? What do we need to know from the external group regarding the javascript to achive it? Will it help, if we have the source code of the javascript?
Please refer to the image for the scenario mentioned here. Any help is appreciated:

Auto updating text clipboard on two different machines connected to the same network?

I want to make a simple webapp on my macbook where I launch a page, and basically its just a massive full page clipboard. I paste my code in, and if I have that same page open on another machine (my windows XP machine), I want that code to auto update in that window.
This is so I can transfer code to and from my machine without having to use my USB key.
Where should I get started with this? I'm not asking for any code, just a push in the right direction, not entirely sure what I should be googling. If this is in the wrong site please move it.
Thanks.
essentially, what you want is like a chat program.
oldschool solution is that wep page polls server at regular intervals. Server needs to persist the data somehow, in order to provide it to the client during the next http request.
A new approach is to use html5 web sockets. Since this allows server to 'push' data to client as soon as its received, nothing needs to be persisted.
http://www.html5rocks.com/en/tutorials/websockets/basics/

How would I save form fields offline if connection drops?

I have a backend where people may take some time filling out the form. The form is written to a temporary table every 5 minutes to store the data. The problem I have is that some peoples internet connections are not strong, so they drop at times without the person knowing and when they go to submit, the form can't because of loss of connection. Every 5 minutes I was going to add if the ajax fails, then prompt the user, but I want to go further and possible allow them to store the data offline and then reconnect to submit it.
The problem is, how would I start storing the data to a file on their local machine? As far as I know, client side scripting can't create files and we couldn't use ajax to call a remote file that saves to a local file. I suppose I could prompt to save the file at the beginning locally, but the local machine still would need to support the language. We are using JSP with MySQL.
Does anyone know of how I would accomplish saving data offline when a connection drops?
Implementing offline capabilities can become a tough exercise. Your question is too broad to provide a final answer, but you should have a look at HTML5 capabilities, an overview is available here. Using this feature requires your users to use a modern browser version. You have to think of synchronization/replication as well.
If the connection only drops for a limited amount of time, it may be enough to just use a rich-client and store the data in memory using JavaScript.
Something like this should do the work :
First way:
Use HTML5 localStorage/session storage, or something like Gear to
save the data on the client side
Make an ajax loop to ping the connection, idealy the server should be configured to reply with a http code 100 (I presume)
Send the data when the connection is on
Second way:
Use HTML5 offline capability or a substitue (see modernizr and polyfill)

See and talk to your currently online users on your site in a Ruby on Rails 3 application

I have a Ruby on Rails 3 application, and I want to be able to see a list of who is currently online. For example user1, IP address, and country. I then want to be able to open a chat / push messages to this user until they leave my site.
How can I accurately monitor who is currently on the site and instantly remove the user from the list when they leave?
I then can talk to them via faye pub/sub.
How can I accurately monitor who is currently on the site and instantly remove from list when they leave?
Well using HTTP you can not do this "instantly" in a browser. Almost all solutions I see use a heartbeat technique. Every X seconds, a request is sent from the browser (using Ajax), that tells if the user is online. If you haven't heard from the user in x heartbeats, you regard the user as disconnected - even Facebook uses this, it seems. I will recommend you to drop your requirement for instant, unless it's really important.
Another approach is to implement Flash or Silverlight, to make a socket connection to the server. But the demand on the server is high, and if many people is on your site, you will run into trouble with ports and so on.
I think this is not so much related with Ruby on Rails... but this is very hard to implement in HTTP with a scripting language only. The server does not know whether a user has closed the browser or not. The server just sends the requested page data to the user and closes the connection.
You would rather have to integrate Ajax or Flash to make things easier. I have seen some people developing chat programs with Flash, and it seems to work much better than any other Ajax-implemented chat programs.
Chat is very unfavorable in a web browsing context, since the page will be reloaded as the user clicks a link. If you are thinking about building an application that only supports a chat feature, you probably want to look something other than Ruby on Rails. For example, Node.js will be a good one.

Implementing web chat, how do I get typing status?

Can someone illustrate how I can get typing status of the other party with JavaScript?
UPDATE
Can someone recommend a one-to-one open source chatting application, preferably written in PHP? I only found open source chatting rooms which are for chatting among all onliners, but I just need a one-to-one chatting.
Here are a list of PHP-based open-source instant messaging software.
Some of those might be relevant for you.
For example, if you had an text area #chat then you could use this code to attach the event:
document.getElementById('chat').addEventListener('keydown', FUNCTION HERE, false);
See http streaming and some ready solutions here: http://ajaxpatterns.org/HTTP_Streaming
this is how google talk does it. And there are ready php or c++ solutions
It was quie a discovery for me!
This is an update to reflect the significant change in the OP's question:
Google Chat and Facebook both use XMPP(jabber) servers, as do most companies I know of that have internal instant messaging.
The nice part about XMPP is that you get all of the "is typing" and other presence-based information without having to roll-your-own in javascript (bear in mind, you will still need to use javascript to pass XMPP requests back to the server, but XMPP has most of the features you'd need already built in).
Check out OpenFire. It's a great XMPP server, totally open source, and they have a web-based version of their Spark client that is pretty nice.
Or you could get a PHP library for XMPP (there are a few). But you'd still need to have the XMPP server running in the background for PHP to work with.
Here's a list of XMPP libraries for PHP from XMPP.org:
Eiffel
JAXL
Lightr
Missus
xmpphp
Or, if you want to keep things mostly browser-side, they also have a list of libraries for javascript:
dojox.xmpp
js.io
JSJaC
strophe.js
xmpp4gwt
xmpp4js
I made a small chat application a while ago, and the only way to do it is to frequently check for new entries in the chat database and fetch anything newer than the last displayed message. At the same time as all that, you can check to see if the user's input is empty. If it is, do nothing. If it isn't, enter a status code into the database beside that user's name. If anyone has that status in the database when you're fetching information about new messages and who is online, you should display the 'user is typing' message. I hope that makes sense...let me know if it isn't.
For User1: If you save the chat message on each key-press to the database, with a status: sent=false and update the last updated date.
For User2: you could pole periodically for the presence of a message where sent=false and use the last updated to update user is typing message. if the lastupdated date is more than a say ten seconds you could remove the message as that person may have stopped typing. This will allow User2 to see User1 typing, stopping and continueing again.
Ideally polling for this information will be part of an existing call to the database to reduce additional overhead.

Categories

Resources