コード例 #1
0
        private void MainActivity_OnPhoneCall(object sender, TwilioEventArgs e)
        {
            //NSDictionary parameters = NSDictionary.FromObjectsAndKeys(
            //    new object[] { from, to },
            //    new object[] { "Source", "Target" }
            //);

            NSDictionary parameters = NSDictionary.FromObjectsAndKeys(
                new object[] { e.CallID },
                new object[] { "CallId" }
                );

            _connection = _device.Connect(parameters, null);
        }
        partial void UIButton5_TouchUpInside(UIButton sender)
        {
            ///Source represents the the phone number that you want Twilio to use as the Caller ID when it calls the
            /// Target. The Source number must be either a phone number you've purchased from Twilio, or a phone number that
            /// has been verified by Twilio.
            var parameters = NSDictionary.FromObjectsAndKeys(
                new object[] { "61411024553", "61411024553" },
                new object[] { "Target", "Source" }
                );

            try {
                _connection = _device.Connect(parameters, null);
            } catch (Exception ex) {
            }
        }
コード例 #3
0
        partial void btnCall(NSObject sender)
        {
            device.StoppedListeningForIncomingConnections += delegate {
                Console.WriteLine("StoppedListeningForIncomingConnection");
                updateStateLabels();
            };

            device.StartedListeningForIncomingConnections += delegate
            {
                Console.WriteLine("StartedListeningForIncomingConnections");
                updateStateLabels();
            };

            device.ReceivedIncomingConnection += (s, a) =>
            {
                Console.WriteLine("ReceivedIncomingConnection");

                if (connection != null && connection.State == TCConnectionState.Connected)
                {
                    connection.Disconnect();
                }

                connection = a.Connection;

                updateStateLabels();
            };

            device.ReceivedPresenceUpdate += delegate { Console.WriteLine("ReceivedPresenceUpdate"); };

            NSDictionary param = NSDictionary.FromObjectsAndKeys(
                new object[] { "+14159929754", "+13144586142" },
                new object[] { "Source", "Target" }
                );

            // HACK:
            // In order to setup events you need to first initialize connection so we have a reference to it, also the delegate param should be null
            // this is because when you set up an event we internally will create a Objc delegate that will be assigned to the delegate property
            // and if we see that delegate property is not null then we will not be able to set you up

            connection = device.Connect(param, null);

            connection.Failed += delegate
            {
                Console.WriteLine("FailedWithError");
                updateStateLabels();
            };
            connection.StartedConnecting += delegate
            {
                Console.WriteLine("StartedConnecting");
                updateStateLabels();
            };
            connection.Connected += delegate
            {
                Console.WriteLine("Connected");
                updateStateLabels();
            };
            connection.Disconnected += delegate
            {
                Console.WriteLine("Disconnected");
                updateStateLabels();
                connection = null;
            };
        }
コード例 #4
0
        public async override void FinishedLaunching(UIApplication application)
        {
            this.Window = new UIWindow(UIScreen.MainScreen.Bounds);

            var client = new HttpClient();
            var token  = await client.GetStringAsync("** Your AuthToken URL goes here **");

            device = new TCDevice(token, null);

            var dialogController = new DialogViewController(new RootElement("Twilio Client Test")
            {
                new Section("Call Options")
                {
                    (numberOrClient = new EntryElement("Target", "Phone # or client name", "")),
                    (callButton = new StyledStatusStringElement("Call", delegate {
                        if (connection == null || connection.State == TCConnectionState.Disconnected)
                        {
                            var param = new TCConnectionParameters {
                                Source = "** Your Twilio Phone Number goes here **",
                                Target = numberOrClient.Value
                            };

                            connection = device.Connect(param, null);

                            SetupConnectionEvents();
                        }
                        else
                        {
                            connection.Disconnect();
                        }
                    })),
                },
                new Section("Status")
                {
                    (deviceState = new StatusStringElement("Device", device.State.ToString())),
                    (connectionState = new StatusStringElement("Connection", "Uninitialized"))
                },

                new Section("Sounds")
                {
                    (disconnectSoundEnabled = new BooleanElement("Disconnect Sound", device.DisconnectSoundEnabled)),
                    (incomingCallSoundEnabled = new BooleanElement("Incoming Sound", device.IncomingSoundEnabled)),
                    (outgoingCallSoundEnabled = new BooleanElement("Outgoing Sound", device.OutgoingSoundEnabled))
                },

                new Section("Options")
                {
                    (muted = new BooleanElement("Muted", false)),
                    (listening = new BooleanElement("Device Listening", true))
                }
            });

            callButton.Alignment = UITextAlignment.Center;
            callButton.TextColor = UIColor.FromRGB(0x00, 0x7A, 0xFF);

            var navigationController = new UINavigationController(dialogController);

            //navigationController.NavigationBar.BarTintColor = UIColor.Red;
            //navigationController.NavigationBar.TintColor = UIColor.White;

            Window.RootViewController = navigationController;

            Window.MakeKeyAndVisible();

            SetupSoundOptionEvents();
            SetupOptions();
            SetupDeviceEvents();
            device.Listen();
        }