Exemple #1
0
        public async Task Run()
        {
            string header = "HTTP/1.1 200 OK\r\n" +
                            $"Content-Type: multipart/x-mixed-replace; boundary={Boundary}\r\n" +
                            "Server: LibMJPEGStreamer\r\n";

            try
            {
                TargetClient.Send(Encoding.UTF8.GetBytes(header));

                while (_streamActive)
                {
                    _newFrameAvailableEvent.WaitOne();
                    _newFrameAvailableEvent.Reset();

                    if (!_streamActive)
                    {
                        break;
                    }

                    await SendFrame();
                }
            }
            catch
            {
                // Shit happens...
                // Client probably disconnected.
            }
        }
Exemple #2
0
        //first recieve fails not sure why
        private void Receive()
        {
            socket.BeginReceiveFrom(PacketBuffer, 0, BufferSize, SocketFlags.None, ref ClientEndpoint, AsReceive = (ar) =>
            {
                AsyncBuffer so = (AsyncBuffer)ar.AsyncState;
                int bytes      = socket.EndReceiveFrom(ar, ref ClientEndpoint);
                socket.BeginReceiveFrom(so.Buffer, 0, BufferSize, SocketFlags.None, ref ClientEndpoint, AsReceive, so);
                byte[] tempBuff = new byte[bytes];
                Array.Copy(so.Buffer, 0, tempBuff, 0, tempBuff.Length);

                Client TargetClient = null;
                //Check if client is already connected
                if (ConnectedClients.Where(x => x.endPoint.Equals(ClientEndpoint)).Count() == 0)
                {
                    Console.WriteLine("New client connected " + ClientEndpoint.ToString());
                    TargetClient = new Client(ClientEndpoint);
                    ConnectedClients.Add(TargetClient);
                }
                else
                {
                    TargetClient = ConnectedClients.Where(x => x.endPoint.Equals(ClientEndpoint)).First();
                }

                Packet packet = new Packet(tempBuff);
                if (packet.IsValid)
                {
                    Console.WriteLine("Recieved " + packet.ToString());
                    socket.SendTo(TargetClient.HandlePacket(packet), ClientEndpoint);
                }
            }, AsBuffer);
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Sync app");

            using var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder.AddSimpleConsole(options => options.TimestampFormat = "hh:mm:ss ");
                builder.SetMinimumLevel(LogLevel.Debug);
            });
            logger = loggerFactory.CreateLogger <ProgramSync>();

            // Initialize the SDK

            var targetClientConfig = new TargetClientConfig.Builder("adobetargetmobile", "B8A054D958807F770A495DD6@AdobeOrg")
                                     .SetLogger(logger)
                                     .SetDecisioningMethod(DecisioningMethod.OnDevice)
                                     .SetOnDeviceDecisioningReady(DecisioningReady)
                                     .SetArtifactDownloadSucceeded(artifact => Console.WriteLine("ArtifactDownloadSucceeded: " + artifact))
                                     .SetArtifactDownloadFailed(exception => Console.WriteLine("ArtifactDownloadFailed " + exception.Message))
                                     .Build();

            targetClient = TargetClient.Create(targetClientConfig);

            // sample server-side GetOffers call

            var deliveryRequest = new TargetDeliveryRequest.Builder()
                                  .SetDecisioningMethod(DecisioningMethod.ServerSide)
                                  .SetThirdPartyId("testThirdPartyId")
                                  .SetContext(new Context(ChannelType.Web))
                                  .SetExecute(new ExecuteRequest(null, new List <MboxRequest>
            {
                new (index: 0, name: "a1-serverside-ab")
            }))
Exemple #4
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Sync app");

            using var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder.AddSimpleConsole(options => options.TimestampFormat = "hh:mm:ss ");
                builder.SetMinimumLevel(LogLevel.Debug);
            });
            var logger = loggerFactory.CreateLogger <ProgramSync>();

            var targetClientConfig = new TargetClientConfig.Builder("adobetargetmobile", "B8A054D958807F770A495DD6@AdobeOrg")
                                     .SetLogger(logger)
                                     .SetDecisioningMethod(DecisioningMethod.OnDevice)
                                     .SetOnDeviceDecisioningReady(DecisioningReady)
                                     .SetArtifactDownloadSucceeded(artifact => Console.WriteLine("ArtifactDownloadSucceeded: " + artifact))
                                     .SetArtifactDownloadFailed(exception => Console.WriteLine("ArtifactDownloadFailed " + exception.Message))
                                     .Build();

            targetClient = TargetClient.Create(targetClientConfig);

            Thread.Sleep(3000);
        }
Exemple #5
0
        private async Task SendFrame()
        {
            if (_lastQuality <= 0)
            {
                _lastQuality = Encoder.GetQuality();
            }

            MemoryStream frameStream = await Encoder.GetCurrentFrame(_lastQuality);

            string header = $"\r\n{Boundary}\r\n" +
                            "Content-Type: image/jpeg\r\n" +
                            $"Content-Length: {frameStream.Length}\r\n\r\n";

            _stopwatch.Restart();
            {
                TargetClient.Send(Encoding.UTF8.GetBytes(header));
                TargetClient.Send(frameStream);
                TargetClient.Send(Encoding.UTF8.GetBytes("\r\n"));
            }
            _stopwatch.Stop();

            int nextTransmissionTime = (int)_stopwatch.ElapsedMilliseconds;

            if (_lastTransmissionTimes.Count >= TransmissionUpdateCount)
            {
                _lastQuality = Encoder.GetQuality(_lastQuality, (int)_lastTransmissionTimes.Average());
                _lastTransmissionTimes.Clear();
            }

            // 1000 FPS ist good enough...
            if (nextTransmissionTime <= 0)
            {
                nextTransmissionTime = 1;
            }

            _lastTransmissionTimes.Add(nextTransmissionTime);
        }
Exemple #6
0
        public ParamsCollatorsShould()
        {
            var targetClientConfig = new TargetClientConfig.Builder(testClientId, testOrgId).Build();

            _ = TargetClient.Create(targetClientConfig);
        }
Exemple #7
0
        public TargetDeliveryRequestBuildShould()
        {
            var targetClientConfig = new TargetClientConfig.Builder(testClientId, testOrgId).Build();

            _ = TargetClient.Create(targetClientConfig);
        }
 public ClientEvent(TargetClient target, string eventName, object arguments = null)
 {
     Target    = target;
     EventName = eventName;
     Arguments = arguments;
 }
Exemple #9
0
        /// <summary>
        /// 数据接收
        /// </summary>
        /// <param name="connection"></param>
        private void ReceiveCallback(IAsyncResult result)
        {
            try
            {
                Socket connection = result.AsyncState as Socket;
                int    length     = 0;
                if (CheckConnection(connection))
                {
                    //(主动)终止通话
                    if (Manager.Stopped)
                    {
                        //终止录音 音频输出
                        Manager.StopRecord();
                        //防止已经启用的Available事件继续Send导致服务端异常关闭
                        TargetClient.Shutdown(SocketShutdown.Send);
                        Thread.Sleep(200);
                        //接收残余数据
                        length = connection.EndReceive(result);
                        TargetClient.Shutdown(SocketShutdown.Receive);
                    }
                    else
                    {
                        //接收数据
                        length = connection.EndReceive(result);
                        Manager.AcceptStream(length);
                        Log.WriteLog("客户{1}已接收{0}位数据", Manager.RStream.Length, Name);
                    }
                    //(主动)终止通话
                    if (Manager.Stopped)
                    {
                        Log.WriteLog("{0}:(主动)终止通话", Name);
                        OnActiveAudioRejected(TargetName);

                        CloseTargetConnection();
                        return;
                    }
                }
                //(被动)终止通话
                if (length != 0)
                {
                    connection.BeginReceive(Manager.BufferReceived, 0, Manager.BufferReceived.Length, SocketFlags.None, ReceiveCallback, connection);
                }
                else
                {
                    Log.WriteLog("{0}:(被动)终止通话", Name);
                    OnPassiveAudioRejected(TargetName);
                    //Stop();
                    Manager.Stopped = true;
                    Manager.StopRecord();
                    CloseTargetConnection();
                }
            }
            catch (Exception ex)
            {
                Log.WriteLog(ex.ToString());
                Log.WriteLog("{0}:(被动)异常终止通话", Name);
                OnPassiveAudioRejected(TargetName);
                //Stop();
                Manager.Stopped = true;
                Manager.StopRecord();
                CloseTargetConnection();
            }
        }
 public MovieService(IMovieRepository movieRepository, IMessagePublisher messagePublisher, TargetClient targetClient)
 {
     _movieRepository   = movieRepository;
     _messagePublisher  = messagePublisher;
     this._targetClient = targetClient;
 }
 /// <summary>
 /// Converts a WMQ target client to the equivalent XMS value.
 /// </summary>
 /// <param name="inputValue">Input value.</param>
 /// <returns>Converted value.</returns>
 public static Int32 ToXMSTargetClient(TargetClient inputValue)
 {
     return((Int32)inputValue);
 }