-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaudio.html
109 lines (87 loc) · 3.22 KB
/
audio.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<head>
<title>Respoke - Audio Calling Example</title>
<!-- Respoke client library -->
<script src="https://cdn.respoke.io/respoke.min.js"></script>
<!-- jQuery, for this example -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<!-- Some simple styles to make things perty -->
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h3 id="status">Not Connected</h3>
<div id="login">
<input id="endpoint" placeholder="Username" type="text" />
<button id="doLogin">Connect</button>
</div>
<div>
<input id="remoteId" placeholder="User to Call" type="text" />
<button id="doCall">Call</button>
<button id="doHangUp">Hang Up</button>
</div>
<script type="text/javascript">
// App ID value from the dev portal. You can play
// around with the supplied ID or replace it with
// your own.
var appid = "b4931d40-ff2b-4c46-8487-bf955a75501d";
var activeCall;
// The ID that other users will identify you by (your username)
var endpointId;
// Create the client object using the App ID
var client = respoke.createClient({
appId: appid,
developmentMode: true
});
// "connect" event fired after successful connection to Respoke
client.listen('connect', function() {
$("#status").html("Connected to Respoke as \"" + endpointId + "\"");
console.log("Client: ", client);
});
// Connect to Respoke when the user clicks "connect"
$("#doLogin").click(function() {
$("#status").html("Connecting...");
endpointId = $("#endpoint").val();
client.connect({
endpointId: endpointId // your username is the endpoint
});
});
// Listen for incoming calls
client.listen('call', function(evt) {
activeCall = evt.call;
// We only want to answer if we didn't initiate the call
if(activeCall.caller !== true) {
// Answer the call
activeCall.answer();
// The hangup event indicates the call is over
activeCall.listen('hangup', function () {
hangUp();
});
}
});
// Call the recipient
$("#doCall").click(function() {
var recipientId = $("#remoteId").val();
client.startAudioCall({
endpointId: recipientId,
onConnect: function (evt) {
// Your Audio
// evt.element contains <video> element with audio stream
},
onLocalMedia: function (evt) {
// The Recipients Audio
// evt.element contains <video> element with audio stream
}
});
});
// Hangup the call
$("#doHangUp").click(hangUp);
// End the current call
function hangUp() {
if( activeCall ){
activeCall.hangup();
activeCall = null;
}
}
</script>
</body>
</html>