HttpInitiatedP2PCallBridge-Csharp - Wiki
Wiki
HttpInitiatedP2PCallBridge-Csharp
Requirements#
Following should be installed on the development machine, on which you will create this application.
1. Latest Microsoft .Net Framework.
2. Visual Studio 2005.
3. Install the CUAE Developer Tools to get the etch framework and the cuae-tool.
Create the Application Project#
1. Open a command window.
2. To start with, the cuae-tool requires the name of the application project, the implementation language (java or csharp), etc.
C:\> cd WxpC:\Wxp> cuae create HttpInitiatedP2PCallBridge_csharp}}}
3. The cuae tool will ask for the type of project that you are creating. Type application and press "Enter"
Project type? [application or plugin] application
4. The cuae tool will ask for the programing that we will be using for this application. Type csharp and press "Enter".
Programming language? [java or csharp] csharp
5. The cuae tool will ask for the namespace that we will be using for this application. For the time being we'll use the default namespace, which is HttpInitiatedP2PCallBridge_csharp.
Project namespace? [default: httpinitiatedp2pcallbridge_csharp]
6. The cuae-tool will ask for the application triggering event. For our application, we will be using "Http.GotRequest". So for the triggering event enter 5.
Available application triggering event:0: Skip this step 1: cisco.uc.cuae.legacy.JTapi.JTapiIncomingCall 2: cisco.uc.cuae.legacy.JTapi.JTapiCallInitiated 3: cisco.uc.cuae.legacy.JTapi.JTapiCallEstablished 4: cisco.uc.cuae.legacy.CallControl.IncomingCall 5: cisco.uc.cuae.legacy.Http.GotRequest 6: cisco.uc.cuae.legacy.Presence.SubscriptionTerminated 7: cisco.uc.cuae.legacy.Presence.Notify 8: cisco.uc.cuae.legacy.TimerFacility.TimerFire Triggering event? [0-8] 5}}}
7. Now the cuae tool will create the all the necessary files for this application.
Generating:
- application named "HttpInitiatedP2PCallBridge_csharp"
- with namespace "httpinitiatedp2pcallbridge_csharp"
- with laguage "csharp"
- with trigger event "cisco.uc.cuae.legacy.Http.GotRequest"
- in location C:\Wxp\
Created project "HttpInitiatedP2PCallBridge_csharp" in directory "C:\Wxp\HttpInitiatedP2PCallBridge_csharp\"}}}
8. Now goto C:\Wxp\HttpInitiatedP2PCallBridge_csharp folder. Open the file HttpInitiatedP2PCallBridge_csharp.etch in a notepad and add the following lines mixin cisco.uc.cuae.legacy.Http, mixin cisco.uc.cuae.legacy.CallControl and mixin cisco.uc.cuae.legacy.MediaControl and save the file. These lines are added in order to incorporate the Http, CallControl and the MediaControl components into the application. We'll be using these components in our applications.
// CUAE Application Etch Service DefinitionThis service defines your application and the CUAE services that you use in your application.
The service module namespace, this will be translated to the namespace of the generated source code. module httpinitiatedp2pcallbridge_csharp
The name of your service.service HttpInitiatedP2PCallBridge_csharp{ By default, you must always use the EtchBridge service. Do not remove this mixin, otherwise your application won't work.mixin cisco.uc.cuae.EtchBridge
You may add any additional service mixins that you require. For example, if you'd like to make and receive phone calls, add the following line: mixin cisco.uc.cuae.legacy.CallControl mixin cisco.uc.cuae.legacy.Http mixin cisco.uc.cuae.legacy.CallControl mixin Cisco.uc.cuae.legacy.MediaControl } }}}
9. Goto cuae-resources in HttpInitiatedP2PCallBridge_Java project. Open file Config.yaml in notepad and add the configuration items. These items can be configured from CUAE once the application is installed on the application server.
configuration:- name: DialNum1 format: String displayName: DialNum1
- name: DialNum2 format: String displayName: DialNum2 }}}
10. From the cmd shell goto application directory, run MSBuild to generate source files.
11. Now open Mirosoft Visual Studio 2005. Goto File->Open->Project/Solution.
- Browse to C:\Wxp\HttpInitiatedP2PCallBridge_csharp and select the file HttpInitiatedP2PCallBridge_csharp.csproj and click on Open. This will open the project in Visual Studio 2005.
12. From the Solution Explorer, open the MainHttpInitiatedP2PCallBridge_csharpClient.cs. Make the following changes in the code where the comment " TODO: Change to correct URI" is written:-
Modify the String URI to match the IP address and port of the Cisco Unified Application Server.
URI settings vary slightly between 2.5(1) Beta 1 and more recent versions of 2.5(1), as follows:
2.5(1) and 2.5(1) Beta 2, Beta 3, Beta 4 & later releases#
// TODO Change to correct URIString uri = "tls://appserver_ipaddress:9000?TlsConnection.authReqd=false&filter=KeepAlive &KeepAlive.Count=5&Packetizer.maxPktSize=102400&TcpTransport.reconnectDelay=4000";}}}
Note: In Beta 2, the Etch Bridge was updated to use Transport Layer Security for encryption by default. For your applications to work, you must specify TLS as the protocol in the URI and set the authReqd parameter to false. In the example above, the KeepAlive filter and Max Packet Size and Reconnect Delay parameters have also been set.
2.5(1) Beta 1#
// TODO Change to correct URIString uri = "tcp://appserver_ipaddress:9000?&TcpConnection.reconnect_delay=4000";}}}
Note: In addition to setting the correct IP address and port for the Cisco Unfied Application Server, the Reconnect Delay parameter should be set on all connection URIs.
13. Also write the below code where the comment "TODO Insert Your Code Here" exists. Provide the administrator credential to access the system
// TODO: Insert Your Code HereString key = server.registerApplication("HttpInitiatedP2PCallBridge_csharp", "Default", "<username>", "<password>"); Console.WriteLine("HttpInitiatedP2PCallBridge_csharp registered with key = " + key);
Console.ReadLine();}}}
14. Now Open the ImplHttpInitiatedP2PCallBridge_csharpClient.cs. On the top of the code add the following namespace.
using cisco.uc.cuae.legacy.types.CuaeCommon;
15. Now add the following gobal variables in the public class ImplHttpInitiatedP2PCallBridge_csharpClient
public String DialNum1 = "";public String DialNum2 = ""; public String g_CallId1 = ""; public String g_CallId2 = "";}}}
16. Now add the below code where the comment " TODO: Implement delegates or provide implementation of server" is written.
// TODO: Implement delegates or provide implementation of server
To handle the incoming Http request.
public override void gotRequest(String sessionId, GotRequestOptions options) {
ConfigEntry[] configs = server.getConfig("Default"); Retrieve the application partition configurationConsole.WriteLine("beginCuaeScript - " + sessionId);
if(configs == null || configs.Length == 0) return;
try { for(int i = 0; i<configs.Length; i++) { if(configs[i].name == "DialNum1") { DialNum1 = configs[i].configValue.ToString(); }
if(configs[i].name == "DialNum2") { DialNum2 = configs[i].configValue.ToString(); } } }
catch(Exception e) { Console.WriteLine("Error in reading the application configs " + e.Message); }
String str1 = "Call1"; MakeCallResult mcr = server.beginMakeCall(sessionId,DialNum1, "Test", "Test", null ,str1); if (mcr.returnValue == CuaeResult.SUCCESS) { server.sendResponse(sessionId, options.remoteHost, 200, "text/plain", "Call Initiated successfully", "Ok", null); g_CallId1 = mcr.callId; server.sessionEnd(sessionId, null); } else { server.sendResponse(sessionId, options.remoteHost, 200, "text/plain", "Make Call Failed", "Ok", null); server.removeCuaeSession(sessionId); server.sessionEnd(sessionId, null); } }
public override void sessionExpired(String sessionId, SessionExpiredOptions options) { server.removeCuaeSession(sessionId); }
public override void onMakeCallComplete(String sessionId, MakeCallResult results, Object state) { if (state.ToString().Equals("Call1")) {
PlayResult pr = server.beginPlay(sessionId, "Hello, this is a P2P test application. Press 1 to continue. Or press 2 to hangup", results.connectionId, null, null, state); if (pr.returnValue != CuaeResult.SUCCESS) { Console.WriteLine("Play Failed!!!"); server.removeCuaeSession(sessionId); server.sessionEnd(sessionId, null); } else { Console.WriteLine("Play successful"); }
GatherDigitsOptions gdoptions = new GatherDigitsOptions(); gdoptions.termCondDigitList = "12";
GatherDigitsResult gdresult = server.beginGatherDigits(sessionId, results.connectionId, gdoptions, state);
if(gdresult.returnValue != CuaeResult.SUCCESS) { Console.WriteLine("GatherDigit Failed"); server.removeCuaeSession(sessionId); server.sessionEnd(sessionId, null); } else { Console.WriteLine("GatherDigit Successful"); } } else if (state.ToString().Equals("Call2")) { Console.WriteLine("Now creating P2P bridge");
UnbridgeCallsResult ucr = server.unbridgeCalls(sessionId, g_CallId1, g_CallId2, null);
if (ucr.returnValue == CuaeResult.SUCCESS) { Console.WriteLine("The two calls are bridged successfully"); } else { Console.WriteLine("The two calls could not be bridged"); server.removeCuaeSession(sessionId); } } }
public override void onGatherDigitsComplete(String sessionId, GatherDigitsResult result, Object state) { if(result.digits.Contains("1")) { String str2 = "Call2"; MakeCallResult mcr1 = server.beginMakeCall(sessionId, DialNum2, "Test", "Test", null, str2); Console.WriteLine("Test 3:-"); if (mcr1.returnValue == CuaeResult.SUCCESS) { Console.WriteLine("Call Initiated successfully."); g_CallId2 = mcr1.callId; } else { Console.WriteLine("Make Call Failed!!!"); server.removeCuaeSession(sessionId); server.sessionEnd(sessionId,null); } } else { server.hangup(sessionId, g_CallId1, null); } } }}}
Build the Application#
To build the application. Go to Build->Build Solution
Packaging and loading the application#
- Once the above mentioned changes are made, open a command window and change directory to C:\Wxp\HttpInitiatedP2PCallBridge_csharp and run the below given command.
C:\Wxp\HttpInitiatedP2PCallBridge_csharp>cuae package
Installing The Test Application
To install the test application on a CUAE server, execute the cuae install command from a DOS command shell in test application parent directory of the test application. The cuae install command varies slightly between 2.5(1) Beta 1 and Beta 2.
2.5(1) Beta 2#
You are prompted to enter an IP address, username, and password (to view the help, run the cuae install -h command). When prompted, enter Y or N to save management settings. This will save the answers to the above three questions in the properties file and remember them the next time you go to install.
Note: You are also prompted for the communications protocol (TCP or TLS). Select the protocol that is set on the Management Service. TLS is the default supported protocol. If you want to use TCP, follow the instructions in Management Service Transport Layer Security (TLS) to change the default URI of the Management Service before running these commands.
C:\Wxp\HttpInitiatedP2PCallBridge_csharp>cuae packageCreated package file "C:\Wxp\HttpInitiatedP2PCallBridge_csharp\bin\HttpInitiatedP2PCallBridge_csharp.mca"
C:\Wxp\HttpInitiatedP2PCallBridge_csharp>cuae install Enter the hostname or IP address of the management service (for example: localhost, 1.1.1.1): localhost Protocol: tls Generated mgmt-service uri: tls://localhost:9001?TlsConnection.authReqd=false Enter management service login username: Entermanagement service login password: Save the amanagement settings with the project? [yes or no] n Application : C:\Wxp\HttpInitiatedP2PCallBridge_csharp\bin\HttpInitiatedP2PCallBridge_csharp.mca Uploading : ===========================> 100% Application has been installed successfully }}}
2.5(1) Beta 1#
You are prompted to enter an IP address, username, and password (to view the help, run the cuae install -h command). When prompted, enter Y or N to save management settings. This will save the answers to the above three questions in the properties file and remember them the next time you go to install.
C:\Wxp\HttpInitiatedP2PCallBridge_csharp>cuae packageCreated package file "C:\Wxp\HttpInitiatedP2PCallBridge_csharp\bin\HttpInitiatedP2PCallBridge_csharp.mca"
C:\Wxp\HttpInitiatedP2PCallBridge_csharp>cuae install Enter management service uri or host/IP <for example: localhost, tcp://1.1.1.1.:4001>: Enter management service login username: Entermanagement service login password: Save the amanagement settings with the project? [YyNn] n Application : C:\Wxp\HttpInitiatedP2PCallBridge_csharp\bin\HttpInitiatedP2PCallBridge_csharp.mca Uploading : ===========================> 100% Application ahas been installed successfully}}}
Note: You need to provide the uri for your application server. Like tcp://<IP address of your application server>:4001 and then you need to provide the login username and password for the application server.
- Before running the application, we need to make some configurations.
- Find the application you have just installed in CUAE Admin (Applications -> List Applications).
- Click on the application and configure the fields with DN's to place a call
Running the application#
- To run the application. Change directory to the bin\debug folder of the project and run the exe created.
C:\Wxp\HttpInitiatedP2PCallBridge_csharp\bin\Debug>HttpInitiatedP2PCallBridge_csharp.exe
- It will register the application with the application server and start waiting for the triggering event to occur.
- To trigger the application, open a web-page and write:
http://<IP address of the Application Server>:8000/P2PBridgedThis will trigger the application and it will start executing