text: import Rx from 'rxjs/Rx';
  
  export default function open(url, channel) {
    let identifier = JSON.stringify({channel});
    let socket = new WebSocket(url);
    let subject = new Rx.Subject();
  
    socket.onmessage = event => {
      let data = JSON.parse(event.data);
      if (data.identifier === identifier && data.type === 'message') {
        subject.next(data.message);
      }
    }
  
    socket.onopen = () => {
      socket.send(JSON.stringify({command: 'subscribe', identifier}));
    }
  
    socket.onclose = () => {
      subject.complete();
    }
  
    subject.close = () => socket.close();
  
    return subject;
  }
  