📄 messageform.cs
字号:
#if Test
this.history.SelectedText="你说:";
#else
this.history.SelectedText="你"+"说:";
#endif
this.history.SelectionColor=c;
this.history.Select(this.history.Text.Length,0);
string rtf=se.Rtf.Substring(0,se.Rtf.LastIndexOf("}"));
this.history.SelectedRtf=rtf;
this.history.ScrollToEnd();
#if !Test
mm.SendMessage(this.itm.Jid,null,se.Text,rtf,null,gowk.core.packets.PacketType.chat);
#endif
}
#region mm
private void mm_ChatMessageReceived(JabberEventArgs e)
{
this.OnChatMessageReceived(e);
}
public void OnChatMessageReceived(JabberEventArgs e)
{
gowk.core.packets.Message msg=(gowk.core.packets.Message)e.Packet;
if(msg.From==null)return;
if(!gowk.core.Jid.Equals(msg.From,this.itm.Jid,false))return;
this.history.Select(this.history.Text.Length,0);
Color c=this.history.SelectionColor;
// Font f=this.history.SelectionFont;
this.history.SelectionColor=Color.Blue;
this.history.SelectedText=this.itm.Name+"说:";
this.history.SelectionColor=c;
if(msg.Rtf!=null)
{
string rtf=msg.Rtf;
this.history.Select(this.history.Text.Length,0);
this.history.SelectedRtf=rtf;
}
else
{
this.history.Text+=msg.Body;
}
this.history.ScrollToEnd();
}
private void mm_ChatMessageError(JabberEventArgs e)
{
}
private void mm_HeadLineMessageReceived(JabberEventArgs e)
{
}
#endregion
private void gButton1_Click(object sender, System.EventArgs e)
{
this.RequestVideoChat();
}
#region av
private void AckResponse(gowk.core.packets.Message.videochat vc)
{
if(vc.ok)
{
if(this.avf!=null)
{
try
{
this.avf.Connect(vc.ip,vc.port);
}
catch(System.Exception ex)
{
System.Diagnostics.Debug.Assert(false,ex.Message,ex.StackTrace);
}
}
else
{
this.mm.EndVideoChat(this.itm.Jid);
}
}
else if(this.avf!=null)
{
this.Notify("info.gif","对方拒绝了您的请求");
this.avf.Close();
}
}
private void AckRequest(gowk.core.packets.Message.videochat vc)
{
Color c=this.history.SelectionColor;
this.history.Select(this.history.Text.Length,0);
this.history.SelectedText="\n";
this.history.InsertImage(new Bitmap(this.GetType(),"info.gif"));
this.history.SelectionColor=Color.LightBlue;
this.history.SelectedText=this.itm.Name+" 请求与您进行视频连接,您是要";
this.history.InsertLink("accept","videoresponse"+vc.ip+":"+vc.port.ToString());
this.history.SelectionColor=Color.LightBlue;
this.history.SelectedText="还是";
this.history.InsertLink("cancel","videoresponse");
this.history.SelectionColor=Color.LightBlue;
this.history.SelectedText="该邀请";
this.history.SelectionColor=c;
this.history.SelectedText="\n";
this.history.ScrollToEnd();
// this.IniAVChat();
}
private void DeleteLink()
{
this.history.Rtf=this.history.Rtf;
this.history.ScrollToEnd();
}
private void AckEnd(gowk.core.packets.Message.videochat vc)
{
this.DeleteLink();
this.Notify("info.gif","对方请求断开连接");
}
public void ResponseVideoChat(gowk.core.packets.Message msg)
{
gowk.core.packets.Message.videochat vc=msg.VideoChat;
switch(vc.type)
{
case gowk.core.packets.Message.VideoChatType.response:
this.AckResponse(vc);
break;
case gowk.core.packets.Message.VideoChatType.request:
this.AckRequest(vc);
break;
case gowk.core.packets.Message.VideoChatType.end:
this.AckEnd(vc);
break;
}
}
public void RequestVideoChat()
{
Color c=this.history.SelectionColor;
this.history.Select(this.history.Text.Length,0);
this.history.InsertImage(new Bitmap(this.GetType(),"info.gif"));
this.history.SelectionColor=Color.LightBlue;
#if !Test
this.history.SelectedText=" 您已经请求与"+this.itm.Name+"进行视频对话。请等待回应或 ";
#endif
this.history.InsertLink("cancel","videorequest");
this.history.SelectionColor=Color.LightBlue;
this.history.SelectedText="该未决的邀请";
this.history.SelectionColor=c;
this.history.SelectedText="\n";
this.history.ScrollToEnd();
this.IniAVChat();
#if !Test
System.Net.IPAddress ad=gowk.utility.net.Address.GetExternalIPAddress();
if(ad==null)
{
this.Notify("info.gif","找不到外部网络地址!连接很可能不能建立!");
ad=gowk.utility.net.Address.GetFirstIPAddress();
}
this.mm.RequestVideoChat(this.itm.Jid,null,ad.ToString(),this.avf.AV.AVChanel.LocalPort);
#endif
}
public void Notify(string icon,string message)
{
Color c=this.history.SelectionColor;
this.history.Select(this.history.Text.Length,0);
if(icon!=null)this.history.InsertImage(new Bitmap(this.GetType(),icon));
this.history.SelectionColor=Color.LightBlue;
this.history.SelectedText=message;
this.history.SelectionColor=c;
this.history.SelectedText="\n";
this.history.ScrollToEnd();
}
private void mm_VideoChatReceived(JabberEventArgs e)
{
this.ResponseVideoChat((gowk.core.packets.Message)e.Packet);
}
private void avf_Closed(object sender, EventArgs e)
{
this.DeleteLink();
this.avf=null;
}
private void IniAVChat()
{
if(this.avf!=null)
{
this.avf.Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();
this.avf=null;
}
this.avf=new AVForm(this);
this.avf.Closed+=new EventHandler(avf_Closed);
this.avf.Location=new Point(this.Right,this.Top);
this.avf.Initialize();
this.avf.AV.AVChanel.StreamEnd+=new gowk.multimedia.AVChanel.AVChanelEventHandler(AVChanel_StreamEnd);
this.avf.AV.AVChanel.StreamError+=new gowk.multimedia.AVChanel.AVChanelEventHandler(AVChanel_StreamError);
avf.Show();
}
private void AVChanel_StreamEnd(object sender, gowk.multimedia.AVChanel.AVChanelEventArgs e)
{
this.Notify("info.gif","和对方的连接已经断开");
if(this.avf!=null)
{
this.avf.Close();
}
}
private void AVChanel_StreamError(object sender, gowk.multimedia.AVChanel.AVChanelEventArgs e)
{
this.Notify("info.gif","网络错误或对方关闭连接,将断开和对方的联接");
if(this.avf!=null)
{
this.avf.Close();
}
}
#endregion
private void history_LinkClicked(object sender, LinkClickedEventArgs e)
{
//////////////////////////////
this.DeleteLink();
///////////////////////////////
string link=e.LinkText.Trim();
if(link.IndexOf("cancel#videorequest")!=-1)
{
this.mm.EndVideoChat(this.itm.Jid);
if(this.avf!=null)
{
this.avf.Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();
this.avf=null;
}
}
else if(link.IndexOf("cancel#videoresponse")!=-1)
{
this.mm.ResponseVideoChat(this.itm.Jid,false,null,null,0);
}
else
{
int index=link.IndexOf("accept#videoresponse");
if(index>-1)
{
this.IniAVChat();
System.Net.IPAddress ad=gowk.utility.net.Address.GetExternalIPAddress();
if(ad==null)
{
this.Notify("info.gif","找不到外部网络地址!连接很可能不能建立!");
ad=gowk.utility.net.Address.GetFirstIPAddress();
}
this.mm.ResponseVideoChat(this.itm.Jid,true,null,ad.ToString(),this.avf.AV.AVChanel.LocalPort);
index+="accept#videoresponse".Length;
string ip_port=link.Substring(index);
int split=link.IndexOf(":");
string ip=link.Substring(index,split-index);
int port=int.Parse(link.Substring(split+1));
this.avf.Connect(ip,port);
}
}
}
#region history
System.Timers.Timer tmr1=new System.Timers.Timer(50);
System.Timers.Timer tmr2=new System.Timers.Timer(50);
private void gButton3_Click(object sender, System.EventArgs e)
{
API.SendMessage(this.history.Handle,API.WM_VSCROLL,API.SB_LINEDOWN,0);
}
private void gButton2_Click(object sender, System.EventArgs e)
{
API.SendMessage(this.history.Handle,API.WM_VSCROLL,API.SB_LINEUP,0);
}
private void InitializeTimers()
{
tmr1.Elapsed+=new System.Timers.ElapsedEventHandler(tmr1_Elapsed);
tmr2.Elapsed+=new System.Timers.ElapsedEventHandler(tmr2_Elapsed);
}
private void gButton2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
tmr1.Enabled=true;
}
private void tmr1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
API.SendMessage(this.history.Handle,API.WM_VSCROLL,API.SB_LINEUP,0);
}
private void tmr2_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
API.SendMessage(this.history.Handle,API.WM_VSCROLL,API.SB_LINEDOWN,0);
}
private void gButton3_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
tmr2.Enabled=true;
}
private void gButton3_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
tmr2.Enabled=false;
}
private void gButton2_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
tmr1.Enabled=false;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -