bigbluebutton-Github/bigbluebutton-client/src/DeskshareStandalone.mxml

160 lines
5.6 KiB
Plaintext
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:mate="http://mate.asfusion.com/"
creationComplete="onCreationComplete()"
width="100%" height="100%"
layout="absolute">
<mate:Listener type="{AppletStartedEvent.APPLET_STARTED}" method="onAppletStart" />
<mate:Listener type="{ViewStreamEvent.STOP}" method="onAppletStop" />
<mate:Listener type="{ViewStreamEvent.START}" method="onViewStreamStart"/>
<mate:Listener type="{CursorEvent.UPDATE_CURSOR_LOC_EVENT}" method="onUpdateCursorEvent" />
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import org.bigbluebutton.modules.deskShare.events.CursorEvent;
import org.bigbluebutton.modules.deskShare.events.ViewStreamEvent;
import mx.controls.Button;
import mx.containers.Canvas;
import org.bigbluebutton.modules.deskShare.events.AppletStartedEvent;
import org.bigbluebutton.util.QueryStringParameters;
import mx.core.UIComponent;
import org.bigbluebutton.modules.deskShare.services.DeskshareService;
import org.bigbluebutton.common.Images;
private var videoHolder:UIComponent;
private var cursor:Shape;
private var images:Images = new Images();
[Bindable] public var bbbLogo:Class = images.bbb_logo;
private var video:Video;
private var ns:NetStream;
private var stream:String;
private var logoutURL:String;
private var host:String;
private var room:String;
private var displayWidth:Number;
private var displayHeight:Number;
private var service:DeskshareService = new DeskshareService();
private function onCreationComplete():void {
var p:QueryStringParameters = new QueryStringParameters();
p.collectParameters();
logoutURL = p.getParameter("LOGOUTURL");
host = p.getParameter("HOST");
room = p.getParameter("ROOM");
service.connect(host+"/"+room);
cursor = new Shape();
cursor.graphics.lineStyle(6, 0xFF0000, 0.6);
cursor.graphics.drawCircle(0,0,3);
cursor.visible = false;
displayWidth = this.parent.width;
displayHeight = this.parent.height;
}
private function onAppletStart(event:AppletStartedEvent):void{
// startVideo(service.getConnection(), room, videoWidth, videoHeight);
}
private function onViewStreamStart(event:ViewStreamEvent):void {
startVideo(service.getConnection(), room, event.videoWidth, event.videoHeight);
}
private function onAppletStop(event:ViewStreamEvent):void {
var url:URLRequest = new URLRequest(logoutURL);
navigateToURL(url, '_self');
}
private function startVideo(connection:NetConnection, stream:String, videoWidth:Number, videoHeight:Number):void{
ns = new NetStream(connection);
ns.addEventListener( NetStatusEvent.NET_STATUS, onNetStatus );
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
ns.client = this;
ns.bufferTime = 0;
ns.receiveVideo(true);
ns.receiveAudio(false);
video = new Video(videoWidth, videoHeight);
video.attachNetStream(ns);
videoHolder = new UIComponent();
calculateDisplayDimensions(video, videoHolder);
videoHolder.addChild(video);
videoHolder.addChild(cursor);
ns.play(stream);
this.stream = stream;
vbox.addChild(videoHolder);
}
private function calculateDisplayDimensions(video:Video, videoHolder:UIComponent):void {
if (videoIsSmallerThanDisplay(video, videoHolder)) {
videoHolder.width = video.width;
videoHolder.height = video.height;
return;
}
if (displayWidth < displayHeight) {
fitToWidthAndAdjustHeightToMaintainAspectRatio();
} else {
fitToHeightAndAdjustWidthToMaintainAspectRatio();
}
}
private function onUpdateCursorEvent(event:CursorEvent):void {
cursor.x = ((event.x/video.videoWidth)) * videoHolder.width;
cursor.y = ((event.y/video.videoHeight)) * videoHolder.height;
cursor.visible = true;
}
public function stopViewing():void {
ns.close();
}
private function onAsyncError(e:AsyncErrorEvent):void{
trace("VIdeoWindow::asyncerror " + e.toString());
}
private function onNetStatus(e:NetStatusEvent):void{
switch(e.info.code){
case "NetStream.Play.Start":
trace("NetStream.Publish.Start for broadcast stream " + stream);
trace("Dispatching start viewing event");
service.sendStartedViewingNotification();
break;
case "NetStream.Play.UnpublishNotify":
trace("NetStream.Play.UnpublishNotify for broadcast stream " + stream);
stopViewing();
break;
}
}
private function videoIsSmallerThanDisplay(video:Video, videoHolder:UIComponent):Boolean {
return (video.height < displayHeight) && (video.width < displayWidth);
}
private function fitToWidthAndAdjustHeightToMaintainAspectRatio():void {
var aspectRatio:Number = video.height/video.width;
video.width = displayWidth;
videoHolder.width = video.width;
// Maintain aspect-ratio
video.height = displayHeight * aspectRatio;
videoHolder.height = video.height;
}
private function fitToHeightAndAdjustWidthToMaintainAspectRatio():void {
var aspectRatio:Number = video.height/video.width;
video.height = displayHeight;
videoHolder.height = video.height;
// Maintain aspect-ratio
video.width = (aspectRatio * displayWidth);
videoHolder.width = video.width;
}
]]>
</mx:Script>
<mx:Canvas id="vbox" width="100%" height="100%"/>
</mx:Application>