Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LWP-7: make the auto-answer optional and compatable with older JS #112

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/lwpCall.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ direction terminating originating localIdentity remoteIdentity

| Name | Type | Default | Description |
| --------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| autoAnswer | boolean | true | If set to false the phone will not honor the auto-answer=0 header, requiring the user to always explicitly answer all calls |
| useAudioContext | boolean | false | Should the lwpAudioContext be used as the destination for the remote audio. See note. |
| globalKeyShortcuts | boolean | true | Should the event listeners in the 'keys' property be added to the document |
| keys.spacebar.enabled | boolean | true | If true, and globalKeyShortcuts is also true, preform keys.spacebar.action if the spacebar is pressed when the body of the document has the focus |
Expand Down
1 change: 1 addition & 0 deletions src/libwebphone.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default class extends EventEmitter {
userAgent: { enabled: true },
videoCanvas: { enabled: true },
call: {
autoAnswer: true,
useAudioContext: false,
globalKeyShortcuts: true,
startWithAudioMuted: false,
Expand Down
14 changes: 12 additions & 2 deletions src/lwpCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,18 @@ export default class lwpCall {
}

_shouldAutoAnswer() {
return this._session?._request?.headers["Call-Info"]
&& this._session._request.headers["Call-Info"][0].raw.includes("answer-after=0");
// Return false if autoAnswer is explicitly set to false
if (this._config.autoAnswer === false) {
return false;
}

// Check for the presence of Call-Info header and the "answer-after=0" value
if (this._session && this._session._request && this._session._request.headers && this._session._request.headers["Call-Info"]) {
const callInfo = this._session._request.headers["Call-Info"][0].raw;
return callInfo.includes("answer-after=0");
}

return false;
}

getId() {
Expand Down