示例#1
0
 private void timerRTCSend_Tick(object sender, EventArgs e)
 {
     if (objpeer != null)
     {
         DllImport.DataChannelSendText(objpeer.peerconn, "Hello RTC Client," + send_test_num++ + ",socketId:" + cursocketId);
     }
 }
示例#2
0
 void OnRenderRemote(IntPtr yuv, int w, int h)
 {
     lock (staticform.pictureBoxRemote)
     {
         if (bgrBuffremote == null)
         {
             bgrBuffremote = new byte[w * 3 * h];
         }
         if (DllImport.EncodeI420toBGR24(yuv, w, h, bgrBuffremote, true) == 0)
         {
             if (remoteImg == null)
             {
                 var bufHandle = GCHandle.Alloc(bgrBuffremote, GCHandleType.Pinned);
                 remoteImg = new Bitmap((int)w, (int)h, (int)w * 3, PixelFormat.Format24bppRgb, bufHandle.AddrOfPinnedObject());
             }
         }
     }
     try
     {
         Invoke(renderRemote, this);
     }
     catch // don't throw on form exit
     {
     }
 }
示例#3
0
        void startPeerconn()
        {
            wsclient = new WebSocket("ws://" + exthost + ":9000");

            wsclient.OnOpen += (wsender, wse) =>
            {
                string smsg = JsonConvert.SerializeObject(new
                {
                    command = "__UserJoin",
                    udata   = new { UserID = UserID, Password = Password }
                });

                wsclient.Send(smsg);
            };
            wsclient.OnMessage += (wsender, wse) =>
            {
                Hashtable ht      = JsonConvert.DeserializeObject <Hashtable>(wse.Data);
                var       command = ht["command"].ToString();
                switch (command)
                {
                case "__OnLoginSuccessful":
                {
                    cursocketId = ht["socketId"].ToString();
                    createPeerConnection();
                }
                break;

                case "__OnError":
                {
                    this.BeginInvoke(new MethodInvoker(delegate()
                        {
                            label1.Text  = ht["info"].ToString();
                            button2.Text = "开启";
                        }));
                }
                break;

                case "__OnSuccessAnswer":
                {
                    DllImport.OnOfferReply(objpeer.peerconn, "answer", ht["sdp"].ToString());
                }
                break;

                case "__OnIceCandidate":
                {
                    if (ht["sdp"] == null || string.IsNullOrEmpty(ht["sdp"].ToString()))
                    {
                        break;
                    }
                    DllImport.AddIceCandidate(objpeer.peerconn, ht["sdp_mid"].ToString(), int.Parse(ht["sdp_mline_index"].ToString()), ht["sdp"].ToString());
                }
                break;
                }
            };
            wsclient.Connect();
        }
示例#4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            staticform           = this;
            _set_global_callback = set_global_callback;
            DllImport.set_global_callback(_set_global_callback);
            DllImport.InitWebRtc();

            startPeerconn();

            System.Windows.Forms.Timer timertcsend = new System.Windows.Forms.Timer();
            timertcsend.Interval = 1000;
            timertcsend.Tick    += timerRTCSend_Tick;
            timertcsend.Start();
        }
示例#5
0
        void createPeerConnection()
        {
            objpeer = new tagpeer();
            objpeer._OnRenderRemote = OnRenderRemote;

            objpeer.peerconn = DllImport.CreatPeerConnection(cursocketId, null, objpeer._OnRenderRemote, screenWidth, screenHeight);
            DllImport.AddServerConfig(objpeer.peerconn, StunIP1, "", "");
            DllImport.AddServerConfig(objpeer.peerconn, StunIP2, "", "");
            if (DllImport.StartPeerConnection(objpeer.peerconn))
            {
                DllImport.CreateDataChannel(objpeer.peerconn, string.Empty);

                DllImport.CreateOffer(objpeer.peerconn);
            }
        }
示例#6
0
 private void button2_Click(object sender, EventArgs e)
 {
     wsclient.Close();
     if (button2.Text == "关闭")
     {
         if (objpeer != null)
         {
             DllImport.StopPeerConnection(objpeer.peerconn);
         }
         objpeer      = null;
         button2.Text = "开启";
     }
     else
     {
         startPeerconn();
         button2.Text = "关闭";
     }
 }
示例#7
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     wsclient.Close();
     DllImport.UninitWebRtc();
 }