PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/dev/FLDev/src/Hello.as

http://github.com/OpenRTMFP/ArcusNode
ActionScript | 831 lines | 603 code | 199 blank | 29 comment | 24 complexity | 13b8a6bac0592867682454e3449fcbdc MD5 | raw file
Possible License(s): GPL-3.0
  1. package
  2. {
  3. import com.bit101.components.CheckBox;
  4. import com.bit101.components.InputText;
  5. import com.bit101.components.Label;
  6. import com.bit101.components.List;
  7. import com.bit101.components.PushButton;
  8. import com.bit101.components.RadioButton;
  9. import com.bit101.components.Text;
  10. import com.bit101.components.TextArea;
  11. import flash.display.Bitmap;
  12. import flash.display.BitmapData;
  13. import flash.display.Loader;
  14. import flash.display.MovieClip;
  15. import flash.events.ActivityEvent;
  16. import flash.events.Event;
  17. import flash.events.IOErrorEvent;
  18. import flash.events.MouseEvent;
  19. import flash.events.NetStatusEvent;
  20. import flash.events.SecurityErrorEvent;
  21. import flash.media.Camera;
  22. import flash.media.Microphone;
  23. import flash.media.Video;
  24. import flash.net.FileReference;
  25. import flash.net.GroupSpecifier;
  26. import flash.net.NetConnection;
  27. import flash.net.NetGroup;
  28. import flash.net.NetGroupReplicationStrategy;
  29. import flash.net.NetStream;
  30. import flash.utils.ByteArray;
  31. import flash.utils.setTimeout;
  32. import flash.display.Sprite;
  33. import flash.display.StageAlign;
  34. import flash.display.StageScaleMode;
  35. public class Hello extends Sprite
  36. {
  37. private var _connected:Boolean = false
  38. private var _broadcasting:Boolean = false
  39. private var _subsribed:Boolean = false
  40. private var _webcam:Boolean = false;
  41. // gui movieclips
  42. private var ntstr_mc:MovieClip
  43. private var grpspf_mc:MovieClip
  44. private var ntcon_mc:MovieClip
  45. private var psting_mc:MovieClip
  46. // GroupSpecifier GUI
  47. private var label_GroupSpecifier:Label
  48. private var it_groupSpecieferName:InputText
  49. private var label_name:Label
  50. private var cb_ipMulticastMemberUpdatesEnabled:CheckBox
  51. private var label_ipMulticastMemberUpdatesEnabled:Label
  52. private var cb_multicastEnabled:CheckBox
  53. private var label_multicastEnabled:Label
  54. private var cb_objectReplicationEnabled:CheckBox
  55. private var label_objectReplicationEnabled:Label
  56. private var cb_peerToPeerDisabled:CheckBox
  57. private var label_peerToPeerDisabled:Label
  58. private var cb_postingEnabled:CheckBox
  59. private var label_postingEnabled:Label
  60. private var cb_routingEnabled:CheckBox
  61. private var label_routingEnabled:Label
  62. private var cb_serverChannelEnabled:CheckBox
  63. private var label_serverChannelEnabled:Label
  64. // Netstream GUI
  65. private var it_streamName:InputText
  66. private var label_streamName:Label
  67. private var btn_broadcast:PushButton
  68. private var btn_subscribe:PushButton
  69. private var label_Netstream:Label
  70. private var btn_webcam:PushButton;
  71. private var btn_netstream:PushButton
  72. // NetConnection GUI
  73. private var label_NetConnection:Label
  74. private var label_protocol_server:Label
  75. private var it_protocol_server:InputText
  76. private var label_ip_server:Label
  77. private var it_ip_server:InputText
  78. private var label_devkey_server:Label
  79. private var it_devkey_server:InputText
  80. private var btn_connect:PushButton
  81. private var btn_disconnect:PushButton
  82. private var cb_reconnect:CheckBox
  83. // info GUI
  84. private var info_mc:MovieClip
  85. private var ta_info:TextArea
  86. private var t_myID:Text
  87. private var l_otherID:List
  88. //video GUI
  89. private var video_mc:Sprite;
  90. private var videoScreen_local:MovieClip;
  91. private var videoScreen_other:MovieClip;
  92. // post GUI
  93. private var label_Posting:Label
  94. private var label_postingName:Label
  95. private var it_postingName:InputText
  96. private var label_postingMessage:Label
  97. private var it_postingMessage:InputText
  98. private var btn_post:PushButton
  99. private var btn_sendToNeighbor:PushButton
  100. //filesharing GUI
  101. public var flsr_mc:MovieClip
  102. private var file:FileReference;
  103. private var p2pSharedObject:Object
  104. //
  105. private var nc:NetConnection;
  106. private var groupspec:GroupSpecifier
  107. private var stream:NetStream;
  108. private var group:NetGroup;
  109. //
  110. private var otherIDs:Array = []
  111. private var userName:String;
  112. private var bmpd_ruis_local:BitmapData;
  113. private var bmpd_ruis_other:BitmapData;
  114. private var bmp_ruis_local:Bitmap;
  115. private var bmp_ruis_other:Bitmap;
  116. private var perlinNoise_number:Number = 0;
  117. private var camera:Camera;
  118. private var microphone:Microphone;
  119. private var video:Video = new Video()
  120. public function Hello()
  121. {
  122. if (stage) init(null);
  123. else addEventListener(Event.ADDED_TO_STAGE, init);
  124. }
  125. private function init(e:Event):void
  126. {
  127. removeEventListener(Event.ADDED_TO_STAGE, init);
  128. stage.scaleMode = StageScaleMode.NO_SCALE;
  129. stage.align = StageAlign.TOP_LEFT;
  130. gui()
  131. info = 'Started...'
  132. userName = 'user_' + int(Math.random()*1000)
  133. it_postingName.text = userName
  134. p2pSharedObject = new Object()
  135. p2pSharedObject.size = 0
  136. p2pSharedObject.packetLenght = 0
  137. p2pSharedObject.data = 0
  138. p2pSharedObject.name = ''
  139. p2pSharedObject.chunks = new Object();
  140. var btn_extra:PushButton = new PushButton(stage, video_mc.x , video_mc.y + video_mc.height, 'ping close neighbor', OnPing)
  141. stage.addEventListener(Event.ENTER_FRAME, onENTER_FRAME)
  142. }
  143. private function OnPing(e:Event):void
  144. {
  145. var message:Object = new Object();
  146. message.sender = group.convertPeerIDToGroupAddress(nc.nearID);
  147. message.user = 'nc.nearID'
  148. message.text = 'ping'+Math.random()*100000;
  149. var a:* = group.sendToNearest(message, group.convertPeerIDToGroupAddress(otherIDs[0]))
  150. trace(a)
  151. //group.post(message);
  152. }
  153. //_________________________________________________________________________________________________GUI
  154. private function gui():void
  155. {
  156. gui_GroupSpecifier()
  157. gui_NetStream()
  158. gui_NetConnection()
  159. gui_Info()
  160. gui_Video()
  161. gui_Posting()
  162. gui_filesharing()
  163. grpspf_mc.y = ntcon_mc.y + ntcon_mc.height
  164. ntstr_mc.y = grpspf_mc.y + grpspf_mc.height + 20
  165. info_mc.x = 600
  166. video_mc.x = info_mc.x
  167. video_mc.y = info_mc.y + info_mc.height + 80
  168. psting_mc.y = ntstr_mc.y + 100
  169. flsr_mc.y = psting_mc.y + 150
  170. }
  171. private function onENTER_FRAME(e:Event):void
  172. {
  173. //ruis()
  174. }
  175. private function gui_Video():void
  176. {
  177. video_mc = new Sprite();
  178. stage.addChild(video_mc)
  179. videoScreen_local = new MovieClip()
  180. video_mc.addChild(videoScreen_local)
  181. videoScreen_local.graphics.beginFill(0xc9c9c9)
  182. videoScreen_local.graphics.lineStyle(1, 0x00)
  183. videoScreen_local.graphics.drawRect(0, 0, 320, 240)
  184. videoScreen_local.y = 20
  185. videoScreen_other = new MovieClip()
  186. video_mc.addChild(videoScreen_other)
  187. videoScreen_other.graphics.beginFill(0xc9c9c9)
  188. videoScreen_other.graphics.lineStyle(1, 0x00)
  189. videoScreen_other.graphics.drawRect(0,0,320,240)
  190. videoScreen_other.x = videoScreen_local.x + videoScreen_local.width + 20
  191. videoScreen_other.y = 20
  192. var l_videoScreen_local:Label = new Label(video_mc, 0, 0, 'local webcam')
  193. var l_videoScreen_other:Label = new Label(video_mc, videoScreen_local.x + videoScreen_local.width + 20, 0, 'otherside video')
  194. bmpd_ruis_local = new BitmapData(320, 240, false)
  195. bmpd_ruis_other = new BitmapData(320, 240, false)
  196. bmp_ruis_local = new Bitmap(bmpd_ruis_local)
  197. bmp_ruis_other = new Bitmap(bmpd_ruis_other)
  198. videoScreen_local.addChild(bmp_ruis_local)
  199. videoScreen_other.addChild(bmp_ruis_other)
  200. ruis();
  201. }
  202. private function gui_Info():void
  203. {
  204. info_mc = new MovieClip()
  205. stage.addChild(info_mc)
  206. ta_info = new TextArea(info_mc, 0, 0, 'info')
  207. ta_info.height = 300
  208. ta_info.width = ta_info.width + 200
  209. var l_myID:Label = new Label(info_mc, 0, ta_info.x + ta_info.height + 20, 'my ID')
  210. t_myID = new Text(info_mc, 50, ta_info.x + ta_info.height + 20, 'my id')
  211. t_myID.height = 20
  212. t_myID.width = t_myID.width + 150
  213. var l_other:Label = new Label(info_mc, 0, t_myID.y + 20, 'other ID\'s')
  214. l_otherID = new List(info_mc, 50, t_myID.y + 20)
  215. l_otherID.width = t_myID.width
  216. }
  217. private function gui_Posting():void
  218. {
  219. psting_mc= new MovieClip()
  220. stage.addChild(psting_mc)
  221. label_Posting = new Label(psting_mc, 0, 0, 'post to peers')
  222. label_postingName = new Label(psting_mc, 0, 20, 'name')
  223. it_postingName = new InputText(psting_mc, 30,20, '', update)
  224. label_postingMessage = new Label(psting_mc, 0, 40, 'msg')
  225. it_postingMessage = new InputText(psting_mc,30,40, '', update)
  226. it_postingMessage.width = 250
  227. var label_postingMessage2:Label = new Label(psting_mc, 320, 40, 'should be diff than last one')
  228. btn_post = new PushButton(psting_mc, 30, 60, 'post to all', onPost)
  229. var label_postingMessage3:Label = new Label(psting_mc, 320, 60, 'posting should be enabled')
  230. btn_sendToNeighbor = new PushButton(psting_mc, 30, 90, 'sendToNeighbor', onPost)
  231. var label_postingMessage4:Label = new Label(psting_mc, 320, 90, 'routing should be enabled')
  232. //var btn_post:PushButton = new PushButton(psting_mc, 30, 60, 'post to all', onPost)
  233. }
  234. private function gui_filesharing():void
  235. {
  236. flsr_mc = new MovieClip()
  237. stage.addChild(flsr_mc)
  238. var label_filesharing:Label = new Label(flsr_mc, 0,0, 'filesharing')
  239. var btn_browse:PushButton = new PushButton(flsr_mc, 0, 30, 'browse', onBrowse)
  240. var btn_getfile:PushButton = new PushButton(flsr_mc, 0, 130, 'get', onGet)
  241. }
  242. private function onGet(e:Event):void
  243. {
  244. group.addWantObjects(0, 1);
  245. }
  246. private function onBrowse(e:Event):void
  247. {
  248. file = new FileReference();
  249. file.addEventListener(Event.SELECT, selectHandler);
  250. //file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
  251. //file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
  252. //file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler)
  253. file.addEventListener(Event.COMPLETE, onBrowseCOMPLETE);
  254. file.browse();
  255. }
  256. private function selectHandler(event:Event):void
  257. {
  258. file.load();
  259. }
  260. private function onBrowseCOMPLETE(e:Event):void
  261. {
  262. info = ("completeHandler");
  263. p2pSharedObject = new Object()
  264. p2pSharedObject.size = file.size;
  265. p2pSharedObject.packetLenght = Math.floor(file.size/64000)+1;
  266. p2pSharedObject.data = file.data;
  267. p2pSharedObject.name = file.name
  268. //in een array ?
  269. p2pSharedObject.chunks = new Object();
  270. p2pSharedObject.chunks[0] = p2pSharedObject.packetLenght+1;
  271. for(var i:int = 1;i<p2pSharedObject.packetLenght;i++){
  272. p2pSharedObject.chunks[i] = new ByteArray();
  273. p2pSharedObject.data.readBytes(p2pSharedObject.chunks[i],0,64000);
  274. }
  275. // +1 last packet
  276. p2pSharedObject.chunks[p2pSharedObject.packetLenght] = new ByteArray();
  277. p2pSharedObject.data.readBytes(p2pSharedObject.chunks[i],0,p2pSharedObject.data.bytesAvailable);
  278. p2pSharedObject.packetLenght+=1;
  279. info = ("----- p2pSharedObject -----");
  280. info = ("packetLenght: "+(p2pSharedObject.packetLenght));
  281. group.replicationStrategy = NetGroupReplicationStrategy.LOWEST_FIRST;
  282. group.addHaveObjects(0, p2pSharedObject.packetLenght);
  283. var message:Object = new Object();
  284. message.user = 'share'
  285. message.text = file.name + '' + t_myID.text
  286. group.post(message)
  287. }
  288. private function gui_NetConnection():void
  289. {
  290. ntcon_mc = new MovieClip()
  291. stage.addChild(ntcon_mc)
  292. label_NetConnection = new Label(ntcon_mc, 0, 0, "NetConnection")
  293. label_protocol_server = new Label(ntcon_mc, 0,20, 'Protocol')
  294. it_protocol_server = new InputText(ntcon_mc, label_protocol_server.x + label_protocol_server.width + 20,20, 'rtmfp', update)
  295. label_ip_server = new Label(ntcon_mc, 0,40, 'IP')
  296. it_ip_server = new InputText(ntcon_mc, it_protocol_server.x,40, 'p2p.rtmfp.net', update)
  297. label_devkey_server = new Label(ntcon_mc, 0, 60, 'dev key')
  298. it_devkey_server = new InputText(ntcon_mc, it_protocol_server.x , 60, '', update)
  299. btn_connect = new PushButton(ntcon_mc, 0, 90, 'connect', onConnect)
  300. btn_disconnect = new PushButton(ntcon_mc, btn_connect.x+btn_connect.width + 10, 90, 'disconnect', ondisConnect)
  301. cb_reconnect = new CheckBox(ntcon_mc, 0, 120, 'reconnect (after 1 min) when connection failed', update)
  302. }
  303. private function gui_NetStream():void
  304. {
  305. ntstr_mc = new MovieClip()
  306. stage.addChild(ntstr_mc)
  307. label_Netstream = new Label(ntstr_mc, 0,0,"NetStream")
  308. it_streamName = new InputText(ntstr_mc, 0, 20, "STREAM_NAME_XYZ", update)
  309. label_streamName = new Label(ntstr_mc, it_streamName.x + it_streamName.width, 20, "Name A string that identifies the stream. Clients that subscribe to this stream must pass this same name")
  310. btn_netstream = new PushButton(ntstr_mc, 0, 50, 'setup netstream', onNetstream)
  311. btn_broadcast = new PushButton(ntstr_mc, 0, 50, "broadcast", onBroadcast)
  312. btn_subscribe = new PushButton(ntstr_mc, btn_broadcast.x +10 + btn_broadcast.width, 50, "subscribe", onSubscribe)
  313. btn_webcam = new PushButton(ntstr_mc, 0,50, 'webcam',onWebcam)
  314. btn_broadcast.visible = false
  315. btn_subscribe.visible = false
  316. btn_webcam.visible = false
  317. btn_netstream.visible = false
  318. }
  319. private function gui_GroupSpecifier():void
  320. {
  321. grpspf_mc = new MovieClip()
  322. stage.addChild(grpspf_mc)
  323. label_GroupSpecifier = new Label(grpspf_mc, 0, 0, "GroupSpecifier")
  324. label_name = new Label(grpspf_mc, 0, 20, 'A name for the Group on which all members must agree.')
  325. it_groupSpecieferName = new InputText(grpspf_mc, label_name.x+label_name.width, label_name.y, 'thename', update)
  326. cb_ipMulticastMemberUpdatesEnabled = new CheckBox(grpspf_mc, 0, 50, "ipMulticastMemberUpdatesEnabled : Boolean", update)
  327. cb_ipMulticastMemberUpdatesEnabled.selected = true
  328. label_ipMulticastMemberUpdatesEnabled = new Label(grpspf_mc, 0, 60, "Specifies whether information about group membership can be exchanged on IP multicast sockets.")
  329. cb_multicastEnabled = new CheckBox(grpspf_mc, 0, 90, "multicastEnabled : Boolean", update)
  330. label_multicastEnabled = new Label(grpspf_mc, 0, 100, "Specifies whether streaming is enabled for the NetGroup.")
  331. cb_objectReplicationEnabled = new CheckBox(grpspf_mc, 0, 130, "objectReplicationEnabled : Boolean", update)
  332. label_objectReplicationEnabled = new Label(grpspf_mc, 0, 140, "Specifies whether object replication is enabled for the NetGroup.")
  333. cb_peerToPeerDisabled = new CheckBox(grpspf_mc, 0, 170, "peerToPeerDisabled : Boolean", update)
  334. label_peerToPeerDisabled= new Label(grpspf_mc, 0, 180, "Specifies whether peer-to-peer connections are disabled for the NetGroup or NetStream.")
  335. cb_postingEnabled = new CheckBox(grpspf_mc, 0, 210, "postingEnabled : Boolean", update)
  336. label_postingEnabled = new Label(grpspf_mc, 0, 220, "Specifies whether posting is enabled for the NetGroup.")
  337. cb_routingEnabled = new CheckBox(grpspf_mc, 0, 250, "routingEnabled : Boolean", update)
  338. label_routingEnabled = new Label(grpspf_mc, 0, 260, "Specifies whether directed routing methods are enabled for the NetGroup.")
  339. cb_serverChannelEnabled = new CheckBox(grpspf_mc, 0, 290, "serverChannelEnabled : Boolean", update)
  340. label_serverChannelEnabled = new Label(grpspf_mc, 0, 300, "Specifies whether members of the NetGroup can open a channel to the server.")
  341. cb_routingEnabled.selected = true
  342. cb_multicastEnabled.selected = true
  343. cb_serverChannelEnabled.selected = true
  344. cb_postingEnabled.selected = true
  345. cb_objectReplicationEnabled.selected = true
  346. }
  347. private function ruis():void
  348. {
  349. perlinNoise_number ++
  350. if(perlinNoise_number > 10)perlinNoise_number = 1
  351. if (!_broadcasting)
  352. {
  353. bmpd_ruis_local.perlinNoise(5,5,1,perlinNoise_number,false, true,1, true)
  354. }
  355. perlinNoise_number ++
  356. if (!_subsribed)
  357. {
  358. bmpd_ruis_other.perlinNoise(5,5,1,perlinNoise_number,false, true,1, true)
  359. }
  360. }
  361. private function setup_groupspec():void
  362. {
  363. groupspec = new GroupSpecifier('myGroup/'+it_groupSpecieferName.text)
  364. groupspec.ipMulticastMemberUpdatesEnabled = cb_ipMulticastMemberUpdatesEnabled.selected
  365. groupspec.multicastEnabled = cb_multicastEnabled.selected
  366. groupspec.objectReplicationEnabled = cb_objectReplicationEnabled.selected
  367. groupspec.peerToPeerDisabled = cb_peerToPeerDisabled.selected
  368. groupspec.postingEnabled = cb_postingEnabled.selected
  369. groupspec.routingEnabled = cb_routingEnabled.selected
  370. groupspec.serverChannelEnabled = cb_serverChannelEnabled.selected
  371. }
  372. private function setup_stream():void
  373. {
  374. stream = new NetStream(nc,groupspec.groupspecWithAuthorizations())
  375. stream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
  376. }
  377. private function setup_group():void
  378. {
  379. group = new NetGroup(nc, groupspec.groupspecWithAuthorizations())
  380. group.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
  381. }
  382. private function setup_camera():void
  383. {
  384. if (!_webcam)
  385. {
  386. camera = Camera.getCamera();
  387. microphone = Microphone.getMicrophone();
  388. camera.setMode(320, 240, 12, false);
  389. camera.setQuality(0, 100);
  390. camera.setKeyFrameInterval(12);
  391. microphone.rate = 11;
  392. microphone.setSilenceLevel(0);
  393. camera.addEventListener(ActivityEvent.ACTIVITY,onACTIVITY)
  394. video.attachCamera(camera);
  395. }
  396. }
  397. //______________________________________________________________________________________________actions from pushbuttons
  398. private function onPost(e:Event):void
  399. {
  400. try{
  401. var message:Object = new Object();
  402. message.user = it_postingName.text
  403. message.text = it_postingMessage.text
  404. switch (e.target.label)
  405. {
  406. case 'post to all':
  407. group.post(message)
  408. break
  409. case 'sendToNeighbor':
  410. var a:String = group.sendToNearest(message, group.convertPeerIDToGroupAddress(otherIDs[l_otherID.selectedIndex]))
  411. info = a
  412. if (a == 'no route')
  413. {
  414. info = 'select other id first'
  415. }
  416. break
  417. }
  418. }catch(e:Error){}
  419. }
  420. private function onNetstream(e:Event):void
  421. {
  422. setup_groupspec()
  423. setup_group()
  424. setup_stream()
  425. }
  426. private function onWebcam(e:Event):void
  427. {
  428. setup_camera()
  429. }
  430. private function onBroadcast(e:Event):void
  431. {
  432. _broadcast()
  433. _broadcasting = true
  434. }
  435. private function onSubscribe(e:Event):void
  436. {
  437. _receive()
  438. _subsribed = true
  439. bmp_ruis_other.visible = false
  440. }
  441. private function onConnect(e:Event):void
  442. {
  443. var _url:String = it_protocol_server.text +'://'+ it_ip_server.text
  444. if (it_devkey_server.text.length > 2)
  445. {
  446. _url += '/'+ it_devkey_server.text
  447. }
  448. if (e.type != 'try again')
  449. {
  450. info = 'try to connect '+_url
  451. }
  452. else
  453. {
  454. info = 'trying AGAIN '+_url
  455. }
  456. nc = new NetConnection()
  457. nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus)
  458. nc.addEventListener(IOErrorEvent.IO_ERROR, netStatus_IO_ERROR)
  459. nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netStatus_SECURITY_ERROR)
  460. nc.connect(_url)
  461. }
  462. private function ondisConnect(e:Event):void
  463. {
  464. if (_webcam)
  465. {
  466. video.attachCamera(null)
  467. stream.attachCamera(camera);
  468. stream.close()
  469. }
  470. nc.close()
  471. }
  472. private function _broadcast():void
  473. {
  474. stream.attachCamera(camera);
  475. stream.publish(it_streamName.text);
  476. }
  477. private function _receive():void
  478. {
  479. stream.play(it_streamName.text);
  480. video.attachNetStream(stream);
  481. videoScreen_other.addChild(video)
  482. }
  483. private function onACTIVITY(e:ActivityEvent):void
  484. {
  485. if (e.activating == true)
  486. {
  487. camera.removeEventListener(ActivityEvent.ACTIVITY, onACTIVITY)
  488. videoScreen_local.addChild(video)
  489. _webcam = true
  490. bmp_ruis_local.visible = false
  491. btn_broadcast.visible = true
  492. btn_webcam.visible = false
  493. //_broadcast()
  494. }
  495. }
  496. //_________________________________________________________________________________________________EVENTS
  497. private function netStatus(e:NetStatusEvent):void
  498. {
  499. //NetStream.Play.Failed
  500. //info = 'net status'
  501. info = e.info.code
  502. switch (e.info.code)
  503. {
  504. case 'NetConnection.Connect.Failed':
  505. info = 'retrying soon'
  506. setTimeout(onConnect, 5000, new Event('try again'))
  507. break;
  508. case 'NetConnection.Connect.Success':
  509. _connected = btn_netstream.visible = true
  510. break;
  511. case 'NetConnection.Connect.Closed':
  512. _connected = _broadcasting = _subsribed = false;
  513. bmp_ruis_local.visible = bmp_ruis_other.visible = true
  514. btn_webcam.visible = btn_subscribe.visible = btn_broadcast.visible = false;
  515. btn_netstream.visible = false;
  516. break;
  517. case 'NetStream.Connect.Success':
  518. t_myID.text = nc.nearID
  519. btn_netstream.visible = false;
  520. info = 'camera ?' + String(_webcam)
  521. btn_webcam.visible = btn_subscribe.visible = true
  522. break;
  523. case 'NetStream.Connect.Success':
  524. break;
  525. case 'NetStream.Connect.Disconnect':
  526. break;
  527. case 'NetGroup.Posting.Notify':
  528. info = e.info.message.user +'> '+e.info.message.text
  529. break;
  530. case 'NetGroup.SendTo.Notify':
  531. info = e.info.message.user +'> '+e.info.message.text
  532. break;
  533. case 'NetGroup.Neighbor.Disconnect':
  534. update_otherIDS(e.info.peerID)
  535. l_otherID.items = otherIDs
  536. break;
  537. case 'NetGroup.Neighbor.Connect':
  538. otherIDs.push(e.info.peerID)
  539. l_otherID.items = otherIDs
  540. break;
  541. case 'NetStream.Publish.Start':
  542. btn_webcam.visible = btn_broadcast.visible = btn_subscribe.visible = false
  543. break;
  544. case 'NetStream.Play.Start':
  545. btn_webcam.visible = btn_broadcast.visible = btn_subscribe.visible = false
  546. break;
  547. case "NetGroup.Replication.Fetch.SendNotify": // e.info.index
  548. //info = ("____ index: "+e.info.index);
  549. break;
  550. case 'NetGroup.Replication.Fetch.Failed':
  551. info = 'NetGroup.Replication.Fetch.Failed'
  552. break;
  553. case "NetGroup.Replication.Request": // e.info.index, e.info.requestID
  554. group.writeRequestedObject(e.info.requestID,p2pSharedObject.chunks[e.info.index])
  555. //
  556. info = ("____ ID: "+e.info.requestID+", index: "+e.info.index);
  557. break;
  558. case "NetGroup.Replication.Fetch.Result": // e.info.index, e.info.object
  559. info = ("____ index: "+e.info.index);
  560. group.addHaveObjects(e.info.index,e.info.index);
  561. p2pSharedObject.chunks[e.info.index] = e.info.object;
  562. trace( e.info.object)
  563. info = 'fetch' + e.info.index
  564. if(e.info.index == 0){
  565. p2pSharedObject.packetLenght = Number(e.info.object);
  566. info = ("p2pSharedObject.packetLenght: "+p2pSharedObject.packetLenght);
  567. receiveObject(1);
  568. }else{
  569. if(e.info.index+1<p2pSharedObject.packetLenght){
  570. receiveObject(e.info.index + 1);
  571. }else{
  572. info = ("Receiving DONE" + p2pSharedObject.name);
  573. info = ("p2pSharedObject.packetLenght: "+p2pSharedObject.packetLenght);
  574. p2pSharedObject.data = new ByteArray();
  575. for(var i:int = 1;i<p2pSharedObject.packetLenght;i++){
  576. p2pSharedObject.data.writeBytes(p2pSharedObject.chunks[i]);
  577. }
  578. group.removeWantObjects(0,p2pSharedObject.packetLenght )
  579. trace(p2pSharedObject.name)
  580. fileShareComplete(p2pSharedObject.name)
  581. }
  582. }
  583. break;
  584. default:
  585. info = 'other'
  586. }
  587. }
  588. private function fileShareComplete(name:String):void{
  589. info = ("fileShareComplete" + name );
  590. var loader:Loader = new Loader()
  591. loader.unload();
  592. loader.loadBytes(p2pSharedObject.data);
  593. stage.addChild(loader)
  594. }
  595. private function receiveObject(index:Number):void{
  596. group.addWantObjects(index,index);
  597. p2pSharedObject.actualFetchIndex = index;
  598. }
  599. private function update_otherIDS(removeID:Object):void
  600. {
  601. var outputArray:Array = []
  602. for (var i:int = 0; i < otherIDs.length; i++)
  603. {
  604. if (otherIDs[i] != removeID)
  605. {
  606. outputArray.push(otherIDs[i])
  607. //otherIDs = otherIDs.splice(i, 1)
  608. }
  609. }
  610. otherIDs = outputArray
  611. }
  612. private function netStatus_SECURITY_ERROR(e:SecurityErrorEvent):void
  613. {
  614. info = String(e)
  615. info = 'netStatus_SECURITY_ERROR'
  616. }
  617. private function netStatus_IO_ERROR(e:IOErrorEvent):void
  618. {
  619. info = String(e)
  620. info = 'netStatus_IO_ERROR'
  621. }
  622. private function update(e:Event):void
  623. {
  624. //trace(e.target is CheckBox)
  625. }
  626. //_________________________________________________________________________________________________ GET SET
  627. public function set info(value:String):void
  628. {
  629. ta_info.text = value + '\n' + ta_info.text
  630. }
  631. }
  632. }