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

199 lines
7.2 KiB
Plaintext
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
2010-11-06 02:04:24 +08:00
<!--
BigBlueButton open source conferencing system - http://www.bigbluebutton.org
Copyright (c) 2010 BigBlueButton Inc. and by respective authors (see below).
BigBlueButton is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2.1 of the License, or (at your option) any later
version.
BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
$Id: $
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:mate="http://mate.asfusion.com/"
creationComplete="onCreationComplete()"
backgroundColor="white"
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.Image;
2010-07-17 00:28:54 +08:00
import org.bigbluebutton.modules.deskshare.events.CursorEvent;
import org.bigbluebutton.modules.deskshare.events.ViewStreamEvent;
import mx.controls.Button;
import mx.containers.Canvas;
2010-07-17 00:28:54 +08:00
import org.bigbluebutton.modules.deskshare.events.AppletStartedEvent;
import org.bigbluebutton.util.QueryStringParameters;
import mx.core.UIComponent;
2010-07-17 00:28:54 +08:00
import org.bigbluebutton.modules.deskshare.services.DeskshareService;
import org.bigbluebutton.common.Images;
private var videoHolder:UIComponent;
private var cursor:Shape = new 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.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, event.videoWidth, event.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);
videoHolder.addChild(cursorImg);
centerVideo();
ns.play(stream);
this.stream = stream;
vbox.addChild(videoHolder);
}
private function centerVideo():void {
videoHolder.x = vbox.width/2 - video.width/2;
videoHolder.y = vbox.height/2 - video.height/2;
}
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 {
if (cursor == null) return;
cursor.x = ((event.x/video.videoWidth)) * videoHolder.width;
cursor.y = ((event.y/video.videoHeight)) * videoHolder.height;
// cursor.visible = true;
cursorImg.visible = true;
// DO NOT compute the x and y coordinate and assign directly to the cursorImg
// as it results in a flickering and jerky mouse pointer (ralam jun 10, 2010).
cursorImg.x = cursor.x;
cursorImg.y = cursor.y;
}
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 = displayWidth * aspectRatio;
videoHolder.height = video.height;
}
private function fitToHeightAndAdjustWidthToMaintainAspectRatio():void {
var aspectRatio:Number = video.width/video.height;
video.height = displayHeight;
videoHolder.height = video.height;
// Maintain aspect-ratio
video.width = aspectRatio * displayHeight;
videoHolder.width = video.width;
}
]]>
</mx:Script>
2010-07-17 00:28:54 +08:00
<mx:Image id="cursorImg" visible="false" source="@Embed('org/bigbluebutton/modules/deskshare/assets/images/cursor4.png')"/>
<mx:Canvas id="vbox" width="100%" height="100%"/>
</mx:Application>