Windows 8 Bluetooth Call Control

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.