package im.actor.runtime.js.webrtc;

import im.actor.runtime.js.media.JsAudio;
import im.actor.runtime.webrtc.WebRTCMediaStream;

public class MediaStream implements WebRTCMediaStream {

    private JsMediaStream stream;
    private JsAudio audio;
    private boolean isEnabled = true;

    public MediaStream(JsMediaStream stream) {
        this(stream, true);
    }

    public MediaStream(JsMediaStream stream, boolean autoPlay) {
        this.stream = stream;
        if (autoPlay) {
            this.audio = JsAudio.create();
            this.audio.setSourceStream(stream);
            this.audio.play();
        }
    }

    public JsMediaStream getStream() {
        return stream;
    }

    public JsAudio getAudio() {
        return audio;
    }

    @Override
    public boolean isEnabled() {
        return isEnabled;
    }

    @Override
    public void setEnabled(boolean isEnabled) {
        if (audio != null) {
            if (isEnabled) {
                audio.play();
            } else {
                audio.pause();
            }
        }
        if (!isEnabled) {
            stream.stopAll();
        } else {
            stream.startAll();
        }
    }

    @Override
    public void close() {
        if (audio != null) {
            audio.pause();
            audio.reset();
        }
        stream.stop();
    }
}

@@ -259,24 +259,29 @@
 e boolean is
+Audio
 Enabled = tr
@@ -786,24 +786,29 @@
 c boolean is
+Audio
 Enabled() %7B%0A
@@ -820,24 +820,29 @@
    return is
+Audio
 Enabled;%0A   
@@ -878,16 +878,21 @@
 void set
+Audio
 Enabled(
@@ -1189,32 +1189,237 @@
        %7D%0A    %7D%0A%0A
+    @Override%0A    public boolean isVideoEnabled() %7B%0A        //TODO implement%0A        return false;%0A    %7D%0A%0A    @Override%0A    public void setVideoEnabled(boolean isEnabled) %7B%0A        //TODO implement%0A    %7D%0A%0A
     @Override%0A  

update js MediaStream