YuukanOO / streamy

Use meteor underlying sockets for realtime communications
https://atmospherejs.com/yuukan/streamy
MIT License
105 stars 20 forks source link

How to send an image with Streamy ? #35

Closed JeromeVi closed 7 years ago

JeromeVi commented 7 years ago

Is it possible to send an image with streamy ? it's a svg file that I need to transfer from Server to Client

JeromeVi commented 7 years ago

I made it

YuukanOO commented 7 years ago

Mind sharing your solution @JeromeVi ?

JeromeVi commented 7 years ago

@YuukanOO yes of course:

Server

function sendTheGraphic(from){
  //we read the file and we got a string
  var fileString = fs.readFileSync("mysource.svg","utf8");
  //we send this string to the client
  Streamy.emit('theGraph', {
       result: fileString,
  }, from);
}

Client

Streamy.on('theGraph', function(result) {
  //we remove the first line (it's static)
  var htmlGraph = result.result.replace("<?xml version='1.0' encoding='UTF-8' standalone='no'?>","");
  //and we add the code to our client web page
  document.getElementById('divGraph').innerHTML = htmlGraph;
});