-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/bg-filter-refactor
- Loading branch information
Showing
86 changed files
with
3,018 additions
and
4,904 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/client/docusaurus/docs/javascript/10-advanced/11-session-timers.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
id: session-timers | ||
title: Session Timers | ||
--- | ||
|
||
A session timer allows you to limit the maximum duration of a call. The duration | ||
[can be configured](https://getstream.io/video/docs/api/calls/#session-timers) | ||
for all calls of a certain type, or on a per-call basis. When a session timer | ||
reaches zero, the call automatically ends. | ||
|
||
## Creating a call with a session timer | ||
|
||
Let's see how to create a single call with a limited duration: | ||
|
||
```ts | ||
const callType = 'default'; | ||
const callId = 'test-call'; | ||
|
||
const call = client.call(callType, callId); | ||
await call.getOrCreate({ | ||
data: { | ||
settings_override: { | ||
limits: { | ||
max_duration_seconds: 3600, | ||
}, | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
This code creates a call with a duration of 3600 seconds (1 hour) from the time | ||
the session is starts (a participant joins the call). | ||
|
||
After joining the call with the specified `max_duration_seconds`, you can | ||
examine a session's `timer_ends_at` field, which provides the timestamp when the | ||
call will end. When a call ends, all participants are removed from the call. | ||
|
||
```ts | ||
await call.join(); | ||
console.log(call.state.session?.timer_ends_at); | ||
``` | ||
|
||
## Extending a call | ||
|
||
You can also extend the duration of a call, both before or during the call. To | ||
do that, you should use the `call.update` method: | ||
|
||
```ts | ||
await call.get(); | ||
// extend by 1 minute | ||
const duration = call.state.settings?.limits.max_duration_seconds + 60; | ||
|
||
await call.update({ | ||
settings_override: { | ||
limits: { | ||
max_duration_seconds: duration, | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
If the call duration is extended, the `timer_ends_at` is updated to reflect this | ||
change. Call participants will receive the `call.updated` event to notify them | ||
about this change. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@stream-io/video-client", | ||
"version": "1.4.1", | ||
"version": "1.4.3", | ||
"packageManager": "[email protected]", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.es.js", | ||
|
@@ -52,10 +52,10 @@ | |
"@vitest/coverage-v8": "^0.34.4", | ||
"dotenv": "^16.3.1", | ||
"happy-dom": "^11.0.2", | ||
"prettier": "^3.3.0", | ||
"rimraf": "^5.0.5", | ||
"prettier": "^3.3.2", | ||
"rimraf": "^5.0.7", | ||
"rollup": "^3.29.4", | ||
"typescript": "^5.4.3", | ||
"typescript": "^5.5.2", | ||
"vite": "^4.4.11", | ||
"vitest": "^0.34.4", | ||
"vitest-mock-extended": "^1.2.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { fromEventPattern, map } from 'rxjs'; | ||
import { isReactNative } from '../helpers/platforms'; | ||
import { getLogger } from '../logger'; | ||
import { disposeOfMediaStream } from './devices'; | ||
import { withoutConcurrency } from '../helpers/concurrency'; | ||
|
||
interface BrowserPermissionConfig { | ||
constraints: DisplayMediaStreamOptions; | ||
queryName: PermissionName; | ||
} | ||
|
||
export class BrowserPermission { | ||
private ready: Promise<void>; | ||
private disposeController = new AbortController(); | ||
private state: PermissionState | undefined; | ||
private wasPrompted: boolean = false; | ||
private listeners = new Set<(state: PermissionState) => void>(); | ||
private logger = getLogger(['permissions']); | ||
|
||
constructor(private readonly permission: BrowserPermissionConfig) { | ||
const signal = this.disposeController.signal; | ||
|
||
this.ready = (async () => { | ||
const assumeGranted = (error?: unknown) => { | ||
this.logger('warn', "Can't query permissions, assuming granted", { | ||
permission, | ||
error, | ||
}); | ||
this.setState('granted'); | ||
}; | ||
|
||
if (!canQueryPermissions()) { | ||
return assumeGranted(); | ||
} | ||
|
||
try { | ||
const status = await navigator.permissions.query({ | ||
name: permission.queryName, | ||
}); | ||
|
||
if (!signal.aborted) { | ||
this.setState(status.state); | ||
status.addEventListener('change', () => this.setState(status.state), { | ||
signal, | ||
}); | ||
} | ||
} catch (err) { | ||
assumeGranted(err); | ||
} | ||
})(); | ||
} | ||
|
||
dispose() { | ||
this.state = undefined; | ||
this.disposeController.abort(); | ||
} | ||
|
||
async getState() { | ||
await this.ready; | ||
if (!this.state) { | ||
throw new Error('BrowserPermission instance possibly disposed'); | ||
} | ||
return this.state; | ||
} | ||
|
||
async prompt({ | ||
forcePrompt = false, | ||
throwOnNotAllowed = false, | ||
}: { forcePrompt?: boolean; throwOnNotAllowed?: boolean } = {}) { | ||
await withoutConcurrency( | ||
`permission-prompt-${this.permission.queryName}`, | ||
async () => { | ||
if ( | ||
(await this.getState()) !== 'prompt' || | ||
(this.wasPrompted && !forcePrompt) | ||
) { | ||
const isGranted = this.state === 'granted'; | ||
|
||
if (!isGranted && throwOnNotAllowed) { | ||
throw new DOMException( | ||
'Permission was not granted previously, and prompting again is not allowed', | ||
'NotAllowedError', | ||
); | ||
} | ||
|
||
return isGranted; | ||
} | ||
|
||
try { | ||
this.wasPrompted = true; | ||
const stream = await navigator.mediaDevices.getUserMedia( | ||
this.permission.constraints, | ||
); | ||
disposeOfMediaStream(stream); | ||
return true; | ||
} catch (e) { | ||
if (e instanceof DOMException && e.name === 'NotAllowedError') { | ||
this.logger('info', 'Browser permission was not granted', { | ||
permission: this.permission, | ||
}); | ||
|
||
if (throwOnNotAllowed) { | ||
throw e; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
this.logger('error', `Failed to getUserMedia`, { | ||
error: e, | ||
permission: this.permission, | ||
}); | ||
throw e; | ||
} | ||
}, | ||
); | ||
} | ||
|
||
listen(cb: (state: PermissionState) => void) { | ||
this.listeners.add(cb); | ||
if (this.state) cb(this.state); | ||
return () => this.listeners.delete(cb); | ||
} | ||
|
||
asObservable() { | ||
return fromEventPattern<PermissionState>( | ||
(handler) => this.listen(handler), | ||
(handler, unlisten) => unlisten(), | ||
).pipe( | ||
// In some browsers, the 'change' event doesn't reliably emit and hence, | ||
// permissionState stays in 'prompt' state forever. | ||
// Typically, this happens when a user grants one-time permission. | ||
// Instead of checking if a permission is granted, we check if it isn't denied | ||
map((state) => state !== 'denied'), | ||
); | ||
} | ||
|
||
private setState(state: PermissionState) { | ||
if (this.state !== state) { | ||
this.state = state; | ||
this.listeners.forEach((listener) => listener(state)); | ||
} | ||
} | ||
} | ||
|
||
function canQueryPermissions() { | ||
return ( | ||
!isReactNative() && | ||
typeof navigator !== 'undefined' && | ||
!!navigator.permissions?.query | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.