Example #1
0
        private void RealtimeManager_OnMessageReceived(Networking.WebSocketManager.StateObject state, string value)
        {
            InstaMessage message = value.JsonToOjbect <InstaMessage>();

            if (OnMessageReceived != null)
            {
                OnMessageReceived(message);
            }
        }
Example #2
0
        private void PushClient_OnMessageReceived(InstaMessage Message)
        {
            switch (Message.Type)
            {
            case InstaMessage.InstaType.Tickle:
                if (Message.SubType == InstaMessage.InstaSubType.Push)
                {
                    PushbulletNetworkManager.GetPushesFilter filter = new PushbulletNetworkManager.GetPushesFilter()
                    {
                        ModifiedAfter = PushClient.LastPushModified,
                        Active        = true
                    };

                    List <PushMessage> results = PushClient.GetPushes(filter);

                    foreach (PushMessage push in results)
                    {
                        if (!push.Dismissed && !SentNotifications.ContainsKey(push) && push.Direction != PushMessage.PushDirection.Outgoing)
                        {
                            string DisplayMessage = String.Format("{0}\n{1}\n{2}", push.SenderName, push.Title, push.Body);
                            uint   id             = 0;
                            if (VRController._IsRunning)
                            {
                                id = VRController.DisplayNotification(DisplayMessage, VRDummyOverlay, Valve.VR.EVRNotificationType.Transient, Valve.VR.EVRNotificationStyle.Application, new Valve.VR.NotificationBitmap_t());
                            }
                            AddNotification(push, id);
                        }
                    }
                }
                break;

            case InstaMessage.InstaType.Push:
                InstaPushMessage response = Message.Push;
                if (response != null && response.Type != InstaPushMessage.InstaPushType.Dismissal)
                {
                    if (SentNotifications.ContainsKey(response))
                    {
                        foreach (MessageBase msg in SentNotifications.Keys)
                        {
                            if (msg is InstaPushMessage && msg.Equals(response))
                            {
                                (msg as InstaPushMessage).Body += response.Body;
                                break;
                            }
                        }
                    }

                    string DisplayMessage = String.Format("{0}\n{1}\n{2}", response.ApplicationName, response.Title, response.Body);
                    Valve.VR.NotificationBitmap_t bitmap = new Valve.VR.NotificationBitmap_t();
                    uint id = 0;
                    if (response.Icon != null && VRController._IsRunning)
                    {
                        using (System.Drawing.Bitmap iconOriginal = new System.Drawing.Bitmap(new System.IO.MemoryStream(response.Icon)))
                            using (System.Drawing.Bitmap iconBMP = new System.Drawing.Bitmap(iconOriginal.Width, iconOriginal.Height,
                                                                                             System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
                                using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(iconBMP))
                                {
                                    gr.DrawImage(iconOriginal, new System.Drawing.Rectangle(0, 0, iconBMP.Width, iconBMP.Height));
                                    System.Drawing.Imaging.BitmapData TextureData =
                                        iconBMP.LockBits(
                                            new System.Drawing.Rectangle(0, 0, iconBMP.Width, iconBMP.Height),
                                            System.Drawing.Imaging.ImageLockMode.ReadOnly,
                                            System.Drawing.Imaging.PixelFormat.Format32bppPArgb
                                            );

                                    bitmap.m_nBytesPerPixel = 4;
                                    bitmap.m_nHeight        = TextureData.Height;
                                    bitmap.m_nWidth         = TextureData.Width;
                                    bitmap.m_pImageData     = TextureData.Scan0;

                                    iconBMP.UnlockBits(TextureData);

                                    Valve.VR.EVRNotificationType type = response.Dismissable ? Valve.VR.EVRNotificationType.Transient : Valve.VR.EVRNotificationType.Persistent;

                                    id = VRController.DisplayNotification(DisplayMessage, VRDummyOverlay, Valve.VR.EVRNotificationType.Transient, Valve.VR.EVRNotificationStyle.Contact_Enabled, bitmap);
                                }
                    }
                    if (SentNotifications.ContainsKey(response))
                    {
                        UpdateNotification(response, id);
                    }
                    else
                    {
                        AddNotification(response, id);
                    }
                }
                else if (response != null && response.Type == InstaPushMessage.InstaPushType.Dismissal)
                {
                    RemoveNotification(response);
                }
                break;
            }
        }