Quantcast
Channel: Armetiz » iPhone
Viewing all articles
Browse latest Browse all 6

Actionscript – NetStream & P2P

0
0

Ce petit programme permet d’afficher la camera d’une personne qui se connecte. Cela est fait grâce à l’utilisation d’un flux NetStream lui même utilisant une connexion P2P sans serveur.

A noter que cela n’est absolument pas optimisé. Si vous avez des conseils à donner sur la configuration du NetStream, NetConnection, NetGroup ou encore du GroupSpecifier pour améliorer les performances, n’hésitez pas..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
private var nc          : NetConnection;
private var group       : NetGroup;
private var connected   : Boolean;
private var sendStream  : NetStream;
private var listenStreams   : Object;
private var groupspec   : GroupSpecifier;
private var listenStream    : NetStream;
private var id          : String;

public function WebcamP2P()
{
    super();
   
    stage.align         = StageAlign.TOP_LEFT;
    stage.scaleMode     = StageScaleMode.NO_SCALE;
   
    id  = String ( ( new Date () ).time * int ( Math.random() * 1000 ) );
   
    nc = new NetConnection ();
    nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
    nc.connect("rtmfp:");
}

private function netStatus (event:NetStatusEvent):void
{
    switch(event.info.code){
        case "NetConnection.Connect.Success":
            setupGroup();
            break;
        case "NetGroup.Connect.Success":
            connected = true;
            break;
        case "NetGroup.MulticastStream.PublishNotify":
            trace ( "name of the detected stream : " + event.info.name);

            var _video          : Video;
            var _listenStream   : NetStream;

            _video  = new Video ( 320, 240 );
            _listenStream   = new NetStream ( nc, groupspec.groupspecWithoutAuthorizations() );
            _listenStream.play ( event.info.name );

            _video.attachNetStream ( _listenStream );

            addChild ( _video );
            break;
    }
}

private function setupGroup():void
{
    groupspec = new GroupSpecifier("myGroup/groupOne");
    groupspec.postingEnabled    = false;
    groupspec.multicastEnabled  = true;
    groupspec.ipMulticastMemberUpdatesEnabled = true;
    groupspec.routingEnabled    = false;
    groupspec.addIPMulticastAddress("225.225.0.1:30303");
   
    group = new NetGroup(nc,groupspec.groupspecWithoutAuthorizations());
    group.receiveMode           = NetGroupReceiveMode.NEAREST;
    group.replicationStrategy       = NetGroupReplicationStrategy.RAREST_FIRST;
    group.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
   
    sendStream = new NetStream (nc, groupspec.groupspecWithoutAuthorizations() );
    sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
    sendStream.multicastAvailabilitySendToAll   = true;
    sendStream.attachAudio ( Microphone.getMicrophone() );
    sendStream.attachCamera ( Camera.getCamera () );
    sendStream.publish ( id );
}

Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images