Beispiel #1
0
        public IEnumerator waitThenStartAdVideoWithJavascriptCall()
        {
            //if (AdGem.verboseLogging) { Debug.Log("Adgem - waitThenStartAdVideoWithJavascriptCall()"); }

            yield return(new WaitForSeconds(0.05f));

            waitingForPlaySuccessConfirmation = true;

            if (AdGem.verboseLogging)
            {
                Debug.Log("Adgem - JAVASCRIPT CALL: " + "init(" + initParams + "," + AdGemPlugin.appSessionId + ");");
            }

            //webView.EvaluateJavaScript("init_debug();", (payload) =>
            webView.EvaluateJavaScript("init(" + initParams + ",'" + AdGemPlugin.appSessionId + "');", (payload) =>
            {
                if (payload.resultCode.Equals("0"))
                {
                    if (AdGem.verboseLogging)
                    {
                        Debug.Log("Starting webview ad video!");
                    }
                }
                else
                {
                    Debug.Log("Something went wrong starting the ad video: " + payload.data);
                }
            });

            //Make sure the play success message is received
            float waitTime = 0f;

            while (waitingForPlaySuccessConfirmation && waitTime < 5.5f)
            {
                Debug.Log("Adgem - waiting for confirmation...");

                if (waitTime > 5f)
                {
                    waitingForPlaySuccessConfirmation = false;
                    if (webView != null)
                    {
                        Debug.Log("Adgem - closing webview because did not get confirmation **********------------*********");
                        webView.Stop();
                        webView.CleanCache();
                        webView.Hide(false);
                        AdGem.videoIsPlaying = false;
                        if (AdGem.videoFailedToLoad != null)
                        {
                            AdGem.videoFailedToLoad();
                        }
                    }
                }

                yield return(new WaitForSeconds(0.1f));

                waitTime += 0.1f;
            }
        }
Beispiel #2
0
        public void closeWebView()
        {
            if (AdGem.videoIsPlaying) //when closing the webview, if it was a video ad rather than the offer wall, do some specific stuff like call delegates.
            {
                if (currentWebviewVideoIsRewarded)
                {
                    if (rewardVideoWasClosedEarly)
                    {
                        if (AdGem.rewardVideoCanceled != null)
                        {
                            AdGem.rewardVideoCanceled();
                        }

                        //--webview handles this now
                        //AdGemManager.staticRef.fireEventEndpoint("videoskip", "rewarded-video", AdGemManager.rewardedVideoCacheId);
                    }
                    else
                    {
                        if (AdGem.rewardVideoFinishedPlaying != null)
                        {
                            AdGem.rewardVideoFinishedPlaying();
                        }

                        //--webview handles this now
                        //AdGemManager.staticRef.fireEventEndpoint("videocomplete", "rewarded-video", AdGemManager.rewardedVideoCacheId);
                    }
                }
                else
                {
                    if (AdGem.interstitialVideoFinishedPlaying != null)
                    {
                        AdGem.interstitialVideoFinishedPlaying();
                    }

                    //--webview handles this now
                    //AdGemManager.staticRef.fireEventEndpoint("videocomplete", "nonrewarded-video", AdGemManager.interstitialVideoCacheId);
                }
                rewardVideoWasClosedEarly = false;
            }
            AdGem.videoIsPlaying       = false;
            AdGemPlugin.videoIsPlaying = false;



            //Right now we don't have a delegate for offerWallClosed
            //if (AdGemPlugin.offerWallClosed != null)
            //{
            //    AdGemPlugin.offerWallClosed();
            //}

            if (webView != null)
            {
                webView.Hide(false);
                //AdGemPlugin.offerWallReady = false;
            }
        }
Beispiel #3
0
        private void processAdgemUrlSchemeMessage(UniWebViewMessage message)
        {
            if (AdGem.verboseLogging)
            {
                Debug.Log("Adgem: adgem url scheme message received");
                Debug.Log("Adgem: " + message.RawMessage);
            }

            if (message.Path.Equals("close", System.StringComparison.InvariantCultureIgnoreCase))
            {
                closeWebView();
            }
            else if (message.Path.Equals("close-not-rewarded", System.StringComparison.InvariantCultureIgnoreCase))
            {
                closeNotRewarded();
            }
            else if (message.Path.Equals("play-success", System.StringComparison.InvariantCultureIgnoreCase))
            {
                waitingForPlaySuccessConfirmation = false;
                if (AdGem.videoAdStarted != null)
                {
                    AdGem.videoAdStarted();
                }
            }
            else //otherwise, the path should be a url ecoded base64 encoded json string
            {
                try
                {
                    string base64payload = message.Path; //Uniwebview automatically url-decodes
                    string jsonString    = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(base64payload));

                    //Debug.Log("Adgem--- offer wall message json string ---***--- " + jsonString);

                    JSONNode baseJson = JSON.Parse(jsonString); if (baseJson == null)
                    {
                        return;
                    }

                    string actionType = baseJson["action"].Value;
                    string url        = baseJson["url"].Value; if (url == null)
                    {
                        url = "";
                    }

                    //Debug.Log("url: " + url);

                    string storeID = baseJson["store_id"].Value; if (storeID == null)
                    {
                        storeID = "";
                    }
                    string app_id = baseJson["app_id"].Value; if (app_id == null)
                    {
                        app_id = "";
                    }
                    int amount = baseJson["amount"].AsInt;

                    if (actionType.Equals("browser", System.StringComparison.InvariantCultureIgnoreCase))
                    {
                        //Debug.Log("browser");
                        Application.OpenURL(url);

                        //Start polling for an offer completion
                        AdGemManager.staticRef.startPollingProcess();
                    }
                    if (actionType.Equals("appstore", System.StringComparison.InvariantCultureIgnoreCase) && AdGemPrefabController.staticRef != null) //appstore //store_id
                    {
                        //Start polling for an offer completion
                        AdGemManager.staticRef.startPollingProcess();

                        //Debug.Log("appstore");
                        AdGemPrefabController.staticRef.userClicked(url, app_id);
                    }
                    //if (actionType.Equals("reward", System.StringComparison.InvariantCultureIgnoreCase) && AdGemPlugin.offerWallRewardReceived != null)
                    //{
                    //    Debug.Log("Adgem--- **** Reward action fired");
                    //    AdGemPlugin.processOfferWallReward(baseJson, amount);
                    //}
                }
                catch (System.Exception ex)
                {
                    Debug.Log("Adgem--- " + ex.ToString());
                }
            }
        }