Beispiel #1
0
		public void Attach(FM.IceLink.Conference conference, Action<Exception> callback)
		{
			try {
				this.Conference = conference;

				conference.OnLinkOfferAnswer += (e) =>
				{
					try {
						Signal signal = new Signal();
						signal.PeerId = e.PeerId;
						signal.DataJson = e.OfferAnswer.ToJson();
						#if USE_TCP_SIGNALLING
							TCPSender<Signal> sender = new TCPSender<Signal> ();
							if (sender.Connect (IPAddress, TCP_PORT_SIGNALLING)) {
								sender.Send (TCP_MESSAGE_OFFER_ANSWER, signal);
								sender.Disconnect ();
							}
						#else
							UDPSender<Signal> sender = new UDPSender<Signal>();
							sender.Send(TCP_MESSAGE_OFFER_ANSWER,signal,this.IPAddress,TCP_PORT_SIGNALLING);
						#endif

					}
					catch (Exception ex)
					{
						Console.WriteLine(ex.Message);
					}
						
				};
				conference.OnLinkCandidate += (e) =>
				{
					try {
						Signal signal = new Signal();
						signal.PeerId = e.PeerId;
						signal.DataJson = e.Candidate.ToJson();
						#if USE_TCP_SIGNALLING
							TCPSender<Signal> sender = new TCPSender<Signal> ();
							if (sender.Connect (IPAddress, TCP_PORT_SIGNALLING)) {
								sender.Send (TCP_MESSAGE_CANDIDATE, signal);
								sender.Disconnect ();
							}
						#else
							UDPSender<Signal> sender = new UDPSender<Signal>();
							sender.Send(TCP_MESSAGE_CANDIDATE,signal,this.IPAddress,TCP_PORT_SIGNALLING);
						#endif


					}
					catch (Exception ex)
					{
						Console.WriteLine(ex.Message);
					}
						
				};					
			}
			catch (Exception ex)
			{
				callback(ex);
			}
		}
		// Message // // // // // // // // // // // // // // // // // // // // // // // //  // // // // // // //

		// sends a chat message
		public bool SendChatMessage(string guid, string serverIPAddress, string text)
		{		
			if (Logging) {
				Database.Instance().SaveLog("Chat - SendChatMessage() " + serverIPAddress);
			}

			MessageChat m = new MessageChat ();
			m.Guid = guid;
			m.Text = text;

			TCPSender<MessageChat> sender = new TCPSender<MessageChat> ();
			if (sender.Connect (serverIPAddress, TCP_PORT_LISTENER)) {
				bool sent = sender.Send (TCP_MESSAGE_CHAT, m);
				sender.Disconnect ();
				return sent;
			}

			return false;
		}
		public bool SendVideoChatRefused(string guid, string serverIPAddress)
		{		
			MessageVideoRequest m = new MessageVideoRequest ();
			bool retVal = false;

			TCPSender<MessageVideoRequest> sender = new TCPSender<MessageVideoRequest> ();
			if (sender.Connect (serverIPAddress, TCP_PORT_LISTENER)) {
				if (sender.Send (TCP_MESSAGE_REFUSED_VIDEO_CHAT, m)) {
					retVal = true;									
					sender.Disconnect ();
				}
			}

			return retVal;
		}
		// send my profile to ip
		public void SendMyProfile(string serverIPAddress, bool includepic, int port)
		{
			if (Logging) {
				Database.Instance ().SaveLog ("Profile - SendMyProfile() " + serverIPAddress);// + ":" + port.ToString ());
			}

			MessageProfile m = new MessageProfile();
			m.Guid = MyProfile.Guid;
			m.Version = MyProfile.Version;
			m.PicVersion = MyProfile.PicVersion;
			m.Name = MyProfile.Name;
			m.Gender = MyProfile.Gender;
			m.ToMeet = MyProfile.ToMeet;
			m.Status = MyProfile.Status;
			if (includepic) {
				m.Big = MyPicture.Big;	
				m.Small = MyPicture.Small;
			}

			TCPSender<MessageProfile> sender = new TCPSender<MessageProfile> ();
			if (sender.Connect (serverIPAddress, TCP_PORT_LISTENER)) {
				sender.Send (TCP_PROFILE_MESSAGE, m);
				sender.Disconnect ();
			}

		}