コード例 #1
0
        public async Task <string> GetAuthorizationHeader(bool includeUser = true)
        {
            //MediaBrowser UserId="e8837bc1-ad67-520e-8cd2-f629e3155721", Client="Android", Device="Samsung Galaxy SIII", DeviceId="xxx", Version="1.0.0.0"

            string value = "MediaBrowser ";

            if (includeUser)
            {
                value += "UserId=\"" + await GetUserID() + "\", ";
            }

            value += "Client=\"Windows RT\", ";

            string deviceName = settings.GetDeviceName();

            if (string.IsNullOrEmpty(deviceName))
            {
                value += "Device=\"SPMB\", ";
            }
            else
            {
                value += "Device=\"SPMB-" + settings.GetDeviceName() + "\", ";
            }

            value += "DeviceId=\"" + settings.GetDeviceId() + "\", ";

            value += "Version=\"0.0.1\"";

            return(value);
        }
コード例 #2
0
        public async Task <bool> SetupWebSocket()
        {
            bool worked = false;

            try
            {
                ServerListItem server = settings.GetServer();
                if (server == null)
                {
                    return(false);
                    //throw new Exception("Server not set");
                }

                Uri serverUri = new Uri("ws://" + server + "/mediabrowser");
                webSocket = new MessageWebSocket();
                webSocket.Control.MessageType = SocketMessageType.Utf8;

                webSocket.MessageReceived += MessageReceived;

                webSocket.Closed += Closed;

                await webSocket.ConnectAsync(serverUri);

                DataWriter messageWriter = new DataWriter(webSocket.OutputStream);

                string deviceName = settings.GetDeviceName();
                string value      = "SPMB";
                if (string.IsNullOrEmpty(deviceName) == false)
                {
                    value = "SPMB-" + settings.GetDeviceName();
                }

                string identityMessage = "{\"MessageType\":\"Identity\", \"Data\":\"Windows RT|" + settings.GetDeviceId() + "|0.0.1|" + value + "\"}";
                messageWriter.WriteString(identityMessage);
                await messageWriter.StoreAsync();

                worked = true;
            }
            catch (Exception e)
            {
                MetroEventSource.Log.Info("Error Creating WebSocket - " + e.Message);
                string errorString = "Error Creating WebSocket : " + e.Message;
                App.AddNotification(new Notification()
                {
                    Title = "Error Creating Web Socket", Message = errorString
                });
            }

            return(worked);
        }