Avatar

Level 3

Here's my view code, if anyone's interested.  The connection session is passed on the open, i.e.

navigator.pushView(VideoAFCSMobile, cSession)

<?xml version="1.0" encoding="utf-8"?>


<s:View


xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:rtc="http://ns.adobe.com/rtc"

xmlns:collaboration="com.adobe.rtc.collaboration.*"

xmlns:authentication="com.adobe.rtc.authentication.*"

xmlns:session="com.adobe.rtc.session.*"

width="100%" height="100%"

xmlns:afcs="com.ssc.components.thirdparty.afcs.*"

viewActivate="onViewActivate()"

creationComplete="view2_creationCompleteHandler(event)"

viewDeactivate="view2_viewDeactivateHandler(event)"

tabBarVisible="false">


<fx:Declarations>

<session:ConnectSession id="connectSession" />

<collaboration:AudioPublisher id="audioPub" connectSession="{this.data}" useEchoSuppression="true"/>

<collaboration:AudioSubscriber id="audioSub" connectSession="{this.data}" />

</fx:Declarations>

<fx:Script>

<![CDATA[

import com.adobe.coreUI.controls.VideoComponent;

import com.adobe.rtc.collaboration.WebcamPublisher;

import com.adobe.rtc.collaboration.WebcamSubscriber;

import com.adobe.rtc.events.SessionEvent;

import com.adobe.rtc.session.ConnectSession;

import com.adobe.rtc.session.IConnectSession;

import com.adobe.rtc.sharedManagers.UserManager;

import com.ssc.components.generic.events.*;

import com.ssc.model.AppModel;


import flash.media.Camera;


import mx.core.IVisualElement;

import mx.events.FlexEvent;


import spark.events.ViewNavigatorEvent;

import spark.transitions.SlideViewTransition;

[


Bindable]

public var model:AppModel = AppModel.getInstance();

[Bindable]

override public function set data(obj:Object):void{

model.logger.debug("VideoAFCSMobile: setting data");

if (obj is IConnectSession) {

model.logger.debug("VideoAFCSMobile: setting data to IConnectSession.");

connectSession = obj as ConnectSession;//super.data = obj;

}

}

override public function get data():Object{

return connectSession;

}

private function broadcastSync(event:SessionEvent):void{

this.dispatchEvent(event);


}


private function recordVideo(event:Event):void{

var evt:CollaborationEvent = new CollaborationEvent(CollaborationEvent.RECORD_VIDEO);

this.dispatchEvent(evt);

}


protected function view1_creationCompleteHandler(event:FlexEvent):void

{


}


protected function onViewActivate():void

{

model.logger.debug(


"VideoAFCSMobile: onViewActivate");

connectSession.addEventListener(SessionEvent.SYNCHRONIZATION_CHANGE, onSynchronizationChange);

tranLeft.direction="right";


}


protected function onSynchronizationChange(event:SessionEvent):void

{


model.logger.debug("VideoAFCSMobile: onSynchronizationChange");


if (connectSession.isSynchronized) {


webcamSub.subscribe();

audioSub.subscribe();


webcamSub.width = width;

webcamSub.height = height

webcamSub.webcamPublisher = webcamPub;

camera.addChild(webcamSub);

if (!webcamPub.isPublishing) {

frontCameraBtn.enabled=true;

backCameraBtn.enabled=true;

} else {

frontCameraBtn.enabled=false;

backCameraBtn.enabled=false;

}

} else {

connectSession.removeEventListener(SessionEvent.SYNCHRONIZATION_CHANGE, onSynchronizationChange);

}

}


protected function logout(event:MouseEvent):void

{

//Stop video

if (webcamPub.isPublishing) {

webcamPub.stop();

//webcamPub.close();

}

// Stop audio

if (audioPub.isPublishing) {

audioPub.stop();

}

frontCameraBtn.enabled=true;

backCameraBtn.enabled=true;

}


protected function login(cameraIdx:String):void

{

var l:int = Camera.names.length;

for (var i:int=0; i<l; i++) {

model.logger.debug("Camera (" + i + ") found:" + Camera.names[i]);

}


if (!webcamPub.isPublishing) {

webcamPub.cameraNameIndex=cameraIdx;

model.logger.debug("Using Camera:" + cameraIdx );// + webcamPub.camera.name);

webcamPub.subscribe();

webcamPub.publish();

webcamSub.width= width;

webcamSub.height= height;

//webcamSub.webcamPublisher = webcamPub;

camera.addChild(webcamSub);

//camera.setLayoutBoundsSize(camera.width,camera.height);


if (!audioPub.isPublishing) {

audioPub.subscribe();

audioPub.publish();

}

}

frontCameraBtn.enabled=false;

backCameraBtn.enabled=false;


}


protected function view2_creationCompleteHandler(event:FlexEvent):void

{

systemManager.stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, orientationChangeHandler);

webcamPub = new WebcamPublisher();

webcamSub = new WebcamSubscriber();

webcamPub.connectSession = this.connectSession;

webcamSub.connectSession = this.connectSession;

onSynchronizationChange(null);

}


public function orientationChangeHandler(event:StageOrientationEvent):void {

if (camera && camera.getChildAt(0)) {

camera.removeChild(webcamSub);

camera.addChild(webcamSub);

}

}


protected function view2_viewDeactivateHandler(event:ViewNavigatorEvent):void

{

// TODO Auto-generated method stub


}


]]>

</fx:Script>


<s:states>

  <s:State name="portrait"/>

  <s:State name="landscape"/>
</s:states>

<s:Group id="cameraHolder" width="100%" height="100%">

  <s:SpriteVisualElement visible.landscape="true" visible.portrait="true" id="camera" x="0" y="0" width="100%" height="100%"

top="0" bottom="0" right="0" left="0" />


  <s:HGroup bottom="20" height="80" visible.landscape="false" visible.portrait="true" width="100%" horizontalAlign="center">

     <s:Button label="Front" id="frontCameraBtn" enabled="{webcamPub.isPublishing}" click="login('1')" width="33%" horizontalCenter="1"/>

     <s:Button label="Back" id="backCameraBtn" enabled="{webcamPub.isPublishing}" click="login('0')" width="33%" horizontalCenter="1"/>

     <s:Button label="End" id="endCameraBtn" click="logout(event)" enabled="{!(frontCameraBtn.enabled || backCameraBtn.enabled)}" width="33%" horizontalCenter="1"/>

  </s:HGroup>
</s:Group>


<s:titleContent>

  <s:Label width="100%" styleName="titleContentTextStyle" text="Video" maxDisplayedLines="2"/>

</s:titleContent>


<s:navigationContent>

  <s:Button id="logoButton" label="Back" click="this.navigator.popView(tranLeft)"/>
</s:navigationContent>

</s:View>