Bluetooth call control example Bluetooth callcontrol example shows how to configure the default Bluetooth communication device for processing calls. This example is written in Javascript. You also need to understand HTML, Windows events, and event processing. Program . ( Function (){
//Initialize the call control object here using the default Bluetooth communications device
VaRCallcontrols =Null;
VaRCalltoken;
VaRAudiotag;
FunctionID (elementid ){
ReturnDocument. getelementbyid (elementid );
}
FunctionInitdevice (){
If(! Callcontrols ){
Callcontrols = windows. Media. devices. callcontrol. getdefault ();
If (Callcontrols ){
// Add the event listener to listen for the various button presses
Callcontrols. addeventlistener ("answerrequested", answerbutton, False );
Callcontrols. addeventlistener ("hanguprequested", hangupbutton, False );
Callcontrols. addeventlistener ("audiotransferrequested", audiotransferbutton, False );
Callcontrols. addeventlistener ("redialrequested", redialbutton, False );
Callcontrols. addeventlistener ("dialrequested", dialbutton, False );
Sdksample. displaystatus ("Call controls initialized ");
ID ("scenario1ring"). Disabled = False ;
ID ("scenario1initialize"). Disabled = True ;
} Else {
Sdksample. displayerror ("no Bluetooth device detected .");
}
}
}
FunctionNewincomingcall (){
//Indicate a new incoming call and ring the headset.
Calltoken = callcontrols. indicatenewincomingcall (True("5555555555 ");
Sdksample. displaystatus ("Call token:" + calltoken );
ID ("scenario1ring"). Disabled =True;
}
Function Answerbutton (){
// When the answer button is pressed indicate to the device that the call was answered
// And start a song on the headset (this is done by streaming music to the Bluetooth
// Device in this sample)
Sdksample. displaystatus ("answer requested:" + calltoken );
Callcontrols. indicateactivecall (calltoken );
Audiotag = Document. getelementbyid ("audiotag ");
Audiotag. Play ();
}
Function Hangupbutton (){
// Hang up request received ed. The application shocould end the active call and stop
// Streaming to the headset
Sdksample. displaystatus ("hangup requested ");
Callcontrols. endcall (calltoken );
Audiotag = Document. getelementbyid ("audiotag ");
Audiotag. Pause ();
ID ("scenario1ring"). Disabled = False ;
}
FunctionAudiotransferbutton (){
//Handle the audio transfer request here
Sdksample. displaystatus ("audio transfer requested ");
}
FunctionRedialbutton (redialrequestedeventargs ){
//Handle the redial request here. indicate to the device that the request was handled.
Sdksample. displaystatus ("redial requested ");
Redialrequestedeventargs. Handled ();
}
Function Dialbutton (dialrequestedeventargs ){
// A device may send a dial request by either sending a URI or if it is a speed dial,
// An integer with the number to dial.
If ( Typeof (Dialrequestedeventargs. Contact) = "Number "){
Sdksample. displaystatus ("dial requested:" + dialrequestedeventargs. Contact );
Dialrequestedeventargs. Handled ();
}
Else {
Sdksample. displaystatus ("dial requested:" + dialrequestedeventargs. Contact. schemename + ":" +
Dialrequestedeventargs. Contact. Path );
Dialrequestedeventargs. Handled ();
}
}
FunctionInitialize (){
ID ("scenario1initialize"). addeventlistener ("click", initdevice,False);
ID ("scenario1ring"). addeventlistener ("click", newincomingcall,False);
ID ("scenarios"). addeventlistener ("change", onscenariochanged,False);
}
FunctionOnscenariochanged (){
Sdksample. displaystatus ("");
}
Document. addeventlistener ("domcontentloaded", initialize,False);
})();
Complete example/files/risk/windows8/Bluetooth controls sample.rar