Red5 video chat sorting and release

Source: Internet
Author: User

When I wrote this code, I was just a newbie, so I forgot to add the comments. I barely read the code again. Some of them may not be easy to understand and offend me. A friend has gone to my space to ask for code. I can only say sorry here. I only saw your application today. It has been several years.

Red5 video chat (server) package red5.example. red5server; import Java. util. collection; import Java. util. hashmap; import Java. util. map; import Org. red5.server. adapter. applicationadapter; import Org. red5.server. API. iconnection; import Org. red5.server. API. iseries; import Org. red5.server. API. service. iservicecapableconnection; import Org. red5.server. API. so. isharedobject; import COM. makefriend. entity. userinfo; import COM. ma Kefriend. service. userinfoservice; import COM. makefriend. service. impl. userinfoserviceimpl; public class application extends applicationadapter {private iscope appscope cope; private string username; private isharedobject listso; private isharedobject msgso; private Map <string, iconnection> onlineclient = new hashmap <string, iconnection> (); @ override public Boolean appstart (isincluscope) {If (! Super. appstart (scope) {return false;} specify criteria = scope; return true;} @ override public Boolean appconnect (iconnection Conn, object [] Params) {system. out. println ("red5server -- a client needs to establish a connection... "); username = (string) Params [0]; userinfoservice userinfoserver = new userinfoserviceimpl (); userinfo user = userinfoserver. getuserinfo (username); If (user = NULL) {return false;} If (! User. getuserpassword (). equals (Params [1]. tostring () {return false;} string link_id = Conn. getclient (). GETID (); onlineclient. put (username, Conn); listso = getdomaindobject (response failed, "listso", false); msgso = getdomaindobject (response failed, "msgso", false); listso. setattribute (link_id, username); Return true;}/*** message group ** @ Param MSG */Public void broadcastusermsg (string MSG) {msgso. setattribute ("MSG", MSG); collection <iconnection> cons = onlineclient. values (); For (iconnection I: cons) {iservicecapableconnection Ic = (iservicecapableconnection) I; IC. invoke ("showmsgbyprivate", new object [] {MSG });}} /*** private chat information ** @ Param MSG * @ Param from * @ Param to */@ suppresswarnings ("unchecked") Public void msgfromprivate (string MSG, string from, string to) {iservicecapableconnection fc = (iservicecapableconnection) onlineclient. get (from); iservicecapableconnection Tc = (iservicecapableconnection) onlineclient. get (to); FC. invoke ("showmsgbyprivate", new object [] {MSG}); TC. invoke ("showmsgbyprivate", new object [] {MSG}) ;}@ override public void appdisconnect (iconnection conn) {system. out. println ("red5server -- client disconnected... "); string dis_link_id = Conn. getclient (). GETID (); string user = (string) listso. getattribute (dis_link_id); onlineclient. remove (User); listso. removeattribute (dis_link_id); super. appdisconnect (conn );}}

Let's just say a few words. This technology was implemented a few years ago when I was bored. It has been a while, and many things do not remember. At that time, I was just a newbie. I was very proud to post but didn't send code. I am very sorry for this. Today I have sorted it out and put all the source code out, something bad to write, hopefully, everyone should feel this way. It's hard to read the previous code!

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

This version is only a basic implementation function, and there is no beautification on the interface, but it should be easy to understand. You can see it for yourself.



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.