Пример #1
0
        /// <summary>
        /// Creates a new Authenticated Session
        /// </summary>
        /// <param name="authenticator"><see cref="IAuthenticator"/> and its implementations:
        /// <seealso cref="StoredAuthenticator"/>
        /// <seealso cref="UserPassAuthenticator"/>
        /// </param>
        /// <param name="cts">Cancellation token for the asynchronous operation.</param>
        /// <param name="deviceType"><see cref="DeviceType"/></param>
        /// <param name="deviceName">string to display on spotify connect</param>
        /// <param name="conf">Configuration file. See <see cref="Configuration"/></param>
        /// <param name="ws">An implementation of the abstract class: <see cref="WebsocketHandler"/></param>
        /// <param name="preferredLocale">2 letter locale code. Default = English</param>
        /// <param name="overrideAdress"></param>
        /// <returns><see cref="SpotifySession"/></returns>
        /// <exception cref="UnauthorizedAccessException">When trying to authenticated with <seealso cref="StoredAuthenticator"/> but no file is saved</exception>
        /// <exception cref="SpotifyAuthenticatedException">When credentials are invalid.</exception>
        public static async Task <SpotifySession> CreateAsync(
            IAuthenticator authenticator,
            CancellationToken cts,
            DeviceType deviceType,
            string deviceName,
            Configuration conf,
            WebsocketHandler ws,
            string preferredLocale = "en",
            string overrideAdress  = null)
        {
            Cache = new MemoryCache(new MemoryCacheOptions());
            GuardAgainst.ArgumentBeingNull(authenticator);
            //  TimeProvider.Init(conf);
            var deviceId = Utils.RandomHexString(new Random(), 40).ToLower();
            var session  =
                new SpotifySession(
                    new Inner(deviceType,
                              deviceName,
                              deviceId,
                              preferredLocale,
                              conf),
                    cts,
                    overrideAdress)
            {
                loginCredentials = await authenticator.Get()
            };
            await session.conn;

            session.Connect();
            await session.Authenticate(session.loginCredentials, ws);

            return(session);
        }
Пример #2
0
 public DealerClient(SpotifySession session, WebsocketHandler websocket)
 {
     _session   = session;
     _webSocket = websocket;
     _webSocket.MessageReceived    += WebSocket_MessageReceived;
     _webSocket.SocketDisconnected += WebSocket_SocketDisconnected;
     _webSocket.SocketConnected    += WebSocket_SocketConnected;
 }
Пример #3
0
            internal Receiver(SpotifySession session)
            {
                this.session = session;
                cts          = new CancellationTokenSource();
                var ts = new ThreadStart(BackgroundMethod);
                var backgroundThread = new Thread(ts);

                backgroundThread.Start();
            }
Пример #4
0
 private SpotifySession([NotNull] Inner inner,
                        CancellationToken closedToken,
                        [CanBeNull] string address)
 {
     recvNonce        = 0;
     sendNonce        = 0;
     this.inner       = inner;
     this.closedToken = closedToken;
     this.conn        = SpotifyConnection.Create(
         inner.Conf,
         address);
     this.keys = new DiffieHellman(new System.Random());
     Debug.WriteLine($"Created new session! deviceId: {inner.DeviceId}, ap: {address}");
     Current = this;
 }
Пример #5
0
 internal SocialHandler(SpotifySession inter)
 {
     _session = inter;
 }