Question

I'm writting voice chat in flash player communicator using Adobe Cirrus. I can't handle the problem with connecting two flash players via local network. I have tomcat server with compiled SWF file (192.168.1.2:8080/evm_server/bin). When I open this SWF file on my local computer (192.168.1.2) everything works fine. I can login and call to client logged on other computer in network, but when I try to login on the other computer, and call to 192.168.1.2 nothing happens (no Alert displays, but it should). this is code of comunicating component:

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx"
           xmlns:components="pl.rafalo235.evm_client.components.*"
           show="initGroup(event)"
           creationComplete="initApp(event)">

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
    <mx:HTTPService id="friendsService"
            method="POST"
            url="{EVMServerConnection.SERVER_ADDRESS}/friends"
            result="friendsService_resultHandler(event)"
            fault="friendsService_faultHandler(event)">
        <mx:request>
            <login>{userAccount.login}</login>
            <password>{password}</password>
        </mx:request>
    </mx:HTTPService>

    <mx:HTTPService id="setPeerIdService"
            method="POST"
            url="{EVMServerConnection.SERVER_ADDRESS}/peerId"
            result="peerIdService_resultHandler(event)"
            fault="peerIdService_faultHandler(event)">
        <mx:request>
            <login>{userAccount.login}</login>
            <password>{password}</password>
            <peerId>{myPeerId}</peerId>
            <a>1</a>
        </mx:request>
    </mx:HTTPService>

    <mx:HTTPService id="clearPeerIdService"
            method="POST"
            url="{EVMServerConnection.SERVER_ADDRESS}/peerId"
            result="peerIdService_resultHandler(event)"
            fault="peerIdService_faultHandler(event)">
        <mx:request>
            <login>{userAccount.login}</login>
            <password>{password}</password>
            <a>0</a>
        </mx:request>
    </mx:HTTPService>
</fx:Declarations>

<fx:Script>
    <![CDATA[
    import flash.events.Event;
    import flash.media.Microphone;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import mx.collections.ArrayCollection;
    import mx.collections.ArrayList;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.events.FaultEvent;
    import pl.rafalo235.evm_client.data.Account;
    import mx.events.FlexEvent;
    import pl.rafalo235.evm_client.data.Friend;
    import pl.rafalo235.evm_client.events.CallButtonClickEvent;
    import flash.events.NetStatusEvent;
    import mx.controls.Alert;
    import pl.rafalo235.evm_client.net.CirrusServerConnection;
    import pl.rafalo235.evm_client.net.EVMServerConnection;
    import pl.rafalo235.evm_client.events.CirrusServerConnectionEvent;

    [Bindable]
    public var applicationRoot:Main;

    [Bindable]
    public var userAccount:Account;

    [Bindable]
    public var friendsList:ArrayCollection = new ArrayCollection();

    [Bindable]
    private var password:String;


    public function initApp(event:FlexEvent):void {
        friendsListUI.addEventListener(CallButtonClickEvent.CALL_BUTTON_CLICK, onCallButtonClick);
    }

    public function initGroup(event:FlexEvent):void {
        initNetConnection();
        friendsService.send();
    }

    public function destructGroup():void {
        clearPeerIdService.send();
        userAccount = null;
        friendsList.removeAll();
        password = null;
    }

    public function setPassword(password:String):void {
        this.password = password;
    }

    public function friendsService_resultHandler(event:ResultEvent):void {
        if (event.result.friends != null) {
            if (event.result.friends.friend is ArrayCollection) {
                var eventData:ArrayCollection = ArrayCollection(event.result.friends.friend);
                var tmpFriend:Friend = null;

                for each (var eventDataItem:Object in eventData) {
                    tmpFriend = new Friend(eventDataItem);
                    friendsList.addItem(tmpFriend);
                    tmpFriend = null;
                }
            } else {
                friendsList.addItem(new Friend(event.result.friends.friend));
            }
        }
    }

    public function friendsService_faultHandler(event:FaultEvent):void {

    }

    public function switchAuthenticationView(event:MouseEvent):void {
        destructGroup();
        applicationRoot.currentState = "default";
    }

    public function onCallButtonClick(event:Event):void {
        var e:CallButtonClickEvent = CallButtonClickEvent(event);
        connectToPeer(e.friend.peerId);
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~private

    [Bindable]
    private var cirrusServerConnection:CirrusServerConnection;

    private const SERVER_ADDRESS:String = "rtmfp://p2p.rtmfp.net/";
    private const DEVELOPER_KEY:String = "f3161a7e23cab7eeae9ea32d-fe63c3b19868";

    private var netConnection:NetConnection;

    [Bindable]
    private var myPeerId:String;
    private var farPeerID:String;

    private var sendStream:NetStream;
    private var recvStream:NetStream;

    private var mic:Microphone;

    private function initNetConnection():void {
        //cirrusServerConnection = new CirrusServerConnection();
        //cirrusServerConnection.addEventListener(CirrusServerConnectionEvent.CONNECTED, openSendStream);
        //cirrusServerConnection.connect();
        netConnection = new NetConnection();
        netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        netConnection.connect(SERVER_ADDRESS + DEVELOPER_KEY);

        if (Microphone.isSupported) {
            mic = Microphone.getMicrophone();
            mic.rate = 11;
            mic.setUseEchoSuppression(true);
            mic.gain = 50;
            mic.setSilenceLevel(20);
        }
    }

    private function netStatusHandler(event:NetStatusEvent):void {
        trace("CirrusConnection: " + event.info.code);
        Alert.show("CirrusConnection: " + event.info.code);
        switch(event.info.code) {
            case "NetConnection.Connect.Success":
                myPeerId = netConnection.nearID;
                openSendStream();
                break;
            case "NetStream.Play.Start":
                break;
        }
    }

    private function sendStreamStatusHandler(event:NetStatusEvent):void {
        trace("SendStream: " + event.info.code);
        Alert.show("SendStream: " + event.info.code);
        switch(event.info.code) {
            case "NetStream.Publish.Start":
                setPeerIdService.send();
                break;
            case "NetStream.Play.Start":
                if (Microphone.isSupported) {
                    sendStream.attachAudio(mic);
                } else {
                    Alert.show("Microphone not supported");
                }
                break;
        }
    }

    private function recvStreamStatusHandler(event:NetStatusEvent):void {
        trace("RecvStream: " + event.info.code);
        Alert.show("RecvStream: " + event.info.code);
        switch(event.info.code) {
            case "NetConnection.Connect.Success":
                break;
            case "NetStream.Play.Start":
                recvStream.receiveAudio(true);
                break;
        }
    }

    private function openSendStream():void {
        var sendStreamClient:Object = new Object();
        sendStreamClient.onPeerConnect = function(callerns:NetStream):Boolean {
            trace("peerConnected");
            if (!Boolean(farPeerID)) {
                connectToPeer(callerns.farID);
            }
            return true;
        }

        sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
        sendStream.addEventListener(NetStatusEvent.NET_STATUS, sendStreamStatusHandler);
        sendStream.client = sendStreamClient;
        sendStream.publish("media");
    }

    public function connectToPeer(id:String):void {
        farPeerID = id;
        recvStream = new NetStream(netConnection,farPeerID);
        recvStream.addEventListener(NetStatusEvent.NET_STATUS, recvStreamStatusHandler);
        recvStream.client = this;
        recvStream.play("media");
    }

    public function peerIdService_resultHandler(event:ResultEvent):void {

    }

    public function peerIdService_faultHandler(event:FaultEvent):void {

    }

    ]]>
</fx:Script>

<s:DataGroup id="friendsListUI" 
            dataProvider="{friendsList}"
                itemRenderer="pl.rafalo235.evm_client.components.FriendItemRenderer"
            x="25" y="25"
            width="200" height="550">

    <s:layout>
        <s:VerticalLayout />
    </s:layout>

</s:DataGroup>

<components:LinkButton x="700" y="25"
        label="Logout" 
        skinClass="pl.rafalo235.evm_client.skins.LinkButtonSkin"
        click="switchAuthenticationView(event)" />

</s:Group>

I publish and get other peerIds on database via Java server (192.168.1.2:8080/evm_server). Maybe important is that only 192.168.1.2 have connected microphone. I would be grateful for quick help. Thank you in advance for it.

Was it helpful?

Solution

The problem was in Firewall configuration. When I turned it off the trouble disappears.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top