HTML and CSS Reference
In-Depth Information
The method works similar to the OnMessage method. The only difference is that it
takes a byte array (data) instead of string as a parameter. An array of bytes is the
most native and efficient image representation.
When the rest of the clients receive the image, a new <img> element will be created.
You have already seen the way, so you update the onmessage function accordingly:
socket.onmessage = function(event) {
if (typeof event.data === "string") {
// Decode JSON, then display nickname and
message.
// …
}
else if (event.data instanceof Blob) {
// Get the raw data and create an image
element.
var blob = event.data;
window.URL = window.URL || window.webkitURL;
var source =
window.URL.createObjectURL(blob);
var image = document.createElement("img");
image.src = source;
image.alt = "Image generated from blob";
document.body.appendChild(image);
}
}
Search WWH ::




Custom Search