Exemple #1
0
        internal DisconnectResult ProcessDisconnect(NetPacket packet)
        {
            switch (_connectionState)
            {
            case ConnectionState.Connected:
            case ConnectionState.InProgress:
                if (packet.Size >= 9 &&
                    BitConverter.ToInt64(packet.RawData, 1) == _connectId &&
                    packet.ConnectionNumber == _connectNum)
                {
                    DisconnectResult result = _connectionState == ConnectionState.Connected
                            ? DisconnectResult.Disconnect
                            : DisconnectResult.Reject;

                    _connectionState = ConnectionState.Disconnected;
                    return(result);
                }
                break;
            }
            return(DisconnectResult.None);
        }
Exemple #2
0
        // This is executed in a new thread each time, so it is safe to use blocking calls
        protected override void Ready()
        {
            // Create the first outbound call leg to the inbound DID associated to the context this client is receiving
            // This will block until the call is answered, times out, busy, or an error occurred
            DialResult resultDial = Client.Calling.DialSip(ToSip, FromSip);

            if (!resultDial.Successful)
            {
                Logger.LogError("Call1 was not answered");
                Completed.Set();
                return;
            }

            // The call was answered, try to connect another outbound call to it
            // The top level list of the devices represents entries that will be called in serial,
            // one at a time.  The inner list of devices represents a set of devices to call in
            // parallel with each other.  Ultimately only one device wins by answering first.
            ConnectResult resultConnect = resultDial.Call.Connect(new List <List <CallDevice> >
            {
                new List <CallDevice>
                {
                    new CallDevice
                    {
                        Type       = CallDevice.DeviceType.phone,
                        Parameters = new CallDevice.PhoneParams
                        {
                            ToNumber   = ToNumber,
                            FromNumber = FromNumber,
                        }
                    }
                }
            });

            bool successful = false;

            if (!(successful = resultConnect.Successful))
            {
                Logger.LogError("Call2 was not connected");
            }
            else
            {
                DisconnectResult resultDisconnect = resultDial.Call.Disconnect();
                if (!(successful = resultDisconnect.Successful))
                {
                    Logger.LogError("Call was not disconnected");
                }
                else
                {
                    resultConnect = resultDial.Call.Connect(new List <List <CallDevice> >
                    {
                        new List <CallDevice>
                        {
                            new CallDevice
                            {
                                Type       = CallDevice.DeviceType.phone,
                                Parameters = new CallDevice.PhoneParams
                                {
                                    ToNumber   = ToNumber,
                                    FromNumber = FromNumber,
                                }
                            }
                        }
                    });

                    if (!(successful = resultConnect.Successful))
                    {
                        Logger.LogError("Call3 was not reconnected");
                    }
                }
            }

            // Hangup both calls
            resultConnect.Call?.Hangup();
            resultDial.Call.Hangup();

            // Mark the test successful and terminate
            Successful = successful;
            Completed.Set();
        }