//void OnRemoteNotificationReceived(UnityEngine.iOS.RemoteNotification n10n) { // Debug.Log("received remote notification in CHSession: "); // Debug.Log(" " + n10n.alertTitle + ": " + n10n.alertBody); // if (n10n.userInfo.Contains("cohortMessage")) { // Debug.Log("n10n had a cohortMessage, processing"); // Hashtable msgHashtable = (Hashtable)n10n.userInfo["cohortMessage"]; // // process int64s // msgHashtable["mediaDomain"] = System.Convert.ToInt32(msgHashtable["mediaDomain"]); // msgHashtable["cueAction"] = System.Convert.ToInt32(msgHashtable["cueAction"]); // ValidateCohortMessage(msgHashtable); // } else { // Debug.Log("notification had no cohortMessage, displaying text"); // // minor hack to mirror notification text in the text cue display area // onTextCue(CueAction.play, n10n.alertBody); // if(n10n.soundName != "default.caf") { // soundCues.ForEach(cue => { // if(cue.audioClip.name == n10n.soundName) { // audioPlayer.clip = cue.audioClip; // audioPlayer.Play(); // return; // } // }); // } // } //} void ValidateCohortMessage(Hashtable msgHashtable) { CHMessage msg = new CHMessage(); msg.cueNumber = System.Convert.ToSingle(msgHashtable["cueNumber"]); //Debug.Log("processing tags"); ArrayList tagsFromMsgHashtable = (ArrayList)msgHashtable["targetTags"]; List <string> tags = new List <string>(); for (int i = 0; i < tagsFromMsgHashtable.Count; i++) { string oneTag = tagsFromMsgHashtable[i].ToString(); tags.Add(oneTag); } Debug.Log(string.Join(", ", tags.ToArray())); msg.targetTags = tags; msg.mediaDomain = (MediaDomain)msgHashtable["mediaDomain"]; msg.cueAction = (CueAction)msgHashtable["cueAction"]; if (msgHashtable.ContainsKey("id")) { msg.id = (int)msgHashtable["id"]; } else { msg.id = -1; } // hacks related to text cues and notifications if (System.Math.Abs(msg.cueNumber) < System.Single.Epsilon && msgHashtable.ContainsKey("cueContent")) { Debug.Log("creating extemporaneous text cue to match cohort message"); CHTextCue extemporaneousTextCue = new CHTextCue((string)msgHashtable["cueContent"].ToString()); float highestTextCueNumber = 0; foreach (CHTextCue cue in textCues) { if (cue.cueNumber > highestTextCueNumber) { highestTextCueNumber = cue.cueNumber; } } Debug.Log("highest text cue number: " + highestTextCueNumber); float newTextCueNumber = highestTextCueNumber + 1; extemporaneousTextCue.cueNumber = newTextCueNumber; msg.cueNumber = newTextCueNumber; textCues.Add(extemporaneousTextCue); } Debug.Log(CHMessage.FormattedMessage(msg)); OnCohortMessageReceived(msg); }
/* * Cohort handlers */ void OnCohortMessageReceived(CHMessage msg) { if (msg.id > 0) { PlayerPrefs.SetInt("lastReceivedCohortMessageId", msg.id); } Debug.Log("current grouping: " + grouping); if (!msg.targetTags.Contains(grouping) && !msg.targetTags.Contains("all")) { Debug.Log("cohort message is for another grouping (not " + grouping + "), not processing it"); return; } // DO STUFF switch (msg.mediaDomain) { case MediaDomain.sound: CHSoundCue soundCue = soundCues.Find((CHSoundCue matchingCue) => System.Math.Abs(matchingCue.cueNumber - msg.cueNumber) < 0.00001); if (soundCue != null) { audioPlayer.clip = soundCue.audioClip; } // looped cues //if(Math.Abs(msg.cueNumber - 4) < Mathf.Epsilon) { // if(msg.cueAction == CueAction.play) { // audioPlayer.loop = true; // } else { // audioPlayer.loop = false; // } //} switch (msg.cueAction) { case CueAction.play: audioPlayer.Play(); break; case CueAction.pause: audioPlayer.Pause(); break; case CueAction.restart: audioPlayer.Pause(); audioPlayer.time = 0; audioPlayer.Play(); break; case CueAction.stop: audioPlayer.Stop(); audioPlayer.clip = null; break; } break; case MediaDomain.video: CHVideoCue videoCue = videoCues.Find((CHVideoCue matchingCue) => System.Math.Abs(matchingCue.cueNumber - msg.cueNumber) < 0.00001); if (videoCue != null) { if (videoPlayer.clip != videoCue.videoClip) { videoPlayer.Pause(); videoPlayer.clip = videoCue.videoClip; } switch (msg.cueAction) { case CueAction.play: videoPlayer.Play(); break; case CueAction.pause: videoPlayer.Pause(); break; case CueAction.restart: videoPlayer.Pause(); videoPlayer.time = 0; videoPlayer.Play(); break; case CueAction.stop: videoPlayer.Stop(); videoPlayer.clip = nullVideo; videoPlayer.Play(); break; default: Debug.Log("Error: cue action not implemented"); break; } break; } else { Debug.Log("Error: cue number not valid"); } break; case MediaDomain.image: CHImageCue imageCue = imageCues.Find((CHImageCue matchingCue) => System.Math.Abs(matchingCue.cueNumber - msg.cueNumber) < 0.00001); if (imageCue != null) { switch (msg.cueAction) { case CueAction.play: Debug.Log("got image cue"); imageCueSurface.sprite = imageCue.image; imageCueSurface.gameObject.SetActive(true); break; case CueAction.stop: imageCueSurface.gameObject.SetActive(false); imageCueSurface.sprite = null; break; default: Debug.Log("Error: cue action not implemented"); break; } } else { Debug.Log("Error: cue number not valid"); } break; case MediaDomain.text: CHTextCue textCue = textCues.Find((CHTextCue matchingCue) => System.Math.Abs(matchingCue.cueNumber - msg.cueNumber) < 0.00001); if (textCue == null && msg.cueContent == null) { return; } string textOfCue; if (msg.cueContent != null) { textOfCue = msg.cueContent; } else if (textCue.text != null) { textOfCue = textCue.text; } else { Debug.Log("Error: Failed to find text for text cue in onboard text cues or in remote cue"); return; } switch (msg.cueAction) { case CueAction.play: UnityEngine.Handheld.Vibrate(); onTextCue(CueAction.play, textOfCue); break; case CueAction.pause: Debug.Log("action 'pause' is not defined for text cues"); break; case CueAction.restart: Debug.Log("action 'restart' is not defined for text cues"); break; case CueAction.stop: onTextCue(CueAction.stop, textOfCue); break; } break; //case MediaDomain.light: // switch(msg.cueAction) { // case CueAction.play: // flashlightController.TurnOn(); // break; // case CueAction.stop: // flashlightController.TurnOff(); // break; // case CueAction.pause: // flashlightController.TurnOff(); // break; // case CueAction.restart: // Debug.Log("action 'restart' is not defined for light cues"); // break; // } // break; case MediaDomain.haptic: UnityEngine.Handheld.Vibrate(); break; } }