HTML and CSS Reference
In-Depth Information
Sending images to the server
Remember the ondrop event we discussed previously? For consistency reasons,
here is the same functionality using Blobs instead of ArrayBuffers:
document.ondrop = function(event) {
var file = event.dataTransfer.files[0];
socket.send(file);
return false;
}
When dealing with HTML5 drag-and-drop, remember to always prevent the default
drag-and-drop behavior! Unless you explicitly define that you want to override the
defaultfunctionality,whateveryouimplementwillnotbeshowncorrectly.Fortunately,
preventing the predefined actions from happening is quite simple:
document.ondragover = function (event) {
event.preventDefault();
}
The server needs to distribute the blob image to all the clients. Fleck library intro-
duces the OnBinary event, which is raised when binary data is received:
socket.OnBinary = data =>
{
// Send the binary data to everyone!
foreach (var client in clients)
{
client.Send(data);
}
};
Search WWH ::




Custom Search