private void PutEvent(RESTapi.event_type type) { RESTapi.web_service ws = new RESTapi.web_service() { Item = new RESTapi.@event() { type = type, resource_type = ResourceType, resource_id = ResourceID, } }; /// IMPORTANT: Call the dispatcher IN A NEW THREAD or stuff will just /// randomly lock up / fail for no apparent reason! /// ThreadPool.QueueUserWorkItem(x => { this.Dispatcher.ProcessRequest(ws); }); }
protected virtual void AnswerCall(RESTapi.media_type MediaType = RESTapi.media_type.audiovideo, bool AsyncCompletion = true) { /// <call answer="yes" media="audiovideo" signaling="yes" dtmf_mode="rfc2833" async_completion="yes" /// async_dtmf="yes" async_tone="yes" rx_delta="+0dB" tx_delta="+0dB" cpa="no" info_ack_mode="automatic"/> /// RESTapi.web_service ws = new RESTapi.web_service() { Item = new RESTapi.call() { answer = RESTapi.boolean_type.yes, answerSpecified = true, async_completion = AsyncCompletion ? RESTapi.boolean_type.yes : RESTapi.boolean_type.no, async_completionSpecified = true, media = MediaType, mediaSpecified = true, dtmf_mode = RESTapi.dtmf_mode_option.rfc2833, async_dtmf = RESTapi.boolean_type.yes, async_dtmfSpecified = true, async_tone = RESTapi.boolean_type.yes, async_toneSpecified = true, info_ack_mode = RESTapi.ack_mode_option.automatic, info_ack_modeSpecified = true, } }; String responseString = String.Empty; if (RestHelpers.SendHttpRequest(out responseString, CallURI, "PUT", ws)) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, "Call::AnswerCall : AnswerCall OK"); LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, responseString); // Note: If we use async_completion, we DON'T have to put the event // manually as it will (or rather... should) appear as a separate // event from the XMS server... // if (!AsyncCompletion) { PutEvent(RESTapi.event_type.answered); } } else { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Error, "Call::AnswerCall : AnswerCall failed!"); Hangup(); } }
/// <summary> /// This is an example of how to populate and call a more complicated /// RESTapi structure. We play an audio/video file from here... /// </summary> /// <param name="audioUri"></param> /// <param name="videoUri"></param> /// protected virtual void PlayFile(String audioUri, RESTapi.audio_type_option audioType = RESTapi.audio_type_option.audioxwav, String videoUri = "", RESTapi.video_type_option videoType = RESTapi.video_type_option.videoxvid) { bool hasAudio = !String.IsNullOrWhiteSpace(audioUri); bool hasVideo = !String.IsNullOrWhiteSpace(videoUri); RESTapi.web_service ws = new RESTapi.web_service() { Item = new RESTapi.call() { call_action = new RESTapi.call_action() { Item = new RESTapi.play() { offset = "0s", repeat = "0", delay = "0s", play_source = new RESTapi.play_source() { audio_uri = hasAudio ? audioUri : String.Empty, audio_type = audioType, audio_typeSpecified = hasAudio, video_uri = hasVideo ? videoUri : String.Empty, video_type = videoType, video_typeSpecified = hasVideo, } } } } }; if (hasAudio) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, "Call::PlayFile : Playing audio \"{0}\"...", audioUri); } if (hasVideo) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, "Call::PlayFile : Playing video \"{0}\"...", videoUri); } String responseString = String.Empty; if (RestHelpers.SendHttpRequest(out responseString, CallURI, "PUT", ws)) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, "Call::PlayFile : Play file OK"); LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, responseString); } else { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Error, "Call::PlayFile : Play file failed!"); PutEvent(RESTapi.event_type.end_play); } }
protected virtual void AcceptCall(bool EarlyMedia = true, RESTapi.media_type MediaType = RESTapi.media_type.audiovideo) { /// <call accept="yes" early_media="yes" media="audiovideo" signaling="yes" dtmf_mode="rfc2833" /// async_dtmf="yes" async_tone="yes" rx_delta="+0dB" tx_delta="+0dB" cpa="no" info_ack_mode="automatic"/> /// RESTapi.web_service ws = new RESTapi.web_service() { Item = new RESTapi.call() { accept = RESTapi.boolean_type.yes, acceptSpecified = true, early_media = EarlyMedia ? RESTapi.boolean_type.yes : RESTapi.boolean_type.no, early_mediaSpecified = true, media = MediaType, mediaSpecified = true, dtmf_mode = RESTapi.dtmf_mode_option.rfc2833, async_dtmf = RESTapi.boolean_type.yes, async_dtmfSpecified = true, async_tone = RESTapi.boolean_type.yes, async_toneSpecified = true, info_ack_mode = RESTapi.ack_mode_option.automatic, info_ack_modeSpecified = true, } }; String responseString = String.Empty; if (RestHelpers.SendHttpRequest(out responseString, CallURI, "PUT", ws)) { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, "Call::AcceptCall : Accept call OK"); LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Debug1, responseString); PutEvent(RESTapi.event_type.ringing); } else { LoggingSingleton.Instance.Message(LogType.Library, LogLevel.Error, "Call::AcceptCall : Accept call failed!"); Hangup(); } }