Xamarin Bindings for TeamViewer SDK

Hi,

I was hoping someone could help me with creating a new binding.

I know NOTHING about Objective-C so I am out of my depth to even consider creating my own bindings for the TeamViewer library: https://integrate.teamviewer.com/en/develop/screen-sharing-sdk/ios-tutorial. I wouldn't know if I had the right switches etc and how to validate that the output is true and correct.

Has anyone already done this or might be willing to do this?

Many thanks in advance for any assistance.
Joe

Posts

  • joehannajoehanna AUBeta ✭✭

    That's awesome @rzee7 !

    Thank you so much!

  • ClaudioSanchezClaudioSanchez USUniversity, Developer Group Leader ✭✭

    @joehanna Were you able to get progress with this effort?

  • joehannajoehanna AUBeta ✭✭

    Not yet. Hey @rzee7, did you end up having a go at this?

    Thanks!
    Joe

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    Hi @joehanna

    Yeah, lets plan it and take this forward :smiley:

    Cheers!!
    RIYAZ

  • FredgieFredgie USMember ✭✭
    edited November 2015

    thought this might be helpful. a while ago, i was able to integrate the team viewer sdk into our iOS project

    using System;

    using UIKit;
    using Foundation;
    using ObjCRuntime;
    using CoreGraphics;
    using System.Reflection;

    namespace TeamViewer.Sdk
    {

    [BaseType(typeof(NSObject))]
    [Protocol]
    [Model]
    public partial interface TVSessionDelegate
    {
        [Export("sessionDidFailWithError:")]
        void Failed(NSError error);
    
        [Export("sessionDidEnd")]
        void Ended();
    
    }
    
    [BaseType(typeof(NSObject))]
    [Protocol]
    [Model]
    public partial interface TVSessionCreationDelegate
    {
        [Export("sessionCreationSuccess:")]
        void Success(TVSession session);
    
        [Export("sessionCreationFailed:")]
        void Failed(NSError error);
    
    }
    
    [Protocol]
    [BaseType(typeof(NSObject))]
    public partial interface TVSessionFactory
    {
        [Static, Export("createTVSessionWithToken:delegate:")]
        void CreateSession(string token, TVSessionCreationDelegate del);
    
    }
    
    public delegate void TVOnBuildSession(TVSessionConfigurationBuilder builder);
    
    [Protocol]
    [BaseType(typeof(NSObject))]
    public partial interface TVSessionConfiguration
    {
        [Export("sessionCode")]
        string SessionCode { get; }
    
        [Export("configurationId")]
        string ConfigurationId { get; }
    
        [Export("serviceCaseName")]
        string ServiceCaseName { get; }
    
        [Export("serviceCaseDescription")]
        string ServiceCaseDescription { get; }
    
        [Static, Export("tvSessionConfigurationWithBlock:")]
        TVSessionConfiguration Create(Action<TVSessionConfigurationBuilder> builder);
    
    }
    
    [Protocol]
    [BaseType(typeof(NSObject))]
    public partial interface TVSessionConfigurationBuilder
    {
        [Export("sessionCode")]
        string SessionCode { get; set;}
    
        [Export("configurationId")]
        string ConfigurationId { get; set; }
    
        [Export("serviceCaseName")]
        string ServiceCaseName { get; set; }
    
        [Export("serviceCaseDescription")]
        string ServiceCaseDescription { get; set; }
    }
    
    [Protocol]
    [BaseType(typeof(NSObject))]
    public partial interface TVSession
    {
        [Export("startWithConfiguration:")]
        void Start(TVSessionConfiguration configuration);
    
        [Export("stop")]
        void Stop();
    
        [Export("setSessionDelegate:")]
        void SetDelegate(TVSessionDelegate del);
    
    }
    

    }

  • FredgieFredgie USMember ✭✭

    here is the link with that goes with the .a file

    using System;
    using ObjCRuntime;

    [assembly: LinkWith("TeamViewerSdk.a",
    LinkTarget.Simulator | LinkTarget.Arm64 | LinkTarget.ArmV7 | LinkTarget.Simulator64,
    Frameworks = "AudioToolbox SystemConfiguration UIKit",
    LinkerFlags = "-dead_strip -lc++ -lz",
    SmartLink = true, ForceLoad = false, IsCxx = true)]

  • rzee7rzee7 INUniversity ✭✭✭✭✭

    Woahh!! Fantastic!! @FredSanders :) Is this whole code for TV?

  • FredgieFredgie USMember ✭✭

    thats all the information for the binding project you will need. i will post the implementation i wrote here in a few minutes

  • FredgieFredgie USMember ✭✭
    public class TvEventArgs : EventArgs
    {
        public TVSession Session { get; set; }
    
        public string ErrorMessage { get; set; }
    
        public bool HasErrorMessage
        {
            get
            {
                return !string.IsNullOrWhiteSpace(ErrorMessage);
            }
        }
    
    }
    
    public class TvSessionDelegate : TVSessionDelegate
    {
    
        public event EventHandler<TvEventArgs> SessionEnded;
        public event EventHandler<TvEventArgs> Error;
    
        public override void Ended()
        {
            OnSessionEnded();
        }
    
        public override void Failed(NSError error)
        {
            OnError(error);
        }
    
        void OnSessionEnded()
        {
            if (SessionEnded == null)
                return;
    
            SessionEnded(this, new TvEventArgs());
        }
    
        void OnError(NSError error)
        {
            if (Error == null)
                return;
    
            Error(this, new TvEventArgs { ErrorMessage = error.ToString() });
    
        }
    
    }
    
    public class TvSessionCreationDelegate : TVSessionCreationDelegate
    {
    
        public string ServiceCaseName { get; set; }
        public string ConfigurationId { get; set; }
        public string ServiceCaseDescription { get; set; }
    
        public event EventHandler<TvEventArgs> SessionCreated;
        public event EventHandler<TvEventArgs> Error;
    
        public override void Success(TVSession session)
        {
            OnSessionCreated(session);
        }
    
        public override void Failed(NSError error)
        {
            OnError(error);
        }
    
        void OnSessionCreated(TVSession session)
        {
            if (SessionCreated == null)
                return;
    
            SessionCreated(this, new TvEventArgs { Session = session });
        }
    
        void OnError(NSError error)
        {
            if (Error == null)
            return;
    
            Error(this, new TvEventArgs { ErrorMessage = error.ToString() });
    
        }
    
    }
    
    public class TvSession : IDisposable
    {
    
        public event EventHandler<TvEventArgs> SessionEnded;
        public event EventHandler<TvEventArgs> SessionCreated;
        public event EventHandler<TvEventArgs> Error;
    
        public string ServiceCaseName { get; set; }
    
        public string ConfigurationId { get; set; }
    
        public string ServiceCaseDescription { get; set; }
    
        TvSessionCreationDelegate _creationDelegate;
        TvSessionDelegate _sessionDelegate;
    
        TvSessionCreationDelegate CreationDelegate
        {
            get
            {
                if (_creationDelegate == null)
                {
                    _creationDelegate = new TvSessionCreationDelegate {
                        ServiceCaseName = ServiceCaseName,
                        ConfigurationId = ConfigurationId,
                        ServiceCaseDescription = ServiceCaseDescription
                    };
                    _creationDelegate.SessionCreated += CreationDelegate_SessionCreated;
                    _creationDelegate.Error += CreationDelegate_Error;
                }
    
                return _creationDelegate;
            }
        }
    
        TvSessionDelegate SessionDelegate
        {
            get
            {
                if (_sessionDelegate == null)
                {
                    _sessionDelegate = new TvSessionDelegate();
                    _sessionDelegate.SessionEnded += SessionDelegate_SessionEnded;
                    _sessionDelegate.Error += SessionDelegate_Error;
                }
    
                return _sessionDelegate;
    
            }
        }
    
    
    
    
        public void Start(string apiKey)
        {
            TVSessionFactory.CreateSession(apiKey, CreationDelegate);
        }
    
        void CreationDelegate_SessionCreated(object sender, TvEventArgs e)
        {
    
            var config = TVSessionConfiguration.Create((builder) =>
            {
                builder.ConfigurationId = ConfigurationId;
                builder.ServiceCaseName = ServiceCaseName;
                builder.ServiceCaseDescription = ServiceCaseDescription;
            });
    
            e.Session.SetDelegate(SessionDelegate);
            e.Session.Start(config);
    
            OnSessionCreated(e.Session);
    
        }
    
        void CreationDelegate_Error(object sender, TvEventArgs e)
        {
            OnError(e.ErrorMessage);
        }
    
        void SessionDelegate_SessionEnded(object sender, TvEventArgs e)
        {
            OnSessionEnded();
        }
    
        void SessionDelegate_Error(object sender, TvEventArgs e)
        {
            OnError(e.ErrorMessage);
        }
    
        void OnSessionCreated(TVSession session)
        {
            if (SessionCreated == null)
                return;
    
            SessionCreated(this, new TvEventArgs { Session = session });
        }
    
        void OnError(string error)
        {
            if (Error == null)
                return;
    
            Error(this, new TvEventArgs { ErrorMessage = error });
    
        }
    
        void OnSessionEnded()
        {
            if (SessionEnded == null)
                return;
    
            SessionEnded(this, new TvEventArgs());
        }
    
        public void Dispose()
        {
            if (_creationDelegate != null)
            {
                _creationDelegate.SessionCreated -= CreationDelegate_SessionCreated;
                _creationDelegate.Error -= CreationDelegate_Error;
            }
    
            if (_sessionDelegate != null)
            {
                _sessionDelegate.SessionEnded -= SessionDelegate_SessionEnded;
                _sessionDelegate.Error -= SessionDelegate_Error;
            }
    
        }
    
    }
    
  • FredgieFredgie USMember ✭✭
    edited November 2015

    then in your view controller, declare a property like this:

        TvSession _supportSession;
    
        TvSession SupportSession
        {
            get
            {
                if (_supportSession == null)
                {
                    _supportSession = new TvSession {
                        ServiceCaseDescription = "Support Session",
                        ConfigurationId = "your-configuration-id"
                    };
    
                    _supportSession.SessionEnded += SessionDelegate_SessionEnded;
                    _supportSession.Error += SessionDelegate_Error;
    
                }
                return _supportSession;
            }
        }
    
        void SessionDelegate_SessionEnded(object sender, TvEventArgs e)
        {
            //do whatever you need to do after the session ends
        }
    
        void SessionDelegate_Error(object sender, TvEventArgs e)
        {
            //do whatever after the session errors out
        }
    

    then you can call SupportSession.Start("your-api-key-goes-here");

    it works great in our iOS app, hope it works well for you.

  • joehannajoehanna AUBeta ✭✭

    @Fredgie, you're a legend for putting this together and sharing! Thanks so much!

  • DrEmigiusDrEmigius DEUniversity ✭✭

    Hi all,

    is there any setting that I have to set, that is not mentioned here?
    We are just unable to get it to work. We used the same code as shown above but still no success.
    After the call:
    "TVSessionFactory.CreateSession(apiKey, CreationDelegate);"
    Nothing happens, no error, no exception, no log... nothing that would put us in the right direction to even start searching.

    Since the whole internet seems to point exclusively to this thread I hope someone here can help us.

    Has anyone had a similar behaviour?

    Thanks in advance!

  • DrEmigiusDrEmigius DEUniversity ✭✭

    It is working now \o/
    We were missing some components that were not mentioned here

    1) we had to add the structsandenums (with a little change)
    2) we added the binding project via sharpie and used its binding project (except the constants and one delegate) for
    3) we were missing the resource.bundle

    Now it runs like a kitten, we built a nugetpackage and can fully integrate the teamviewer screensharing in our xamarin forms projects.

    Hodor!

  • lassanalassana BYMember ✭✭

    I've created a bindings project using code from this thread and got exactly the same problem: nothing happens after "SupportSession.Start("abcdef...");" - no crashes, no logs. As Dennis mentioned before, it is necessary to add a few lines to bindings (fortunately, Objective Sharpie created them for me) and include the resource bundle. It seems I've got bindings to work this way.

    My problem is in Android bindings. Building DLL for Android was much simpler that for iOS, but my app crashes after few seconds after new session was created: TVSessionFactory.CreateTVSession(activity, "abcde...", callback);
    The only line in logs is:
    [libc] Fatal signal 6 (SIGABRT) at 0x00000f8d (code=-6), thread 4050 (pool-1-thread-1)

    I would be truly grateful if someone could point me in right direction.

  • BenHlzemerBenHlzemer USMember ✭✭

    Hey,
    I am currently trying to create the bindings with the xamarin templet. After the creation of the dll and the inclusion of using Com.Teamviewer.Sdk.Screensharing.Api I have only access to TVCreationError TVSessoionCode and TVSessionError. Am I doing something wrong? the example does mention TVSessionConfiguration which I cannot find.

  • RogerSchmidlinRogerSchmidlin CHUniversity ✭✭✭

    I would like to use TeamViewer in my Xamarin Forms project. @DrEmigius you were talking about a nuget package you had done that does include everything you need. Is that something I could use in my project? What is the package called?

  • tuyenvtuyenv VNUniversity ✭✭✭

    Any updates on this? I am kindly to help.

Sign In or Register to comment.