WebRTC sending string messages - javascript

I want to realize a simple application in HTML/Javascript.
There should be two pages:
page1.html and page2.html. page1 should have a text box and a button. When pressing the button it should just be sent to page2, which has to display it.
I have found this example and hosted :
http://bobvann.noip.me/temp/chatp2p/
(this works with a websocket which connects to a ruby program running on that same server.
Please let me have a simple solution how to send text messages from a page to an other. Just this.
Thank you very much.
Have a good day :)

So assuming you know how to set up WebRTC for audio and video, the answer is quite short. You need to use a WebRTC data channel over a similar "peer connection" that is used for audio and video. Here is a decent example that shows how to send strings. You should be able to use it for sending structured messages in JSON, major browsers have JSON.parse that deals with conversion to objects.
But you probably want to know how it works in a bit more detail than a working non-configurable example, even if it solves your problem. Some up-to-date explaination about what it is and how to use it can be found in this article on HTML5 Rocks. The nature of your task implies using a reliable mode — you don't want your messages have a chance of not arriving or arriving disordered, right? The rest is up to you.
Regardless, I strongly recommend that you watch and understand this presentation about WebRTC at Google I/O that show pretty much everything WebRTC is designed for.

Javascript and PHP connected through AJAX is far from enough to achieve a chat.
Each side you need:
a DIV to display the conversation.
Followed:
an INPUT to enter message.
a BUTTON to send your message, using an Ajax function
that send string.
A PHP function to append the message field at the end of a chat sequential text file, display back chat list in the DIV.
Trick if you send an empty message, jump append, it will display your counterpart messages had sent while.
Empty message can trigger BUTTON after 5 sec delay repeatedly.

Related

Trying to create script that first sends an email notification, and then selects random link

First of all, thanks in advance for considering my question.
I'm pretty new to html/js, so I was wondering if it would be possible to get help on making a button on my website that completes the following:
Opens a random link from a list of links in a new tab
Sends an email notification to me that the button has been clicked, without any window popping up on the client's side (and maybe tells me what link has been used)
And looks pretty :)
I'm using Weebly to put most of my website together, so it might be difficult to use some of the server side commands or other things like that. I do believe I have the option to use php, html, javascript, and anything else that I can embed onto an html file.
Anyways, thanks!
You cannot send an email from the computer that hosts the client/browser without the user knowing. That would open a huge security hole!!!!
Perhaps you should considered sending the email from the server side when the page (the target of the random link) is rendered.

php: pushing new data on server-side event

Web development being completely new to me, this may be easy to find online but I might lack the technical jargon in this area...
I need to display some data on a linux-device that also runs a webserver, so I figured the easiest way would probably be to do this in a browser. The data might change due to (physical) interaction with the device: it has external push-buttons attached. I need the data on the webpage to change instantly when a button is pressed, so that the user sees the values change immediately when he presses a button.
This might be complete and utter nonsense, but is it possible to have the program that watches for button-presses pipe its output somewhere and have a piece of php respond to this?
A sub-optimal solution would be to have a piece of client-side javascript with a timer that periodically "calls" (?) a piece of php. I don't like this solution because you either reload ad nauseam to minimize delays, or you'll notice lag in the response to the button-presses.
You can use socket programming. Usually used in chat servers to send data to client without refreshing.
http://php.net/manual/en/sockets.examples.php
This should help
In this question the p asker tries to do the same u are trying, push data on some external event
Python Socket Programming - need to do something while listening for connections

How to show alert with sound on Website by sending some data/flag from Android app

I am working on app in which I am having one button named as Help, on click of this button I would like to send some notification to the website page, where user will get alert with sound. I am android developer and having very basic knowledge in PHP so I would like to get guidance from PHP experts.
What I think for achieving this feature is :-
1) Creating 1 web service and passing some data/flag from app to this web service.
2) This web service will send some data to page somehow and using that data we can show alert with sound.
Question :-
I know how to pass data using web service from app to web service. But I don;t know how can I show alert from web service on website where user can see it and also playing sound. And I would like to play it constantly until user click on OK or some other button provided on the site.
Please forgive me If my question looks very poor as I am not good in writing. But I am clear what I would like to achieve but don't have the knowledge of how to do that using PHP, so it will be really great if someone can guide me for this and help me a little bit so that I can at least proceed further.
To do this you need that resource downloaded on your device. I don't think you can stream it. It's not recomanded anyway.
In php just send a json key "play_file": 1 or "play_file": "sound.mp3"
Use the Android documentation for further info.
You can try using a button with a event to check the flag status and start the sound method.
obs: You can use Javascript for this action.
example: Start a method from clickEvent with a sound loop
Method code
while(flag){
playSound('UrlToSoundFile');
}

jQuery post big text data transfer (eventual load)

The problem:
I have a jquery ajax (post) based website, where the website doesn't refresh every time user navigates to another page. Which means I have to pull data with ajax and present it to the user. Now for pulling small text data, this system works great. However once the text data is huge (let's say over 200,000 words), the load time is quite high (especially for mobile users). What I mean to say is, ajax tries to load full text information and displays it after it is done loading all text. So the user has to wait quite a bit to get the information.
If you look at a different scenario, let's say wikipedia. There are big pages in wikipedia. However, a user doesn't feel he/she has to wait a lot because the page loads step by step (top to bottom). So even if the page is large, the user is already kept busy with some information. And while the user is processing those, rest of the page keeps loading.
Question:
So is it possible to display, via ajax, information on real time load? Meaning keep showing whatever is loaded and not wait for the full document to be loaded?
Ajax (xmlhttprequest) is a really great feature in html5, for the same thing, ajax is better than socket, by that, I mean non-persistant connection but as soon as the connection is persistant (impossible for xmlhttprequest)socket is fastest.
The simplest way is to use web socket is socket.io but you need a JavaScript server to use this library and there is one host where you can get one for free with admin tools: heroku.
You can use PHP server if you dont want to use JavaScript server with the socketme library but it is a bit more complex.
Also, you can think diferently, you try to send a lot of data.
200 000 words is something like 70ko (I try a lorem ipsum), the upload speed is relative to data and connection speed/ping. You can compress by any way your data before sending and uncompress server-side. There is probably thousand way to do this but I think the simpliest way is to find a JavaScript library to compress/uncompress data and simply use your jquery ajax to send what's compressed.
EDIT — 21/03/14:
I misunderstood the question, you want to display the current upload progress ?
Yes, it is possible by using the onprogress event, in jQuery you must follow this simple exemple: jQuery ajax progress

Javascript to set part of website

Is there any way I could, using only Javascript and HTML, have a page with only a line of text and a text box, and when someone hits enter in the text box, it would set the text on the page, not just for them, but for anyone seeing the page?
EDIT: If there was a way to self-modify the HTML page to show whatever was typed, while unstable, that would be best in this case - don't ask.
EDIT2: If not, how could I do this in PHP? Here's kind of my idea: A very sketchy idea of a twitter-like site, kind of a "1.4 seconds of fame" thing. Anyone can post anything, and until someone posts on top of it, the entire world can see it. I guess it's like a public chatroom with only the 3 latest messages visible. Here's a basic, non-functional HTML prototype:
http://uploadir.com/u/i774cx
Yes … but only if the JavaScript is running on the server (e.g. via node.js).
You can't record changes to data stored on the server entirely with client side scripting. The closest you could come would be make an HTTP PUT request, but even that would require a web server which supported PUT and gave the client permission to add the file.

Categories