Video chat source code (simplified version [on ])

Source: Internet
Author: User

After a period of research, video chat has finally come to an end today. I am sending a Code <br/> <? XML version = "1.0" encoding = "UTF-8"?> <Br/> <s: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" <br/> xmlns: S = "Library: // ns.adobe.com/flex/spark" <br/> xmlns: MX = "Library: // ns.adobe.com/flex/mx" width = "800" Height = "600" creationcomplete = "Init ()"> <br/> <s: layout> <br/> <s: basiclayout/> <br/> </S: layout> <br/> <FX: declarations> <br/> <! -- Place non-visual elements (such as services and value objects) Here --> <br/> </FX: declarations> <br/> <FX: SCRIPT> <br/> <! -- [CDATA [<br/> Import MX. collections. arraycollection; <br/> Import MX. collections. ilist; <br/> Import MX. collections. xmllistcollection; <br/> Import MX. controls. alert; </P> <p> private var IP: string; <br/> private var Redpath: string; <br/> private var NC: netconnection; <br/> private var ns: netstream; <br/> private var NS2. <br/> private var cam: Camera <br/> private var mic: microphone; <br/> Private var listso: Empty dobject; <br/> private var msgso: Empty dobject; <br/> [Bindable] <br/> private var userarr: arraycollection; <br/> private var sendmsg: string; <br/> private var now: date; <br/> private var useridobj: object; <br/> private var video: video; </P> <p> private function Init (): void {<br/> IP = "192.168.1.100"; <br/> Redpath = "rtmp: // "+ IP +"/makefriend "; <br/> NC = new netconnection (); <br /> Now = new date (); <br/> main. visible = false; <br/> login. visible = true; <br/> userlist. visible = true; <br/> chatvideo. visible = false; </P> <p >}</P> <p> private function startconnect (): void {<br/> NC. addeventlistener (netstatusevent. net_status, statushandler); <br/> NC. addeventlistener (securityerrorevent. security_error, securityhandler); <br/> NC. addeventlistener (asyncerrorevent. async_error, asynchandler); <Br/> NC. connect (Redpath, username. text, userpwd. text); <br/> NC. client = This; <br/>}</P> <p> private function statushandler (E: netstatusevent): void {<br/> If (e.info. code = "netconnection. connect. success ") {<br/> alert. show ("Logon successful"); <br/> login. visible = false; <br/> main. visible = true; <br/> publishvideo (); <br/> setlistso (); <br/> setmsgso (); <br/> btnsend. addeventlistener (mouseevent. click, sendbtnbyclic K); <br/> main. addeventlistener (keyboardevent. key_down, sendbtnbykey); <br/>}< br/> If (e.info. code = "netconnection. connect. failed ") <br/>{< br/> alert. show ("connection failed"); <br/>}< br/> If (e.info. code = "netconnection. connect. closed ") <br/>{< br/> alert. show ("the account password is incorrect. Please enter it again !!! "); <Br/>}</P> <p> private function securityhandler (E: securityerror): void {<br/> alert. show ("low-key security sandbox error"); <br/>}</P> <p> private function asynchandler (E: asyncerrorevent): void {<br/> alert. show ("low-key asynchronous error"); <br/>}</P> <p> private function publishvideo (): void {<br/> NS = new netstream (NC); <br/> cam = camera. getcamera (); <br/> MIC = microphone. getmicrophone (); <br/> myvideo. attachcamera (CAM); <br/> NS. client = This; <br/> ns. addeventlistener (netstatusevent. net_status, statushandler); <br/> ns. addeventlistener (asyncerrorevent. async_error, asynchandler); <br/> ns. attachcamera (CAM); <br/> ns. attachaudio (MIC); <br/> ns. publish (username. text, "live"); <br/>}</P> <p> private function setlistso (): void {<br/> listso = sharedobject. getremote ("listso", NC. uri, false); <br/> listso. connect (NC); <br/> listso. add Eventlistener (syncevent. sync, listsosynchandler); <br/>}</P> <p> private function setmsgso (): void {<br/> msgso = synchronized dobject. getremote ("msgso", NC. uri, false); <br/> msgso. addeventlistener (syncevent. sync, msgsosynchandler); <br/> msgso. connect (NC); <br/>}< br/> private function msgsosynchandler (): void {<br/> for (var I in msgso. data) {<br/> txtmessage. TEXT = txtmessage. text + msgso. data [I]; <br/>} <Br/>}</P> <p> private function listsosynchandler (E: syncevent): void {<br/> showuserlist (); <br/> userlist. addeventlistener (mouseevent. click, updatechatto); <br/> userlist. addeventlistener (mouseevent. double_click, updatevideoshow); <br/>}</P> <p> private function showuserlist (): void {<br/> userarr = new arraycollection (); <br/> for (var tmp in listso. data) {<br/> userarr. additem (listso. data [TMP]); <br />}< Br/> userarr. additemat ("all", 0); </P> <p> This. userlist. dataprovider = userarr; <br/>}</P> <p> private function updatechatto (E: mouseevent): void {<br/> main. title = "you are working with" + userlist. selecteditem + "chatting"; <br/>}</P> <p> private function updatevideoshow (E: mouseevent): void {<br/> If (userlist. selecteditem = "all" | userlist. selecteditem = "") <br/>{< br/> alert. show ("You cannot have a video chat with everyone. "); <Br/> return; <br/>}< br/> userlist. visible = false; <br/> chatvideo. visible = true; <br/> Video = new video (); <br/> int32 = new netstream (NC); <br/> ns2.addeventlistener (netstatusevent. net_status, statushandler); <br/> ns2.addeventlistener (asyncerrorevent. async_error, asynchandler); <br/> ns2.play (userlist. selecteditem); <br/> ns2.client = This; </P> <p> video. attachnetstream (NS2.); <br/> video. width = 288; <B R/> video. height = 218; </P> <p> chatvideo. addchild (video); <br/> chatvideo. play (); </P> <p >}</P> <p> private function sendbtnbyclick (E: mouseevent): void {<br/> sendmsge (); <br/>}</P> <p> private function sendbtnbykey (E: keyboardevent): void {<br/> If (E. keycode = keyboard. enter & E. ctrlkey = true) <br/>{< br/> sendmsge (); <br/>}</P> <p> private function sendmsge (): void {<br/> var mess: String = usernam E. text + "said:" + sendmessage. text + "/R/N"; <br/> If (username. TEXT = userlist. selecteditem) {<br/> alert. show ("You cannot chat with yourself, please change the chat object again"); <br/> return; <br/>}</P> <p> If (sendmessage. TEXT = "") {<br/> alert. show ("The message cannot be blank"); <br/> return; <br/>}< br/> If (userlist. selecteditem = "all") {<br/> NC. call ("broadcastusermsg", null, Mess); <br/> sendmessage. TEXT = ""; <br/> return; <br/>}< br/> If (userlist. selecteditem! = NULL) {<br/> NC. call ("msgfromprivate", null, mess, username. text, userlist. selecteditem); <br/> sendmessage. TEXT = ""; <br/>}</P> <p> Public Function showmsgbyprivate (MSG: string): void {<br/> txtmessage. TEXT = txtmessage. text + MSG; <br/>}< br/>] --> <br/> </FX: SCRIPT> <br/> <s: panel id = "login" Title = "welcome to visit" width = "100%" Height = "100%"> <br/> <s: label x = "381" Y = "109" text = "" width = "192" Height = "35" fontsize = "25" verticalalalign = "Middle" textalign =" center "fontweight =" normal "fontstyle =" normal "/> <br/> <s: label x = "353" Y = "167" text = "username: "width =" 73 "Height =" 24 "verticalalign =" Middle "fontsize =" 16 "/> <br/> <s: label x = "353" Y = "212" text = "password: "width =" 73 "Height =" 24 "verticalalign =" Middle "fontsize =" 16 "/> <br/> <s: textinput id = "username" x = "446" Y = "168" width = "154" textalign = "Left" maxchars = "18"/> <br/> <s: textinput id = "userpwd" x = "445" Y = "214" width = "154" textalign = "Left" displayaspassword = "true" maxchars = "18"/> <br /> <s: button x = "373" Y = "257" label = "login" id = "btnsub" Click = "startconnect ()"/> <br/> <s: button x = "501" Y = "257" label = "cancel" id = "cancel" Click = "navigatetoURL (New URLRequest ('javascript: window. close () '),' _ Self ') "/> <br/> </S: Panel> <br/> <s: panel id = "Main" width = "100%" Height = "100%"> <br/> <mx: videodisplay id = "myvideo" x = "468" Y = "276" width = "288" Height = "217"/> <br/> <s: group x = "468" Y = "24" width = "288" Height = "218"> <br/> <mx: videodisplay id = "chatvideo" width = "100%" Height = "100%"/> <br/> <s: list id = "userlist" width = "100%" Height = "100%" doubleclickenabled = "true" DoubleClick = "updatevideoshow (event)"/> <br/> </s: group> <br/> <s: button id = "btnsend" x = "279" Y = "519" label = "send"/> <br/> <s: textarea enabled = "false" id = "txtmessage" x = "46" Y = "26" width = "402" Height = "292"/> <br/> <s: textarea id = "sendmessage" x = "47" Y = "348" width = "397" Height = "145"/> <br/> <s: button id = "btnexit" x = "374" Y = "519" label = "quit"/> <br/> </s: panel> </P> <p> </S: Application>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.