Compare commits

...

66 Commits

Author SHA1 Message Date
Jim Gustafson
9a9d9fbc1c Update to RingRTC v2.22.0 2022-11-28 17:45:27 -08:00
Jim Gustafson
e062457b82 Update to RingRTC v2.21.5 2022-11-11 11:40:11 -08:00
Jim Gustafson
3b9c6d607c Update to RingRTC v2.21.3 2022-10-27 21:56:17 -07:00
Jim Gustafson
7e1b508953 Update to RingRTC v2.21.2 2022-10-05 14:19:22 -07:00
Jim Gustafson
6c3a7f12df Update to RingRTC v2.21.1 2022-09-23 14:00:24 -07:00
Jim Gustafson
25788b37d3 Update to RingRTC v2.21.0 2022-08-30 17:50:44 -07:00
Jim Gustafson
928dae72e8 Update to RingRTC v2.20.14 2022-08-16 14:48:01 -07:00
Jim Gustafson
009b3eec4f Update to RingRTC v2.20.13 2022-07-29 13:52:42 -07:00
Jim Gustafson
d2a43fa1e5 Update to RingRTC v2.20.12 2022-07-22 10:53:13 -07:00
Jim Gustafson
3e05d7ec7b Update to RingRTC v2.20.11 2022-06-30 15:42:14 -07:00
Jim Gustafson
4450aa43e0 Update to RingRTC v2.20.10 2022-06-22 13:54:37 -07:00
Jim Gustafson
af944ae043 Update to RingRTC v2.20.9 2022-06-17 15:37:27 -07:00
Jim Gustafson
ebd88d19b7 Update to RingRTC v2.20.8 2022-06-02 18:48:13 -07:00
Jim Gustafson
d00319a015 Update to RingRTC v2.20.7 2022-05-26 16:08:13 -07:00
Jim Gustafson
b70d7fd947 Update to RingRTC v2.20.6 2022-05-20 21:28:38 -07:00
Jim Gustafson
89a47c3ae7 Update to RingRTC v2.20.5 2022-05-05 22:50:58 -07:00
Jim Gustafson
ccb71f118a Update to RingRTC v2.20.4 2022-04-29 12:12:53 -07:00
Jim Gustafson
e66b5511e6 Update to RingRTC v2.20.2 2022-04-21 19:32:30 -07:00
Jim Gustafson
0464fe30a7 Update to RingRTC v2.20.1 2022-04-06 16:04:54 -07:00
Jim Gustafson
fc3a17abb2 Update to RingRTC v2.20.0 2022-03-17 19:43:34 -07:00
Jim Gustafson
9d03ddf06f Update to RingRTC v2.19.2 2022-03-04 09:35:15 -08:00
Jim Gustafson
a32abe1c72 Update to RingRTC v2.19.0 2022-03-01 19:40:42 -08:00
Jim Gustafson
561484a82f Update to RingRTC v2.18.0 2022-02-02 22:19:42 -08:00
Jim Gustafson
f22009252b Update to RingRTC v2.17.2 2022-01-28 11:14:56 -08:00
Jim Gustafson
f25f900355 Update to RingRTC v2.17.0 2022-01-14 16:56:29 -08:00
Jim Gustafson
4cfc6e77af Update to RingRTC v2.16.1 2021-12-17 10:57:16 -08:00
Jim Gustafson
7564aff3d1 Update to RingRTC v2.16.0 2021-12-03 11:09:33 -08:00
Jim Gustafson
7a17d31bc0 Update to RingRTC v2.15.0 2021-11-19 15:12:26 -08:00
Jim Gustafson
3688e37493 Update to RingRTC v2.14.3 2021-11-18 16:56:24 -08:00
Jim Gustafson
17f0615e7e Update to RingRTC v2.14.2 2021-11-15 16:20:27 -08:00
Jim Gustafson
011bdd9a71 Update to RingRTC v2.14.1 2021-11-09 16:58:33 -08:00
Jim Gustafson
fb4701c8b1 Update to RingRTC v2.14.0 2021-11-05 16:04:11 -07:00
Jim Gustafson
f876415675 Update to RingRTC v2.13.6 2021-10-21 14:02:21 -07:00
Jim Gustafson
d40ca0729b Update to RingRTC v2.13.5 2021-10-15 11:49:31 -07:00
Jim Gustafson
9b4ff94737 Update to RingRTC v2.13.4 2021-10-05 16:24:07 -07:00
Jim Gustafson
721fba9620 Update to RingRTC v2.13.3 2021-10-02 13:29:53 -07:00
Jim Gustafson
3f842dc9ce Update to RingRTC v2.13.2 2021-09-28 10:35:51 -07:00
Jim Gustafson
8b028d8f1e Update to RingRTC v2.13.1 2021-09-21 14:12:04 -07:00
Jim Gustafson
432139dfeb Update to RingRTC v2.13.0 2021-09-10 15:46:34 -07:00
Jim Gustafson
a0ce3a13fb Update to RingRTC v2.12.0 2021-08-31 21:26:14 -07:00
Jim Gustafson
031abcc756 Update to RingRTC v2.11.1 2021-08-18 15:36:53 -07:00
Jim Gustafson
800b31c5d4 Update to RingRTC v2.11.0 2021-08-16 17:49:43 -07:00
Jim Gustafson
677ece9c3b Update to RingRTC v2.10.7 2021-07-23 18:26:38 -07:00
Jim Gustafson
868f7ecb69 Update to RingRTC v2.10.6 2021-06-28 15:36:02 -07:00
Jim Gustafson
0956fdc542 Release Candidate 1 of RingRTC v2.10.6 2021-06-18 11:15:09 -07:00
Jim Gustafson
a669f0becf Update to RingRTC v2.10.5 2021-06-09 11:35:31 -07:00
Jim Gustafson
ff5a8cbc0e Update to RingRTC v2.10.4 2021-06-02 17:42:52 -07:00
Jim Gustafson
d44ffdaa1e Update to RingRTC v2.10.3 2021-05-31 22:35:55 -07:00
Jim Gustafson
0067701691 Update to RingRTC v2.10.2 2021-05-29 00:14:25 -07:00
Jim Gustafson
17b22fc9d4 Update to RingRTC v2.10.1 2021-05-19 14:13:02 -07:00
Jim Gustafson
298628379a Update to RingRTC v2.10.0 2021-05-12 15:36:23 -07:00
Jim Gustafson
0384c6f1b2 Update to RingRTC v2.9.7 2021-05-06 16:39:07 -07:00
Jim Gustafson
36332761d5 Update to RingRTC v2.9.6 2021-04-24 04:45:40 -07:00
Jim Gustafson
78a5557590 Update to RingRTC v2.9.5 2021-04-23 14:21:37 -07:00
Jim Gustafson
b43c6b728d Update to RingRTC v2.9.4 2021-03-01 18:40:20 -08:00
Jim Gustafson
ecc8dbdfe9 Update to RingRTC v2.9.3 2021-02-10 10:49:21 -08:00
Jim Gustafson
552582f971 Update to RingRTC v2.9.2 2021-01-28 18:43:34 -08:00
Jim Gustafson
c0b1416ab1 Update to RingRTC v2.9.1 2021-01-22 16:25:42 -08:00
Jim Gustafson
3235e40ef2 Release Candidate 1 of RingRTC v2.8.10 2020-12-15 17:02:14 -08:00
Jim Gustafson
82d1f84fda Update to RingRTC v2.8.9 2020-12-14 18:04:21 -08:00
Jim Gustafson
5bab04da0b Update to RingRTC v2.8.7 2020-12-07 12:03:56 -08:00
Jim Gustafson
054c5b4797 Update to RingRTC v2.8.6 2020-12-04 15:41:02 -08:00
Jim Gustafson
dd1400e829 Update to RingRTC v2.8.5 2020-12-02 12:18:19 -08:00
Jim Gustafson
eb01373e32 Update to RingRTC v2.8.4 2020-11-26 08:34:32 -08:00
Jim Gustafson
e0c31ca672 Update to RingRTC v2.8.3 2020-11-19 18:05:47 -08:00
Jim Gustafson
aec1d34326 Update to RingRTC v2.8.2 2020-11-19 15:35:09 -08:00
19 changed files with 5054 additions and 2293 deletions

157
LICENSE
View File

@ -1,29 +1,21 @@
This software is provided under:
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
SPDX-License-Identifier: GPL-3.0-only
The complete license text:
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
@ -32,44 +24,34 @@ them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
@ -78,7 +60,7 @@ modification follow.
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
@ -555,35 +537,45 @@ to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
@ -626,3 +618,44 @@ copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.

View File

@ -1,16 +1,27 @@
# RingRTC
RingRTC is a middleware library providing [Signal
Messenger](https://www.signal.org/) applications with video and voice
calling services built on top of [WebRTC](https://webrtc.org/).
RingRTC is a middleware library providing [Signal Messenger](https://www.signal.org/) applications with video and voice calling services built on top of [WebRTC](https://webrtc.org/).
## Building
For building RingRTC see [BUILDING.md](BUILDING.md).
<br/>
## Contributing
Contributions to this project are welcome. Pull requests should be tested across all supported platforms.
-----------------
For larger changes and feature ideas, we ask that you propose it on the [unofficial Community Forum](https://community.signalusers.org) for a high-level discussion with the wider community before implementation.
Copyright (C) 2020 Signal Messenger, LLC.<br/>
All rights reserved.
Signing a [CLA (Contributor License Agreement)](https://signal.org/cla/) is required for all contributions.
Licensed under [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) only.
# Legal things
## Cryptography Notice
This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See <http://www.wassenaar.org/> for more information.
The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms. The form and manner of this distribution makes it eligible for export under the License Exception ENC Technology Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for both object code and source code.
## License
Copyright 2019-2021 Signal Messenger, LLC<br/>
Licensed under [AGPLv3](https://www.gnu.org/licenses/agpl-3.0.html) only.

Binary file not shown.

BIN
build/linux/libringrtc-arm64.node Executable file

Binary file not shown.

BIN
build/win32/libringrtc-arm64.node Executable file

Binary file not shown.

4
dist/index.d.ts vendored
View File

@ -1,4 +1,4 @@
export { AudioDevice, BandwidthMode, Call, CallId, CallEndedReason, CallLogLevel, CallState, CallingMessage, CallSettings, ConnectionState, DeviceId, GroupCall, GroupCallEndReason, GroupCallObserver, GroupMemberInfo, HangupMessage, HangupType, HttpMethod, JoinState, LocalDeviceState, OfferType, OpaqueMessage, RemoteDeviceState, RenderedResolution, RingRTCType, UserId, VideoCapturer, VideoRenderer } from './ringrtc/Service';
export { CanvasVideoRenderer, GumVideoCapturer, VideoFrameSource, } from './ringrtc/VideoSupport';
export { AudioDevice, BandwidthMode, Call, CallEndedReason, CallId, CallLogLevel, CallMessageUrgency, CallSettings, CallState, CallingMessage, ConnectionState, DeviceId, GroupCall, GroupCallEndReason, GroupCallObserver, GroupMemberInfo, HangupMessage, HangupType, HttpMethod, JoinState, LocalDeviceState, OfferType, OpaqueMessage, PeekInfo, RemoteDeviceState, RingCancelReason, RingRTCType, RingUpdate, UserId, VideoCapturer, VideoRenderer, VideoRequest, } from './ringrtc/Service';
export { CanvasVideoRenderer, GumVideoCapturer, VideoFrameSource, MAX_VIDEO_CAPTURE_AREA, MAX_VIDEO_CAPTURE_BUFFER_SIZE, MAX_VIDEO_CAPTURE_HEIGHT, MAX_VIDEO_CAPTURE_WIDTH, } from './ringrtc/VideoSupport';
import { RingRTCType } from './ringrtc/Service';
export declare const RingRTC: RingRTCType;

59
dist/index.js vendored
View File

@ -1,34 +1,41 @@
"use strict";
//
// Copyright (C) 2020 Signal Messenger, LLC.
// All rights reserved.
//
// SPDX-License-Identifier: GPL-3.0-only
// Copyright 2019-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
Object.defineProperty(exports, "__esModule", { value: true });
exports.RingRTC = exports.MAX_VIDEO_CAPTURE_WIDTH = exports.MAX_VIDEO_CAPTURE_HEIGHT = exports.MAX_VIDEO_CAPTURE_BUFFER_SIZE = exports.MAX_VIDEO_CAPTURE_AREA = exports.GumVideoCapturer = exports.CanvasVideoRenderer = exports.VideoRequest = exports.RingUpdate = exports.RingRTCType = exports.RingCancelReason = exports.RemoteDeviceState = exports.PeekInfo = exports.OpaqueMessage = exports.OfferType = exports.LocalDeviceState = exports.JoinState = exports.HttpMethod = exports.HangupType = exports.HangupMessage = exports.GroupMemberInfo = exports.GroupCallEndReason = exports.GroupCall = exports.ConnectionState = exports.CallingMessage = exports.CallState = exports.CallMessageUrgency = exports.CallLogLevel = exports.CallEndedReason = exports.Call = exports.BandwidthMode = void 0;
var Service_1 = require("./ringrtc/Service");
exports.BandwidthMode = Service_1.BandwidthMode;
exports.Call = Service_1.Call;
exports.CallEndedReason = Service_1.CallEndedReason;
exports.CallLogLevel = Service_1.CallLogLevel;
exports.CallState = Service_1.CallState;
exports.CallingMessage = Service_1.CallingMessage;
exports.ConnectionState = Service_1.ConnectionState;
exports.GroupCall = Service_1.GroupCall;
exports.GroupCallEndReason = Service_1.GroupCallEndReason;
exports.GroupMemberInfo = Service_1.GroupMemberInfo;
exports.HangupMessage = Service_1.HangupMessage;
exports.HangupType = Service_1.HangupType;
exports.HttpMethod = Service_1.HttpMethod;
exports.JoinState = Service_1.JoinState;
exports.LocalDeviceState = Service_1.LocalDeviceState;
exports.OfferType = Service_1.OfferType;
exports.OpaqueMessage = Service_1.OpaqueMessage;
exports.RemoteDeviceState = Service_1.RemoteDeviceState;
exports.RenderedResolution = Service_1.RenderedResolution;
exports.RingRTCType = Service_1.RingRTCType;
Object.defineProperty(exports, "BandwidthMode", { enumerable: true, get: function () { return Service_1.BandwidthMode; } });
Object.defineProperty(exports, "Call", { enumerable: true, get: function () { return Service_1.Call; } });
Object.defineProperty(exports, "CallEndedReason", { enumerable: true, get: function () { return Service_1.CallEndedReason; } });
Object.defineProperty(exports, "CallLogLevel", { enumerable: true, get: function () { return Service_1.CallLogLevel; } });
Object.defineProperty(exports, "CallMessageUrgency", { enumerable: true, get: function () { return Service_1.CallMessageUrgency; } });
Object.defineProperty(exports, "CallState", { enumerable: true, get: function () { return Service_1.CallState; } });
Object.defineProperty(exports, "CallingMessage", { enumerable: true, get: function () { return Service_1.CallingMessage; } });
Object.defineProperty(exports, "ConnectionState", { enumerable: true, get: function () { return Service_1.ConnectionState; } });
Object.defineProperty(exports, "GroupCall", { enumerable: true, get: function () { return Service_1.GroupCall; } });
Object.defineProperty(exports, "GroupCallEndReason", { enumerable: true, get: function () { return Service_1.GroupCallEndReason; } });
Object.defineProperty(exports, "GroupMemberInfo", { enumerable: true, get: function () { return Service_1.GroupMemberInfo; } });
Object.defineProperty(exports, "HangupMessage", { enumerable: true, get: function () { return Service_1.HangupMessage; } });
Object.defineProperty(exports, "HangupType", { enumerable: true, get: function () { return Service_1.HangupType; } });
Object.defineProperty(exports, "HttpMethod", { enumerable: true, get: function () { return Service_1.HttpMethod; } });
Object.defineProperty(exports, "JoinState", { enumerable: true, get: function () { return Service_1.JoinState; } });
Object.defineProperty(exports, "LocalDeviceState", { enumerable: true, get: function () { return Service_1.LocalDeviceState; } });
Object.defineProperty(exports, "OfferType", { enumerable: true, get: function () { return Service_1.OfferType; } });
Object.defineProperty(exports, "OpaqueMessage", { enumerable: true, get: function () { return Service_1.OpaqueMessage; } });
Object.defineProperty(exports, "PeekInfo", { enumerable: true, get: function () { return Service_1.PeekInfo; } });
Object.defineProperty(exports, "RemoteDeviceState", { enumerable: true, get: function () { return Service_1.RemoteDeviceState; } });
Object.defineProperty(exports, "RingCancelReason", { enumerable: true, get: function () { return Service_1.RingCancelReason; } });
Object.defineProperty(exports, "RingRTCType", { enumerable: true, get: function () { return Service_1.RingRTCType; } });
Object.defineProperty(exports, "RingUpdate", { enumerable: true, get: function () { return Service_1.RingUpdate; } });
Object.defineProperty(exports, "VideoRequest", { enumerable: true, get: function () { return Service_1.VideoRequest; } });
var VideoSupport_1 = require("./ringrtc/VideoSupport");
exports.CanvasVideoRenderer = VideoSupport_1.CanvasVideoRenderer;
exports.GumVideoCapturer = VideoSupport_1.GumVideoCapturer;
Object.defineProperty(exports, "CanvasVideoRenderer", { enumerable: true, get: function () { return VideoSupport_1.CanvasVideoRenderer; } });
Object.defineProperty(exports, "GumVideoCapturer", { enumerable: true, get: function () { return VideoSupport_1.GumVideoCapturer; } });
Object.defineProperty(exports, "MAX_VIDEO_CAPTURE_AREA", { enumerable: true, get: function () { return VideoSupport_1.MAX_VIDEO_CAPTURE_AREA; } });
Object.defineProperty(exports, "MAX_VIDEO_CAPTURE_BUFFER_SIZE", { enumerable: true, get: function () { return VideoSupport_1.MAX_VIDEO_CAPTURE_BUFFER_SIZE; } });
Object.defineProperty(exports, "MAX_VIDEO_CAPTURE_HEIGHT", { enumerable: true, get: function () { return VideoSupport_1.MAX_VIDEO_CAPTURE_HEIGHT; } });
Object.defineProperty(exports, "MAX_VIDEO_CAPTURE_WIDTH", { enumerable: true, get: function () { return VideoSupport_1.MAX_VIDEO_CAPTURE_WIDTH; } });
const Service_2 = require("./ringrtc/Service");
exports.RingRTC = new Service_2.RingRTCType();

View File

@ -1,48 +1,110 @@
/// <reference types="node" />
import { GumVideoCaptureOptions, VideoPixelFormatEnum } from './VideoSupport';
declare class Config {
use_new_audio_device_module: boolean;
}
declare type GroupId = Buffer;
declare type GroupCallUserId = Buffer;
export declare class PeekDeviceInfo {
demuxId: number;
userId?: GroupCallUserId;
constructor(demuxId: number, userId: GroupCallUserId | undefined);
}
export declare class PeekInfo {
devices: Array<PeekDeviceInfo>;
creator?: GroupCallUserId;
eraId?: string;
maxDevices?: number;
deviceCount: number;
constructor();
}
declare enum NetworkAdapterType {
Unknown = 0,
Ethernet = 1,
Wifi = 2,
Cellular = 4,
Vpn = 8,
Loopback = 16,
Default = 32,
Cellular2G = 64,
Cellular3G = 128,
Cellular4G = 256,
Cellular5G = 512
}
export declare class NetworkRoute {
localAdapterType: NetworkAdapterType;
constructor();
}
export declare type RawAudioLevel = number;
export declare type NormalizedAudioLevel = number;
export declare class ReceivedAudioLevel {
demuxId: number;
level: RawAudioLevel;
constructor(demuxId: number, level: RawAudioLevel);
}
export declare class RingRTCType {
private readonly callManager;
private _call;
private _groupCallByClientId;
private _peekRequests;
private _callInfoByCallId;
private getCallInfoKey;
handleOutgoingSignaling: ((remoteUserId: UserId, message: CallingMessage) => Promise<boolean>) | null;
handleIncomingCall: ((call: Call) => Promise<CallSettings | null>) | null;
handleAutoEndedIncomingCallRequest: ((remoteUserId: UserId, reason: CallEndedReason) => void) | null;
handleAutoEndedIncomingCallRequest: ((callId: CallId, remoteUserId: UserId, reason: CallEndedReason, ageSec: number, wasVideoCall: boolean, receivedAtCounter: number | undefined) => void) | null;
handleLogMessage: ((level: CallLogLevel, fileName: string, line: number, message: string) => void) | null;
handleSendHttpRequest: ((requestId: number, url: string, method: HttpMethod, headers: {
[name: string]: string;
}, body: ArrayBuffer | undefined) => void) | null;
handleSendCallMessage: ((recipientUuid: ArrayBuffer, message: ArrayBuffer) => void) | null;
}, body: Buffer | undefined) => void) | null;
handleSendCallMessage: ((recipientUuid: Buffer, message: Buffer, urgency: CallMessageUrgency) => void) | null;
handleSendCallMessageToGroup: ((groupId: Buffer, message: Buffer, urgency: CallMessageUrgency) => void) | null;
handleGroupCallRingUpdate: ((groupId: Buffer, ringId: bigint, sender: Buffer, update: RingUpdate) => void) | null;
constructor();
private pollEvery;
setConfig(config: Config): void;
setSelfUuid(uuid: Buffer): void;
startOutgoingCall(remoteUserId: UserId, isVideoCall: boolean, localDeviceId: DeviceId, settings: CallSettings): Call;
cancelGroupRing(groupId: GroupId, ringId: bigint, reason: RingCancelReason | null): void;
onStartOutgoingCall(remoteUserId: UserId, callId: CallId): void;
onStartIncomingCall(remoteUserId: UserId, callId: CallId, isVideoCall: boolean): void;
private proceed;
onCallState(remoteUserId: UserId, state: CallState): void;
onCallEnded(remoteUserId: UserId, reason: CallEndedReason): void;
onCallEnded(remoteUserId: UserId, callId: CallId, reason: CallEndedReason, ageSec: number): void;
onRemoteVideoEnabled(remoteUserId: UserId, enabled: boolean): void;
renderVideoFrame(width: number, height: number, buffer: ArrayBuffer): void;
onSendOffer(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, offerType: OfferType, opaque?: ArrayBuffer, sdp?: string): void;
onSendAnswer(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, opaque?: ArrayBuffer, sdp?: string): void;
onSendIceCandidates(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, candidates: Array<IceCandidateMessage>): void;
onSendLegacyHangup(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, hangupType: HangupType, deviceId: DeviceId | null): void;
onRemoteSharingScreen(remoteUserId: UserId, enabled: boolean): void;
onNetworkRouteChanged(remoteUserId: UserId, localNetworkAdapterType: NetworkAdapterType): void;
onAudioLevels(remoteUserId: UserId, capturedLevel: RawAudioLevel, receivedLevel: RawAudioLevel): void;
renderVideoFrame(width: number, height: number, buffer: Buffer): void;
onSendOffer(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, offerType: OfferType, opaque: Buffer): void;
onSendAnswer(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, opaque: Buffer): void;
onSendIceCandidates(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, candidates: Array<Buffer>): void;
onSendHangup(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, hangupType: HangupType, deviceId: DeviceId | null): void;
onSendBusy(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean): void;
private sendSignaling;
receivedHttpResponse(requestId: number, status: number, body: ArrayBuffer): void;
receivedHttpResponse(requestId: number, status: number, body: Buffer): void;
httpRequestFailed(requestId: number, debugInfo: string | undefined): void;
getGroupCall(groupId: ArrayBuffer, observer: GroupCallObserver): GroupCall | undefined;
getGroupCall(groupId: Buffer, sfuUrl: string, hkdfExtraInfo: Buffer, audioLevelsIntervalMillis: number | undefined, observer: GroupCallObserver): GroupCall | undefined;
peekGroupCall(sfuUrl: string, membershipProof: Buffer, groupMembers: Array<GroupMemberInfo>): Promise<PeekInfo>;
requestMembershipProof(clientId: GroupCallClientId): void;
requestGroupMembers(clientId: GroupCallClientId): void;
handleConnectionStateChanged(clientId: GroupCallClientId, connectionState: ConnectionState): void;
handleJoinStateChanged(clientId: GroupCallClientId, joinState: JoinState): void;
handleJoinStateChanged(clientId: GroupCallClientId, joinState: JoinState, demuxId: number | undefined): void;
handleNetworkRouteChanged(clientId: GroupCallClientId, localNetworkAdapterType: NetworkAdapterType): void;
handleAudioLevels(clientId: GroupCallClientId, capturedLevel: RawAudioLevel, receivedLevels: Array<ReceivedAudioLevel>): void;
handleRemoteDevicesChanged(clientId: GroupCallClientId, remoteDeviceStates: Array<RemoteDeviceState>): void;
handleJoinedMembersChanged(clientId: GroupCallClientId, members: Array<ArrayBuffer>): void;
handlePeekChanged(clientId: GroupCallClientId, info: PeekInfo): void;
handlePeekResponse(request_id: number, info: PeekInfo): void;
handleEnded(clientId: GroupCallClientId, reason: GroupCallEndReason): void;
groupCallRingUpdate(groupId: GroupId, ringIdString: string, sender: GroupCallUserId, state: RingUpdate): void;
onLogMessage(level: number, fileName: string, line: number, message: string): void;
handleCallingMessage(remoteUserId: UserId, remoteUuid: ArrayBuffer | null, remoteDeviceId: DeviceId, localDeviceId: DeviceId, messageAgeSec: number, message: CallingMessage, senderIdentityKey: ArrayBuffer, receiverIdentityKey: ArrayBuffer): void;
logError(message: string): void;
logWarn(message: string): void;
logInfo(message: string): void;
handleCallingMessage(remoteUserId: UserId, remoteUuid: Buffer | null, remoteDeviceId: DeviceId, localDeviceId: DeviceId, messageAgeSec: number, messageReceivedAtCounter: number, message: CallingMessage, senderIdentityKey: Buffer, receiverIdentityKey: Buffer): void;
sendHttpRequest(requestId: number, url: string, method: HttpMethod, headers: {
[name: string]: string;
}, body: ArrayBuffer | undefined): void;
sendCallMessage(recipientUuid: ArrayBuffer, message: ArrayBuffer): void;
}, body: Buffer | undefined): void;
sendCallMessage(recipientUuid: Buffer, message: Buffer, urgency: CallMessageUrgency): void;
sendCallMessageToGroup(groupId: Buffer, message: Buffer, urgency: CallMessageUrgency): void;
get call(): Call | null;
getCall(callId: CallId): Call | null;
accept(callId: CallId, asVideoCall: boolean): void;
@ -51,6 +113,7 @@ export declare class RingRTCType {
hangup(callId: CallId): void;
setOutgoingAudio(callId: CallId, enabled: boolean): void;
setOutgoingVideo(callId: CallId, enabled: boolean): void;
setOutgoingVideoIsScreenShare(callId: CallId, isScreenShare: boolean): void;
setVideoCapturer(callId: CallId, capturer: VideoCapturer | null): void;
setVideoRenderer(callId: CallId, renderer: VideoRenderer | null): void;
getAudioInputs(): AudioDevice[];
@ -61,6 +124,8 @@ export declare class RingRTCType {
export interface CallSettings {
iceServer: IceServer;
hideIp: boolean;
bandwidthMode: BandwidthMode;
audioLevelsIntervalMillis?: number;
}
interface IceServer {
username?: string;
@ -75,7 +140,7 @@ export interface AudioDevice {
}
export interface VideoCapturer {
enableCapture(): void;
enableCaptureAndSend(call: Call): void;
enableCaptureAndSend(call: Call, captureOptions?: GumVideoCaptureOptions): void;
disable(): void;
}
export interface VideoRenderer {
@ -92,19 +157,28 @@ export declare class Call {
private _state;
private _outgoingAudioEnabled;
private _outgoingVideoEnabled;
private _outgoingVideoIsScreenShare;
private _remoteVideoEnabled;
outgoingAudioLevel: NormalizedAudioLevel;
remoteAudioLevel: NormalizedAudioLevel;
remoteSharingScreen: boolean;
networkRoute: NetworkRoute;
private _videoCapturer;
private _videoRenderer;
endedReason?: CallEndedReason;
handleStateChanged?: () => void;
handleRemoteVideoEnabled?: () => void;
renderVideoFrame?: (width: number, height: number, buffer: ArrayBuffer) => void;
handleRemoteSharingScreen?: () => void;
handleNetworkRouteChanged?: () => void;
handleAudioLevels?: () => void;
renderVideoFrame?: (width: number, height: number, buffer: Buffer) => void;
constructor(callManager: CallManager, remoteUserId: UserId, callId: CallId, isIncoming: boolean, isVideoCall: boolean, settings: CallSettings | null, state: CallState);
get remoteUserId(): UserId;
get isIncoming(): boolean;
get isVideoCall(): boolean;
get state(): CallState;
set state(state: CallState);
setCallEnded(): void;
set videoCapturer(capturer: VideoCapturer | null);
set videoRenderer(renderer: VideoRenderer | null);
accept(): void;
@ -115,13 +189,14 @@ export declare class Call {
set outgoingAudioEnabled(enabled: boolean);
get outgoingVideoEnabled(): boolean;
set outgoingVideoEnabled(enabled: boolean);
set outgoingVideoIsScreenShare(isScreenShare: boolean);
get remoteVideoEnabled(): boolean;
set remoteVideoEnabled(enabled: boolean);
sendVideoFrame(width: number, height: number, rgbaBuffer: ArrayBuffer): void;
receiveVideoFrame(buffer: ArrayBuffer): [number, number] | undefined;
sendVideoFrame(width: number, height: number, format: VideoPixelFormatEnum, buffer: Buffer): void;
receiveVideoFrame(buffer: Buffer): [number, number] | undefined;
private enableOrDisableCapturer;
private setOutgoingVideoEnabled;
setLowBandwidthMode(enabled: boolean): void;
updateBandwidthMode(bandwidthMode: BandwidthMode): void;
private enableOrDisableRenderer;
}
export declare type GroupCallClientId = number;
@ -136,54 +211,75 @@ export declare enum JoinState {
Joining = 1,
Joined = 2
}
export declare enum BandwidthMode {
Low = 0,
Normal = 1
}
export declare enum GroupCallEndReason {
DeviceExplicitlyDisconnected = 0,
ServerExplicitlyDisconnected = 1,
SfuClientFailedToJoin = 2,
FailedToCreatePeerConnectionFactory = 3,
FailedToGenerateCertificate = 4,
FailedToCreateOutgoingAudioTrack = 5,
CallManagerIsBusy = 2,
SfuClientFailedToJoin = 3,
FailedToCreatePeerConnectionFactory = 4,
FailedToNegotiateSrtpKeys = 5,
FailedToCreatePeerConnection = 6,
FailedToCreateDataChannel = 7,
FailedToStartPeerConnection = 8,
FailedToUpdatePeerConnection = 9,
FailedToSetMaxSendBitrate = 10,
IceFailedWhileConnecting = 11,
IceFailedAfterConnected = 12,
ServerChangedDemuxId = 13
FailedToStartPeerConnection = 7,
FailedToUpdatePeerConnection = 8,
FailedToSetMaxSendBitrate = 9,
IceFailedWhileConnecting = 10,
IceFailedAfterConnected = 11,
ServerChangedDemuxId = 12,
HasMaxDevices = 13
}
export declare enum CallMessageUrgency {
Droppable = 0,
HandleImmediately = 1
}
export declare enum RingUpdate {
Requested = 0,
ExpiredRequest = 1,
AcceptedOnAnotherDevice = 2,
DeclinedOnAnotherDevice = 3,
BusyLocally = 4,
BusyOnAnotherDevice = 5,
CancelledByRinger = 6
}
export declare enum HttpMethod {
Get = 0,
Put = 1,
Post = 2
Post = 2,
Delete = 3
}
export declare class LocalDeviceState {
connectionState: ConnectionState;
joinState: JoinState;
demuxId?: number;
audioMuted: boolean;
videoMuted: boolean;
audioLevel: NormalizedAudioLevel;
presenting: boolean;
sharingScreen: boolean;
networkRoute: NetworkRoute;
constructor();
}
export declare class RemoteDeviceState {
demuxId: number;
userId: ArrayBuffer;
userId: Buffer;
mediaKeysReceived: boolean;
audioMuted: boolean | undefined;
videoMuted: boolean | undefined;
speakerIndex: number | undefined;
audioLevel: NormalizedAudioLevel;
presenting: boolean | undefined;
sharingScreen: boolean | undefined;
videoAspectRatio: number | undefined;
audioLevel: number | undefined;
constructor(demuxId: number, userId: ArrayBuffer);
addedTime: string | undefined;
speakerTime: string | undefined;
forwardingVideo: boolean | undefined;
isHigherResolutionPending: boolean;
constructor(demuxId: number, userId: Buffer, mediaKeysReceived: boolean);
}
export declare class GroupMemberInfo {
userId: ArrayBuffer;
userIdCipherText: ArrayBuffer;
constructor(userId: ArrayBuffer, userIdCipherText: ArrayBuffer);
userId: Buffer;
userIdCipherText: Buffer;
constructor(userId: Buffer, userIdCipherText: Buffer);
}
export declare class RenderedResolution {
export declare class VideoRequest {
demuxId: number;
width: number;
height: number;
@ -195,7 +291,8 @@ export interface GroupCallObserver {
requestGroupMembers(groupCall: GroupCall): void;
onLocalDeviceStateChanged(groupCall: GroupCall): void;
onRemoteDeviceStatesChanged(groupCall: GroupCall): void;
onJoinedMembersChanged(groupCall: GroupCall): void;
onAudioLevels(groupCall: GroupCall): void;
onPeekChanged(groupCall: GroupCall): void;
onEnded(groupCall: GroupCall, reason: GroupCallEndReason): void;
}
export declare class GroupCall {
@ -205,39 +302,46 @@ export declare class GroupCall {
get clientId(): GroupCallClientId;
private _localDeviceState;
private _remoteDeviceStates;
private _joinedGroupMembers;
constructor(callManager: CallManager, groupId: ArrayBuffer, observer: GroupCallObserver);
private _peekInfo;
constructor(callManager: CallManager, groupId: Buffer, sfuUrl: string, hkdfExtraInfo: Buffer, audioLevelsIntervalMillis: number | undefined, observer: GroupCallObserver);
connect(): void;
join(): void;
leave(): void;
disconnect(): void;
getLocalDeviceState(): LocalDeviceState;
getRemoteDeviceStates(): Array<RemoteDeviceState> | undefined;
getJoinedGroupMembers(): Array<ArrayBuffer> | undefined;
getPeekInfo(): PeekInfo | undefined;
setOutgoingAudioMuted(muted: boolean): void;
setOutgoingVideoMuted(muted: boolean): void;
setPresenting(presenting: boolean): void;
setOutgoingVideoIsScreenShare(isScreenShare: boolean): void;
ringAll(): void;
resendMediaKeys(): void;
setBandwidthMode(bandwidthMode: BandwidthMode): void;
setRenderedResolutions(resolutions: Array<RenderedResolution>): void;
requestVideo(resolutions: Array<VideoRequest>, activeSpeakerHeight: number): void;
setGroupMembers(members: Array<GroupMemberInfo>): void;
setMembershipProof(proof: ArrayBuffer): void;
setMembershipProof(proof: Buffer): void;
requestMembershipProof(): void;
requestGroupMembers(): void;
handleConnectionStateChanged(connectionState: ConnectionState): void;
handleJoinStateChanged(joinState: JoinState): void;
handleJoinStateChanged(joinState: JoinState, demuxId: number | undefined): void;
handleNetworkRouteChanged(localNetworkAdapterType: NetworkAdapterType): void;
handleAudioLevels(capturedLevel: RawAudioLevel, receivedLevels: Array<ReceivedAudioLevel>): void;
handleRemoteDevicesChanged(remoteDeviceStates: Array<RemoteDeviceState>): void;
handleJoinedMembersChanged(members: Array<ArrayBuffer>): void;
handlePeekChanged(info: PeekInfo): void;
handleEnded(reason: GroupCallEndReason): void;
sendVideoFrame(width: number, height: number, rgbaBuffer: ArrayBuffer): void;
sendVideoFrame(width: number, height: number, format: VideoPixelFormatEnum, buffer: Buffer): void;
getVideoSource(remoteDemuxId: number): GroupCallVideoFrameSource;
setRemoteAspectRatio(remoteDemuxId: number, aspectRatio: number): void;
}
declare class GroupCallVideoFrameSource {
private readonly _callManager;
private readonly _clientId;
private readonly _groupCall;
private readonly _remoteDemuxId;
constructor(callManager: CallManager, clientId: GroupCallClientId, remoteDemuxId: number);
receiveVideoFrame(buffer: ArrayBuffer): [number, number] | undefined;
constructor(callManager: CallManager, groupCall: GroupCall, remoteDemuxId: number);
receiveVideoFrame(buffer: Buffer): [number, number] | undefined;
}
declare type ProtobufArrayBuffer = ArrayBuffer | {
declare type ProtobufBuffer = Buffer | {
toArrayBuffer: () => ArrayBuffer;
};
export declare type UserId = string;
@ -257,7 +361,7 @@ export declare class CallingMessage {
export declare class OfferMessage {
callId?: CallId;
type?: OfferType;
opaque?: ProtobufArrayBuffer;
opaque?: ProtobufBuffer;
sdp?: string;
}
export declare enum OfferType {
@ -266,14 +370,14 @@ export declare enum OfferType {
}
export declare class AnswerMessage {
callId?: CallId;
opaque?: ProtobufArrayBuffer;
opaque?: ProtobufBuffer;
sdp?: string;
}
export declare class IceCandidateMessage {
callId?: CallId;
mid?: string;
line?: number;
opaque?: ProtobufArrayBuffer;
opaque?: ProtobufBuffer;
sdp?: string;
}
export declare class BusyMessage {
@ -285,7 +389,7 @@ export declare class HangupMessage {
deviceId?: DeviceId;
}
export declare class OpaqueMessage {
data?: ProtobufArrayBuffer;
data?: ProtobufBuffer;
}
export declare enum HangupType {
Normal = 0,
@ -294,28 +398,41 @@ export declare enum HangupType {
Busy = 3,
NeedPermission = 4
}
export declare enum BandwidthMode {
VeryLow = 0,
Low = 1,
Normal = 2
}
export declare enum RingCancelReason {
DeclinedByUser = 0,
Busy = 1
}
export interface CallManager {
setConfig(config: Config): void;
setSelfUuid(uuid: Buffer): void;
createOutgoingCall(remoteUserId: UserId, isVideoCall: boolean, localDeviceId: DeviceId): CallId;
proceed(callId: CallId, iceServerUsername: string, iceServerPassword: string, iceServerUrls: Array<string>, hideIp: boolean): void;
proceed(callId: CallId, iceServerUsername: string, iceServerPassword: string, iceServerUrls: Array<string>, hideIp: boolean, bandwidthMode: BandwidthMode, audioLevelsIntervalMillis: number): void;
accept(callId: CallId): void;
ignore(callId: CallId): void;
hangup(): void;
cancelGroupRing(groupId: GroupId, ringId: string, reason: RingCancelReason | null): void;
signalingMessageSent(callId: CallId): void;
signalingMessageSendFailed(callId: CallId): void;
setOutgoingAudioEnabled(enabled: boolean): void;
setOutgoingVideoEnabled(enabled: boolean): void;
setLowBandwidthMode(enabled: boolean): void;
sendVideoFrame(width: number, height: number, buffer: ArrayBuffer): void;
receiveVideoFrame(buffer: ArrayBuffer): [number, number] | undefined;
receivedOffer(remoteUserId: UserId, remoteDeviceId: DeviceId, messageAgeSec: number, callId: CallId, offerType: OfferType, localDeviceId: DeviceId, remoteSupportsMultiRing: boolean, opaque: ArrayBuffer | undefined, sdp: string | undefined, senderIdentityKey: ArrayBuffer, receiverIdentityKey: ArrayBuffer): void;
receivedAnswer(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, remoteSupportsMultiRing: boolean, opaque: ArrayBuffer | undefined, sdp: string | undefined, senderIdentityKey: ArrayBuffer, receiverIdentityKey: ArrayBuffer): void;
receivedIceCandidates(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, candidates: Array<IceCandidateMessage>): void;
setOutgoingVideoIsScreenShare(enabled: boolean): void;
updateBandwidthMode(bandwidthMode: BandwidthMode): void;
sendVideoFrame(width: number, height: number, format: VideoPixelFormatEnum, buffer: Buffer): void;
receiveVideoFrame(buffer: Buffer): [number, number] | undefined;
receivedOffer(remoteUserId: UserId, remoteDeviceId: DeviceId, messageAgeSec: number, callId: CallId, offerType: OfferType, localDeviceId: DeviceId, opaque: Buffer, senderIdentityKey: Buffer, receiverIdentityKey: Buffer): void;
receivedAnswer(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, opaque: Buffer, senderIdentityKey: Buffer, receiverIdentityKey: Buffer): void;
receivedIceCandidates(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, candidates: Array<Buffer>): void;
receivedHangup(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, hangupType: HangupType, hangupDeviceId: DeviceId | null): void;
receivedBusy(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId): void;
receivedCallMessage(remoteUserId: ArrayBuffer, remoteDeviceId: DeviceId, localDeviceId: DeviceId, data: ArrayBuffer, messageAgeSec: number): void;
receivedHttpResponse(requestId: number, status: number, body: ArrayBuffer): void;
receivedCallMessage(remoteUserId: Buffer, remoteDeviceId: DeviceId, localDeviceId: DeviceId, data: Buffer, messageAgeSec: number): void;
receivedHttpResponse(requestId: number, status: number, body: Buffer): void;
httpRequestFailed(requestId: number, debugInfo: string | undefined): void;
createGroupCallClient(groupId: ArrayBuffer): GroupCallClientId;
createGroupCallClient(groupId: Buffer, sfuUrl: string, hkdfExtraInfo: Buffer, audioLevelsIntervalMillis: number): GroupCallClientId;
deleteGroupCallClient(clientId: GroupCallClientId): void;
connect(clientId: GroupCallClientId): void;
join(clientId: GroupCallClientId): void;
@ -323,44 +440,50 @@ export interface CallManager {
disconnect(clientId: GroupCallClientId): void;
setOutgoingAudioMuted(clientId: GroupCallClientId, muted: boolean): void;
setOutgoingVideoMuted(clientId: GroupCallClientId, muted: boolean): void;
setPresenting(clientId: GroupCallClientId, presenting: boolean): void;
setOutgoingGroupCallVideoIsScreenShare(clientId: GroupCallClientId, isScreenShare: boolean): void;
groupRing(clientId: GroupCallClientId, recipient: Buffer | undefined): void;
resendMediaKeys(clientId: GroupCallClientId): void;
setBandwidthMode(clientId: GroupCallClientId, bandwidthMode: BandwidthMode): void;
setRenderedResolutions(clientId: GroupCallClientId, resolutions: Array<RenderedResolution>): void;
requestVideo(clientId: GroupCallClientId, resolutions: Array<VideoRequest>, activeSpeakerHeight: number): void;
setGroupMembers(clientId: GroupCallClientId, members: Array<GroupMemberInfo>): void;
setMembershipProof(clientId: GroupCallClientId, proof: ArrayBuffer): void;
receiveGroupCallVideoFrame(clientId: GroupCallClientId, remoteDemuxId: number, buffer: ArrayBuffer): [number, number] | undefined;
setMembershipProof(clientId: GroupCallClientId, proof: Buffer): void;
receiveGroupCallVideoFrame(clientId: GroupCallClientId, remoteDemuxId: number, buffer: Buffer): [number, number] | undefined;
peekGroupCall(requestId: number, sfu_url: string, membership_proof: Buffer, group_members: Array<GroupMemberInfo>): Promise<PeekInfo>;
getAudioInputs(): AudioDevice[];
setAudioInput(index: number): void;
getAudioOutputs(): AudioDevice[];
setAudioOutput(index: number): void;
poll(callbacks: CallManagerCallbacks): void;
}
export interface CallManagerCallbacks {
onStartOutgoingCall(remoteUserId: UserId, callId: CallId): void;
onStartIncomingCall(remoteUserId: UserId, callId: CallId, isVideoCall: boolean): void;
onCallState(remoteUserId: UserId, state: CallState): void;
onCallEnded(remoteUserId: UserId, endedReason: CallEndedReason): void;
onCallEnded(remoteUserId: UserId, callId: CallId, endedReason: CallEndedReason, ageSec: number): void;
onRemoteVideoEnabled(remoteUserId: UserId, enabled: boolean): void;
onSendOffer(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, mediaType: number, opaque?: ArrayBuffer, sdp?: string): void;
onSendAnswer(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, opaque?: ArrayBuffer, sdp?: string): void;
onSendIceCandidates(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, candidates: Array<IceCandidateMessage>): void;
onSendLegacyHangup(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, HangupType: HangupType, hangupDeviceId: DeviceId | null): void;
onRemoteSharingScreen(remoteUserId: UserId, enabled: boolean): void;
onSendOffer(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, mediaType: number, opaque: Buffer): void;
onSendAnswer(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, opaque: Buffer): void;
onSendIceCandidates(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, candidates: Array<Buffer>): void;
onSendHangup(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean, HangupType: HangupType, hangupDeviceId: DeviceId | null): void;
onSendBusy(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, broadcast: boolean): void;
sendCallMessage(recipientUuid: ArrayBuffer, message: ArrayBuffer): void;
sendCallMessage(recipientUuid: Buffer, message: Buffer, urgency: CallMessageUrgency): void;
sendCallMessageToGroup(groupId: Buffer, message: Buffer, urgency: CallMessageUrgency): void;
sendHttpRequest(requestId: number, url: string, method: HttpMethod, headers: {
[name: string]: string;
}, body: ArrayBuffer | undefined): void;
}, body: Buffer | undefined): void;
requestMembershipProof(clientId: GroupCallClientId): void;
requestGroupMembers(clientId: GroupCallClientId): void;
handleConnectionStateChanged(clientId: GroupCallClientId, connectionState: ConnectionState): void;
handleJoinStateChanged(clientId: GroupCallClientId, joinState: JoinState): void;
handleJoinStateChanged(clientId: GroupCallClientId, joinState: JoinState, demuxId: number | undefined): void;
handleRemoteDevicesChanged(clientId: GroupCallClientId, remoteDeviceStates: Array<RemoteDeviceState>): void;
handleJoinedMembersChanged(clientId: GroupCallClientId, members: Array<ArrayBuffer>): void;
handlePeekChanged(clientId: GroupCallClientId, info: PeekInfo): void;
handlePeekResponse(request_id: number, info: PeekInfo): void;
handleEnded(clientId: GroupCallClientId, reason: GroupCallEndReason): void;
onLogMessage(level: number, fileName: string, line: number, message: string): void;
}
export declare enum CallState {
Prering = "init",
Prering = "idle",
Ringing = "ringing",
Accepted = "connected",
Reconnecting = "connecting",
@ -373,17 +496,18 @@ export declare enum CallEndedReason {
Declined = "Declined",
Busy = "Busy",
Glare = "Glare",
ReCall = "ReCall",
ReceivedOfferExpired = "ReceivedOfferExpired",
ReceivedOfferWhileActive = "ReceivedOfferWhileActive",
ReceivedOfferWithGlare = "ReceivedOfferWithGlare",
SignalingFailure = "SignalingFailure",
GlareFailure = "GlareFailure",
ConnectionFailure = "ConnectionFailure",
InternalFailure = "InternalFailure",
Timeout = "Timeout",
AcceptedOnAnotherDevice = "AcceptedOnAnotherDevice",
DeclinedOnAnotherDevice = "DeclinedOnAnotherDevice",
BusyOnAnotherDevice = "BusyOnAnotherDevice",
CallerIsNotMultiring = "CallerIsNotMultiring"
BusyOnAnotherDevice = "BusyOnAnotherDevice"
}
export declare enum CallLogLevel {
Off = 0,

File diff suppressed because it is too large Load Diff

View File

@ -1,44 +1,58 @@
/// <reference types="node" />
interface Ref<T> {
readonly current: T | null;
}
export declare enum VideoPixelFormatEnum {
I420 = 0,
Nv12 = 1,
Rgba = 2
}
export interface VideoFrameSource {
receiveVideoFrame(buffer: ArrayBuffer): [number, number] | undefined;
receiveVideoFrame(buffer: Buffer): [number, number] | undefined;
}
interface VideoFrameSender {
sendVideoFrame(width: number, height: number, rgbaBuffer: ArrayBuffer): void;
sendVideoFrame(width: number, height: number, format: VideoPixelFormatEnum, buffer: Buffer): void;
}
export declare class GumVideoCaptureOptions {
maxWidth: number;
maxHeight: number;
maxFramerate: number;
preferredDeviceId?: string;
screenShareSourceId?: string;
}
export declare class GumVideoCapturer {
private readonly maxWidth;
private readonly maxHeight;
private readonly maxFramerate;
private defaultCaptureOptions;
private localPreview?;
private capturing;
private captureOptions?;
private sender?;
private mediaStream?;
private canvas?;
private canvasContext?;
private intervalId?;
private spawnedSenderRunning;
private preferredDeviceId?;
private capturingStartTime;
fakeVideoName: string | undefined;
constructor(maxWidth: number, maxHeight: number, maxFramerate: number);
private updateLocalPreviewIntervalId?;
constructor(defaultCaptureOptions: GumVideoCaptureOptions);
capturing(): boolean;
setLocalPreview(localPreview: Ref<HTMLVideoElement> | undefined): void;
enableCapture(): void;
enableCaptureAndSend(sender: VideoFrameSender): void;
enableCaptureAndSend(sender: VideoFrameSender, options?: GumVideoCaptureOptions): void;
disable(): void;
setPreferredDevice(deviceId: string): Promise<void>;
enumerateDevices(): Promise<MediaDeviceInfo[]>;
private getUserMedia;
private startCapturing;
private stopCapturing;
private startSending;
private spawnSender;
private stopSending;
private setLocalPreviewSourceObject;
private captureAndSendOneVideoFrame;
private drawFakeVideo;
private updateLocalPreviewSourceObject;
}
export declare const MAX_VIDEO_CAPTURE_WIDTH: number;
export declare const MAX_VIDEO_CAPTURE_HEIGHT: number;
export declare const MAX_VIDEO_CAPTURE_AREA: number;
export declare const MAX_VIDEO_CAPTURE_BUFFER_SIZE: number;
export declare class CanvasVideoRenderer {
private canvas?;
private buffer;
private imageData?;
private source?;
private rafId?;
constructor();

View File

@ -1,9 +1,7 @@
"use strict";
//
// Copyright (C) 2020 Signal Messenger, LLC.
// All rights reserved.
//
// SPDX-License-Identifier: GPL-3.0-only
// Copyright 2019-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@ -15,93 +13,195 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CanvasVideoRenderer = exports.MAX_VIDEO_CAPTURE_BUFFER_SIZE = exports.MAX_VIDEO_CAPTURE_AREA = exports.MAX_VIDEO_CAPTURE_HEIGHT = exports.MAX_VIDEO_CAPTURE_WIDTH = exports.GumVideoCapturer = exports.GumVideoCaptureOptions = exports.VideoPixelFormatEnum = void 0;
const index_1 = require("../index");
// Given a weird name to not conflict with WebCodec's VideoPixelFormat
var VideoPixelFormatEnum;
(function (VideoPixelFormatEnum) {
VideoPixelFormatEnum[VideoPixelFormatEnum["I420"] = 0] = "I420";
VideoPixelFormatEnum[VideoPixelFormatEnum["Nv12"] = 1] = "Nv12";
VideoPixelFormatEnum[VideoPixelFormatEnum["Rgba"] = 2] = "Rgba";
})(VideoPixelFormatEnum = exports.VideoPixelFormatEnum || (exports.VideoPixelFormatEnum = {}));
function videoPixelFormatFromEnum(format) {
switch (format) {
case VideoPixelFormatEnum.I420: {
return 'I420';
}
case VideoPixelFormatEnum.Nv12: {
return 'NV12';
}
case VideoPixelFormatEnum.Rgba: {
return 'RGBA';
}
}
}
function videoPixelFormatToEnum(format) {
switch (format) {
case 'I420': {
return VideoPixelFormatEnum.I420;
}
case 'NV12': {
return VideoPixelFormatEnum.Nv12;
}
case 'RGBA': {
return VideoPixelFormatEnum.Rgba;
}
}
}
class GumVideoCaptureOptions {
constructor() {
this.maxWidth = 640;
this.maxHeight = 480;
this.maxFramerate = 30;
}
}
exports.GumVideoCaptureOptions = GumVideoCaptureOptions;
class GumVideoCapturer {
constructor(maxWidth, maxHeight, maxFramerate) {
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
this.maxFramerate = maxFramerate;
this.capturing = false;
constructor(defaultCaptureOptions) {
this.spawnedSenderRunning = false;
this.defaultCaptureOptions = defaultCaptureOptions;
}
capturing() {
return this.captureOptions != undefined;
}
setLocalPreview(localPreview) {
var _a;
const oldLocalPreview = (_a = this.localPreview) === null || _a === void 0 ? void 0 : _a.current;
if (oldLocalPreview) {
oldLocalPreview.srcObject = null;
}
this.localPreview = localPreview;
this.updateLocalPreviewSourceObject();
// This is a dumb hack around the fact that sometimes the
// this.localPreview.current is updated without a call
// to setLocalPreview, in which case the local preview
// won't be rendered.
if (this.updateLocalPreviewIntervalId != undefined) {
clearInterval(this.updateLocalPreviewIntervalId);
}
this.updateLocalPreviewIntervalId = setInterval(this.updateLocalPreviewSourceObject.bind(this), 1000);
}
enableCapture() {
// tslint:disable no-floating-promises
this.startCapturing();
this.startCapturing(this.defaultCaptureOptions);
}
enableCaptureAndSend(sender) {
enableCaptureAndSend(sender, options) {
// tslint:disable no-floating-promises
this.startCapturing();
this.startCapturing(options !== null && options !== void 0 ? options : this.defaultCaptureOptions);
this.startSending(sender);
}
disable() {
this.stopCapturing();
this.stopSending();
if (this.updateLocalPreviewIntervalId != undefined) {
clearInterval(this.updateLocalPreviewIntervalId);
}
this.updateLocalPreviewIntervalId = undefined;
}
setPreferredDevice(deviceId) {
return __awaiter(this, void 0, void 0, function* () {
this.preferredDeviceId = deviceId;
if (this.capturing) {
// Restart capturing to start using the new device
yield this.stopCapturing();
yield this.startCapturing();
if (this.captureOptions) {
const captureOptions = this.captureOptions;
const sender = this.sender;
this.disable();
this.startCapturing(captureOptions);
if (sender) {
this.startSending(sender);
}
}
});
}
enumerateDevices() {
return __awaiter(this, void 0, void 0, function* () {
const devices = yield window.navigator.mediaDevices.enumerateDevices();
const cameras = devices.filter(d => d.kind == "videoinput");
const cameras = devices.filter(d => d.kind == 'videoinput');
return cameras;
});
}
startCapturing() {
getUserMedia(options) {
var _a;
// TODO: Figure out a better way to make typescript accept "mandatory".
let constraints = {
audio: false,
video: {
deviceId: (_a = options.preferredDeviceId) !== null && _a !== void 0 ? _a : this.preferredDeviceId,
width: {
max: options.maxWidth,
},
height: {
max: options.maxHeight,
},
frameRate: {
max: options.maxFramerate,
},
},
};
if (options.screenShareSourceId != undefined) {
constraints.video = {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: options.screenShareSourceId,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
maxFrameRate: options.maxFramerate,
},
};
}
return window.navigator.mediaDevices.getUserMedia(constraints);
}
startCapturing(options) {
return __awaiter(this, void 0, void 0, function* () {
if (this.capturing) {
if (this.capturing()) {
index_1.RingRTC.logWarn('startCapturing(): already capturing');
return;
}
this.capturing = true;
this.capturingStartTime = Date.now();
index_1.RingRTC.logInfo(`startCapturing(): ${options.maxWidth}x${options.maxHeight}@${options.maxFramerate}`);
this.captureOptions = options;
try {
const mediaStream = yield window.navigator.mediaDevices.getUserMedia({
audio: false,
video: {
deviceId: this.preferredDeviceId,
width: {
max: this.maxWidth,
},
height: {
max: this.maxHeight,
},
frameRate: {
max: this.maxFramerate,
},
},
});
// We could have been disabled between when we requested the stream
// and when we got it.
if (!this.capturing) {
// If we start/stop/start, we may have concurrent calls to getUserMedia,
// which is what we want if we're switching from camera to screenshare.
// But we need to make sure we deal with the fact that things might be
// different after the await here.
const mediaStream = yield this.getUserMedia(options);
// It's possible video was disabled, switched to screenshare, or
// switched to a different camera while awaiting a response, in
// which case we need to disable the camera we just accessed.
if (this.captureOptions != options) {
index_1.RingRTC.logWarn('startCapturing(): different state after getUserMedia()');
for (const track of mediaStream.getVideoTracks()) {
// Make the light turn off faster
track.stop();
}
return;
}
if (this.localPreview && !!this.localPreview.current && !!mediaStream) {
this.setLocalPreviewSourceObject(mediaStream);
}
this.mediaStream = mediaStream;
if (!this.spawnedSenderRunning &&
this.mediaStream != undefined &&
this.sender != undefined) {
this.spawnSender(this.mediaStream, this.sender);
}
this.updateLocalPreviewSourceObject();
}
catch (_a) {
// We couldn't open the camera. Oh well.
catch (e) {
index_1.RingRTC.logError(`startCapturing(): ${e}`);
// It's possible video was disabled, switched to screenshare, or
// switched to a different camera while awaiting a response, in
// which case we should reset the captureOptions if we set them.
if (this.captureOptions == options) {
// We couldn't open the camera. Oh well.
this.captureOptions = undefined;
}
}
});
}
stopCapturing() {
if (!this.capturing) {
if (!this.capturing()) {
index_1.RingRTC.logWarn('stopCapturing(): not capturing');
return;
}
this.capturing = false;
index_1.RingRTC.logInfo('stopCapturing()');
this.captureOptions = undefined;
if (!!this.mediaStream) {
for (const track of this.mediaStream.getVideoTracks()) {
// Make the light turn off faster
@ -109,34 +209,75 @@ class GumVideoCapturer {
}
this.mediaStream = undefined;
}
if (this.localPreview && !!this.localPreview.current) {
this.localPreview.current.srcObject = null;
}
this.updateLocalPreviewSourceObject();
}
startSending(sender) {
if (this.sender === sender) {
return;
}
if (!this.sender) {
if (!!this.sender) {
// If we're replacing an existing sender, make sure we stop the
// current setInterval loop before starting another one.
this.stopSending();
}
this.sender = sender;
this.canvas = new OffscreenCanvas(this.maxWidth, this.maxHeight);
this.canvasContext = this.canvas.getContext('2d') || undefined;
const interval = 1000 / this.maxFramerate;
this.intervalId = setInterval(this.captureAndSendOneVideoFrame.bind(this), interval);
}
stopSending() {
this.sender = undefined;
this.canvas = undefined;
this.canvasContext = undefined;
if (!!this.intervalId) {
clearInterval(this.intervalId);
if (!this.spawnedSenderRunning && this.mediaStream != undefined) {
this.spawnSender(this.mediaStream, this.sender);
}
}
setLocalPreviewSourceObject(mediaStream) {
spawnSender(mediaStream, sender) {
const track = mediaStream.getVideoTracks()[0];
if (track == undefined || this.spawnedSenderRunning) {
return;
}
const reader = new MediaStreamTrackProcessor({
track,
}).readable.getReader();
const buffer = Buffer.alloc(exports.MAX_VIDEO_CAPTURE_BUFFER_SIZE);
this.spawnedSenderRunning = true;
(() => __awaiter(this, void 0, void 0, function* () {
var _a;
try {
while (sender === this.sender && mediaStream == this.mediaStream) {
const { done, value: frame } = yield reader.read();
if (done) {
break;
}
if (!frame) {
continue;
}
try {
const format = videoPixelFormatToEnum((_a = frame.format) !== null && _a !== void 0 ? _a : 'I420');
if (format == undefined) {
index_1.RingRTC.logWarn(`Unsupported video frame format: ${frame.format}`);
break;
}
frame.copyTo(buffer);
sender.sendVideoFrame(frame.codedWidth, frame.codedHeight, format, buffer);
}
catch (e) {
index_1.RingRTC.logError(`sendVideoFrame(): ${e}`);
}
finally {
// This must be called for more frames to come.
frame.close();
}
}
}
catch (e) {
index_1.RingRTC.logError(`spawnSender(): ${e}`);
}
finally {
reader.releaseLock();
}
this.spawnedSenderRunning = false;
}))();
}
stopSending() {
// The spawned sender should stop
this.sender = undefined;
}
updateLocalPreviewSourceObject() {
if (!this.localPreview) {
return;
}
@ -144,95 +285,34 @@ class GumVideoCapturer {
if (!localPreview) {
return;
}
localPreview.srcObject = mediaStream;
// I don't know why this is necessary
if (localPreview.width === 0) {
localPreview.width = this.maxWidth;
}
if (localPreview.height === 0) {
localPreview.height = this.maxHeight;
}
}
captureAndSendOneVideoFrame() {
if (!this.canvas || !this.canvasContext || !this.sender) {
const { mediaStream = null } = this;
if (localPreview.srcObject === mediaStream) {
return;
}
if ((this.fakeVideoName != undefined) && (this.capturingStartTime != undefined)) {
let width = 640;
let height = 480;
let duration = Date.now() - this.capturingStartTime;
this.drawFakeVideo(this.canvasContext, width, height, this.fakeVideoName, duration);
const image = this.canvasContext.getImageData(0, 0, width, height);
this.sender.sendVideoFrame(image.width, image.height, image.data.buffer);
return;
}
if (this.localPreview && this.localPreview.current) {
if (!this.localPreview.current.srcObject && !!this.mediaStream) {
this.setLocalPreviewSourceObject(this.mediaStream);
if (mediaStream) {
localPreview.srcObject = mediaStream;
if (localPreview.width === 0) {
localPreview.width = this.captureOptions.maxWidth;
}
const width = this.localPreview.current.videoWidth;
const height = this.localPreview.current.videoHeight;
if (width === 0 || height === 0) {
return;
if (localPreview.height === 0) {
localPreview.height = this.captureOptions.maxHeight;
}
this.canvasContext.drawImage(this.localPreview.current, 0, 0, width, height);
const image = this.canvasContext.getImageData(0, 0, width, height);
this.sender.sendVideoFrame(image.width, image.height, image.data.buffer);
}
}
drawFakeVideo(context, width, height, name, time) {
function fill(style, draw) {
context.fillStyle = style;
context.beginPath();
draw();
context.fill();
else {
localPreview.srcObject = null;
}
function stroke(style, draw) {
context.strokeStyle = style;
context.beginPath();
draw();
context.stroke();
}
function arc(x, y, radius, start, end) {
const twoPi = 2 * Math.PI;
context.arc(x, y, radius, start * twoPi, end * twoPi);
}
function circle(x, y, radius) {
arc(x, y, radius, 0, 1);
}
function fillFace(x, y, faceRadius) {
const eyeRadius = faceRadius / 5;
const eyeOffsetX = faceRadius / 2;
const eyeOffsetY = -faceRadius / 4;
const smileRadius = faceRadius / 2;
const smileOffsetY = -eyeOffsetY;
fill("yellow", () => circle(x, y, faceRadius));
fill("black", () => circle(x - eyeOffsetX, y + eyeOffsetY, eyeRadius));
fill("black", () => circle(x + eyeOffsetX, y + eyeOffsetY, eyeRadius));
stroke("black", () => arc(x, y + smileOffsetY, smileRadius, 0, 0.5));
}
function fillText(x, y, fillStyle, fontSize, fontName, align, text) {
context.font = `${fontSize}px ${fontName}`;
context.textAlign = align;
context.fillStyle = fillStyle;
context.fillText(text, x, y);
}
function fillLabeledFace(x, y, faceRadius, label) {
const labelSize = faceRadius * .3;
const labelOffsetY = faceRadius * 1.5;
fillFace(x, y, faceRadius);
fillText(x, y + labelOffsetY, "black", labelSize, "monospace", "center", label);
}
context.fillStyle = 'white';
context.fillRect(0, 0, width, height);
fillLabeledFace(width / 2, height / 2, height / 3, `${name} ${time}`);
}
}
exports.GumVideoCapturer = GumVideoCapturer;
// We add 10% in each dimension to allow for things that are slightly wider or taller than 1080p.
const MAX_VIDEO_CAPTURE_MULTIPLIER = 1.0;
exports.MAX_VIDEO_CAPTURE_WIDTH = 1920 * MAX_VIDEO_CAPTURE_MULTIPLIER;
exports.MAX_VIDEO_CAPTURE_HEIGHT = 1080 * MAX_VIDEO_CAPTURE_MULTIPLIER;
exports.MAX_VIDEO_CAPTURE_AREA = exports.MAX_VIDEO_CAPTURE_WIDTH * exports.MAX_VIDEO_CAPTURE_HEIGHT;
exports.MAX_VIDEO_CAPTURE_BUFFER_SIZE = exports.MAX_VIDEO_CAPTURE_AREA * 4;
class CanvasVideoRenderer {
constructor() {
// The max size video frame we'll support (in RGBA)
this.buffer = new ArrayBuffer(1920 * 1080 * 4);
this.buffer = Buffer.alloc(exports.MAX_VIDEO_CAPTURE_BUFFER_SIZE);
}
setCanvas(canvas) {
this.canvas = canvas;
@ -244,8 +324,9 @@ class CanvasVideoRenderer {
if (!!this.source) {
// If we're replacing an existing source, make sure we stop the
// current rAF loop before starting another one.
// And blanking the video is nice as well.
this.disable();
if (this.rafId) {
window.cancelAnimationFrame(this.rafId);
}
}
this.source = source;
this.requestAnimationFrameCallback();
@ -277,6 +358,7 @@ class CanvasVideoRenderer {
context.fillRect(0, 0, canvas.width, canvas.height);
}
renderVideoFrame() {
var _a, _b;
if (!this.source || !this.canvas) {
return;
}
@ -293,8 +375,10 @@ class CanvasVideoRenderer {
return;
}
const [width, height] = frame;
if (canvas.clientWidth <= 0 || width <= 0 ||
canvas.clientHeight <= 0 || height <= 0) {
if (canvas.clientWidth <= 0 ||
width <= 0 ||
canvas.clientHeight <= 0 ||
height <= 0) {
return;
}
const frameAspectRatio = width / height;
@ -322,7 +406,11 @@ class CanvasVideoRenderer {
context.fillStyle = 'black';
context.fillRect(0, 0, canvas.width, canvas.height);
}
context.putImageData(new ImageData(new Uint8ClampedArray(this.buffer, 0, width * height * 4), width, height), dx, dy);
if (((_a = this.imageData) === null || _a === void 0 ? void 0 : _a.width) !== width || ((_b = this.imageData) === null || _b === void 0 ? void 0 : _b.height) !== height) {
this.imageData = new ImageData(width, height);
}
this.imageData.data.set(this.buffer.subarray(0, width * height * 4));
context.putImageData(this.imageData, dx, dy);
}
}
exports.CanvasVideoRenderer = CanvasVideoRenderer;

View File

@ -1,45 +1,51 @@
//
// Copyright (C) 2020 Signal Messenger, LLC.
// All rights reserved.
//
// SPDX-License-Identifier: GPL-3.0-only
// Copyright 2019-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
export {
AudioDevice,
BandwidthMode,
Call,
CallId,
CallEndedReason,
CallLogLevel,
CallState,
CallingMessage,
CallSettings,
ConnectionState,
DeviceId,
GroupCall,
GroupCallEndReason,
GroupCallObserver,
GroupMemberInfo,
HangupMessage,
HangupType,
HttpMethod,
JoinState,
LocalDeviceState,
OfferType,
OpaqueMessage,
RemoteDeviceState,
RenderedResolution,
RingRTCType,
UserId,
VideoCapturer,
VideoRenderer
AudioDevice,
BandwidthMode,
Call,
CallEndedReason,
CallId,
CallLogLevel,
CallMessageUrgency,
CallSettings,
CallState,
CallingMessage,
ConnectionState,
DeviceId,
GroupCall,
GroupCallEndReason,
GroupCallObserver,
GroupMemberInfo,
HangupMessage,
HangupType,
HttpMethod,
JoinState,
LocalDeviceState,
OfferType,
OpaqueMessage,
PeekInfo,
RemoteDeviceState,
RingCancelReason,
RingRTCType,
RingUpdate,
UserId,
VideoCapturer,
VideoRenderer,
VideoRequest,
} from './ringrtc/Service';
export {
CanvasVideoRenderer,
GumVideoCapturer,
VideoFrameSource,
CanvasVideoRenderer,
GumVideoCapturer,
VideoFrameSource,
MAX_VIDEO_CAPTURE_AREA,
MAX_VIDEO_CAPTURE_BUFFER_SIZE,
MAX_VIDEO_CAPTURE_HEIGHT,
MAX_VIDEO_CAPTURE_WIDTH,
} from './ringrtc/VideoSupport';
import { RingRTCType } from './ringrtc/Service';

View File

@ -1,45 +1,47 @@
{
"name": "ringrtc",
"version": "2.8.1",
"version": "2.22.0",
"description": "Signal Messenger voice and video calling library.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/index.d.ts"
"dist/ringrtc/*",
"build/*"
],
"scripts": {
"build": "tsc",
"clean": "rimraf dist",
"test": "electron-mocha --recursive dist/test",
"eslint": "eslint .",
"lint": "yarn eslint && yarn tslint",
"tslint": "tslint --format stylish --project .",
"eslint": "eslint --cache .",
"lint": "yarn format --list-different && yarn eslint",
"format": "prettier --write \"*.{css,js,json,md,scss,ts,tsx}\" \"./**/*.{css,js,json,md,scss,ts,tsx}\""
},
"author": "",
"license": "ISC",
"license": "AGPL-3.0-only",
"dependencies": {},
"devDependencies": {
"@types/chai": "4.2.7",
"@types/chai": "4.2.18",
"@types/chai-as-promised": "^7.1.3",
"@types/dom-mediacapture-transform": "0.1.2",
"@types/mocha": "5.2.7",
"@types/node": "13.1.8",
"@types/uuid": "^8.3.0",
"chai": "4.2.0",
"electron": "8.5.2",
"electron-mocha": "8.1.1",
"eslint": "4.18.2",
"eslint-config-airbnb-base": "12.1.0",
"eslint-config-prettier": "2.9.0",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-mocha": "4.12.1",
"eslint-plugin-more": "0.3.1",
"mocha": "7.1.1",
"prettier": "1.19.1",
"rimraf": "3.0.1",
"tslint": "5.13.0",
"tslint-microsoft-contrib": "6.2.0",
"tslint-react": "3.6.0",
"typescript": "3.7.4",
"uuid": "8.3.1"
"@types/node": "14.14.37",
"@types/offscreencanvas": "^2019.6.4",
"@types/react": "16.8.5",
"chai": "4.3.5",
"chai-as-promised": "^7.1.1",
"electron": "15.3.2",
"electron-mocha": "11.0.2",
"eslint": "7.32.0",
"eslint-config-airbnb-typescript-prettier": "4.2.0",
"eslint-config-prettier": "6.15.0",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-mocha": "9.0.0",
"eslint-plugin-more": "1.0.5",
"eslint-plugin-react": "7.28.0",
"mocha": "9.2.0",
"prettier": "^2.5.1",
"rimraf": "3.0.2",
"typescript": "4.5.2",
"yarn-audit-fix": "^9.2.2"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,9 @@
//
// Copyright (C) 2020 Signal Messenger, LLC.
// All rights reserved.
//
// SPDX-License-Identifier: GPL-3.0-only
// Copyright 2019-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import { RingRTC } from '../index';
import { Call } from './Service';
// Match a React.RefObject without relying on React.
@ -12,102 +11,210 @@ interface Ref<T> {
readonly current: T | null;
}
// Given a weird name to not conflict with WebCodec's VideoPixelFormat
export enum VideoPixelFormatEnum {
I420 = 0,
Nv12 = 1,
Rgba = 2,
}
function videoPixelFormatFromEnum(
format: VideoPixelFormatEnum
): VideoPixelFormat {
switch (format) {
case VideoPixelFormatEnum.I420: {
return 'I420';
}
case VideoPixelFormatEnum.Nv12: {
return 'NV12';
}
case VideoPixelFormatEnum.Rgba: {
return 'RGBA';
}
}
}
function videoPixelFormatToEnum(
format: VideoPixelFormat
): VideoPixelFormatEnum | undefined {
switch (format) {
case 'I420': {
return VideoPixelFormatEnum.I420;
}
case 'NV12': {
return VideoPixelFormatEnum.Nv12;
}
case 'RGBA': {
return VideoPixelFormatEnum.Rgba;
}
}
}
// The way a CanvasVideoRender gets VideoFrames
export interface VideoFrameSource {
// Fills in the given buffer and returns the width x height
// or returns undefined if nothing was filled in because no
// video frame was available.
receiveVideoFrame(buffer: ArrayBuffer): [number, number] | undefined;
receiveVideoFrame(buffer: Buffer): [number, number] | undefined;
}
// The way a GumVideoCapturer sends frames
// Sends frames (after getting them from something like GumVideoCapturer, for example).
interface VideoFrameSender {
sendVideoFrame(width: number, height: number, rgbaBuffer: ArrayBuffer): void;
sendVideoFrame(
width: number,
height: number,
format: VideoPixelFormatEnum,
buffer: Buffer
): void;
}
export class GumVideoCaptureOptions {
maxWidth: number = 640;
maxHeight: number = 480;
maxFramerate: number = 30;
preferredDeviceId?: string;
screenShareSourceId?: string;
}
export class GumVideoCapturer {
private readonly maxWidth: number;
private readonly maxHeight: number;
private readonly maxFramerate: number;
private defaultCaptureOptions: GumVideoCaptureOptions;
private localPreview?: Ref<HTMLVideoElement>;
private capturing: boolean;
private captureOptions?: GumVideoCaptureOptions;
private sender?: VideoFrameSender;
private mediaStream?: MediaStream;
private canvas?: OffscreenCanvas;
private canvasContext?: OffscreenCanvasRenderingContext2D;
private intervalId?: any;
private spawnedSenderRunning: boolean = false;
private preferredDeviceId?: string;
private capturingStartTime: number | undefined;
// Set this if you want fake video
public fakeVideoName: string | undefined;
private updateLocalPreviewIntervalId?: any;
constructor(maxWidth: number, maxHeight: number, maxFramerate: number) {
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
this.maxFramerate = maxFramerate;
this.capturing = false;
constructor(defaultCaptureOptions: GumVideoCaptureOptions) {
this.defaultCaptureOptions = defaultCaptureOptions;
}
capturing() {
return this.captureOptions != undefined;
}
setLocalPreview(localPreview: Ref<HTMLVideoElement> | undefined) {
const oldLocalPreview = this.localPreview?.current;
if (oldLocalPreview) {
oldLocalPreview.srcObject = null;
}
this.localPreview = localPreview;
this.updateLocalPreviewSourceObject();
// This is a dumb hack around the fact that sometimes the
// this.localPreview.current is updated without a call
// to setLocalPreview, in which case the local preview
// won't be rendered.
if (this.updateLocalPreviewIntervalId != undefined) {
clearInterval(this.updateLocalPreviewIntervalId);
}
this.updateLocalPreviewIntervalId = setInterval(
this.updateLocalPreviewSourceObject.bind(this),
1000
);
}
enableCapture(): void {
// tslint:disable no-floating-promises
this.startCapturing();
this.startCapturing(this.defaultCaptureOptions);
}
enableCaptureAndSend(sender: VideoFrameSender): void {
enableCaptureAndSend(
sender: VideoFrameSender,
options?: GumVideoCaptureOptions
): void {
// tslint:disable no-floating-promises
this.startCapturing();
this.startCapturing(options ?? this.defaultCaptureOptions);
this.startSending(sender);
}
disable(): void {
this.stopCapturing();
this.stopSending();
if (this.updateLocalPreviewIntervalId != undefined) {
clearInterval(this.updateLocalPreviewIntervalId);
}
this.updateLocalPreviewIntervalId = undefined;
}
async setPreferredDevice(deviceId: string): Promise<void> {
this.preferredDeviceId = deviceId;
if (this.capturing) {
// Restart capturing to start using the new device
await this.stopCapturing();
await this.startCapturing();
if (this.captureOptions) {
const captureOptions = this.captureOptions;
const sender = this.sender;
this.disable();
this.startCapturing(captureOptions);
if (sender) {
this.startSending(sender);
}
}
}
async enumerateDevices(): Promise<MediaDeviceInfo[]> {
const devices = await window.navigator.mediaDevices.enumerateDevices();
const cameras = devices.filter(d => d.kind == "videoinput");
const cameras = devices.filter(d => d.kind == 'videoinput');
return cameras;
}
private async startCapturing(): Promise<void> {
if (this.capturing) {
private getUserMedia(options: GumVideoCaptureOptions): Promise<MediaStream> {
// TODO: Figure out a better way to make typescript accept "mandatory".
let constraints: any = {
audio: false,
video: {
deviceId: options.preferredDeviceId ?? this.preferredDeviceId,
width: {
max: options.maxWidth,
},
height: {
max: options.maxHeight,
},
frameRate: {
max: options.maxFramerate,
},
},
};
if (options.screenShareSourceId != undefined) {
constraints.video = {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: options.screenShareSourceId,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
maxFrameRate: options.maxFramerate,
},
};
}
return window.navigator.mediaDevices.getUserMedia(constraints);
}
private async startCapturing(options: GumVideoCaptureOptions): Promise<void> {
if (this.capturing()) {
RingRTC.logWarn('startCapturing(): already capturing');
return;
}
this.capturing = true;
this.capturingStartTime = Date.now();
RingRTC.logInfo(
`startCapturing(): ${options.maxWidth}x${options.maxHeight}@${options.maxFramerate}`
);
this.captureOptions = options;
try {
const mediaStream = await window.navigator.mediaDevices.getUserMedia({
audio: false,
video: {
deviceId: this.preferredDeviceId,
width: {
max: this.maxWidth,
},
height: {
max: this.maxHeight,
},
frameRate: {
max: this.maxFramerate,
},
},
});
// We could have been disabled between when we requested the stream
// and when we got it.
if (!this.capturing) {
// If we start/stop/start, we may have concurrent calls to getUserMedia,
// which is what we want if we're switching from camera to screenshare.
// But we need to make sure we deal with the fact that things might be
// different after the await here.
const mediaStream = await this.getUserMedia(options);
// It's possible video was disabled, switched to screenshare, or
// switched to a different camera while awaiting a response, in
// which case we need to disable the camera we just accessed.
if (this.captureOptions != options) {
RingRTC.logWarn(
'startCapturing(): different state after getUserMedia()'
);
for (const track of mediaStream.getVideoTracks()) {
// Make the light turn off faster
track.stop();
@ -115,20 +222,36 @@ export class GumVideoCapturer {
return;
}
if (this.localPreview && !!this.localPreview.current && !!mediaStream) {
this.setLocalPreviewSourceObject(mediaStream);
}
this.mediaStream = mediaStream;
} catch {
// We couldn't open the camera. Oh well.
if (
!this.spawnedSenderRunning &&
this.mediaStream != undefined &&
this.sender != undefined
) {
this.spawnSender(this.mediaStream, this.sender);
}
this.updateLocalPreviewSourceObject();
} catch (e) {
RingRTC.logError(`startCapturing(): ${e}`);
// It's possible video was disabled, switched to screenshare, or
// switched to a different camera while awaiting a response, in
// which case we should reset the captureOptions if we set them.
if (this.captureOptions == options) {
// We couldn't open the camera. Oh well.
this.captureOptions = undefined;
}
}
}
private stopCapturing(): void {
if (!this.capturing) {
if (!this.capturing()) {
RingRTC.logWarn('stopCapturing(): not capturing');
return;
}
this.capturing = false;
RingRTC.logInfo('stopCapturing()');
this.captureOptions = undefined;
if (!!this.mediaStream) {
for (const track of this.mediaStream.getVideoTracks()) {
// Make the light turn off faster
@ -136,40 +259,84 @@ export class GumVideoCapturer {
}
this.mediaStream = undefined;
}
if (this.localPreview && !!this.localPreview.current) {
this.localPreview.current.srcObject = null;
}
this.updateLocalPreviewSourceObject();
}
private startSending(sender: VideoFrameSender): void {
if (this.sender === sender) {
return;
}
if (!this.sender) {
if (!!this.sender) {
// If we're replacing an existing sender, make sure we stop the
// current setInterval loop before starting another one.
this.stopSending();
}
this.sender = sender;
this.canvas = new OffscreenCanvas(this.maxWidth, this.maxHeight);
this.canvasContext = this.canvas.getContext('2d') || undefined;
const interval = 1000 / this.maxFramerate;
this.intervalId = setInterval(
this.captureAndSendOneVideoFrame.bind(this),
interval
);
}
private stopSending(): void {
this.sender = undefined;
this.canvas = undefined;
this.canvasContext = undefined;
if (!!this.intervalId) {
clearInterval(this.intervalId);
if (!this.spawnedSenderRunning && this.mediaStream != undefined) {
this.spawnSender(this.mediaStream, this.sender);
}
}
private setLocalPreviewSourceObject(mediaStream: MediaStream): void {
private spawnSender(mediaStream: MediaStream, sender: VideoFrameSender) {
const track = mediaStream.getVideoTracks()[0];
if (track == undefined || this.spawnedSenderRunning) {
return;
}
const reader = new MediaStreamTrackProcessor({
track,
}).readable.getReader();
const buffer = Buffer.alloc(MAX_VIDEO_CAPTURE_BUFFER_SIZE);
this.spawnedSenderRunning = true;
(async () => {
try {
while (sender === this.sender && mediaStream == this.mediaStream) {
const { done, value: frame } = await reader.read();
if (done) {
break;
}
if (!frame) {
continue;
}
try {
const format = videoPixelFormatToEnum(frame.format ?? 'I420');
if (format == undefined) {
RingRTC.logWarn(
`Unsupported video frame format: ${frame.format}`
);
break;
}
frame.copyTo(buffer);
sender.sendVideoFrame(
frame.codedWidth,
frame.codedHeight,
format,
buffer
);
} catch (e) {
RingRTC.logError(`sendVideoFrame(): ${e}`);
} finally {
// This must be called for more frames to come.
frame.close();
}
}
} catch (e) {
RingRTC.logError(`spawnSender(): ${e}`);
} finally {
reader.releaseLock();
}
this.spawnedSenderRunning = false;
})();
}
private stopSending(): void {
// The spawned sender should stop
this.sender = undefined;
}
private updateLocalPreviewSourceObject(): void {
if (!this.localPreview) {
return;
}
@ -178,118 +345,43 @@ export class GumVideoCapturer {
return;
}
localPreview.srcObject = mediaStream;
// I don't know why this is necessary
if (localPreview.width === 0) {
localPreview.width = this.maxWidth;
}
if (localPreview.height === 0) {
localPreview.height = this.maxHeight;
}
}
const { mediaStream = null } = this;
private captureAndSendOneVideoFrame(): void {
if (!this.canvas || !this.canvasContext || !this.sender) {
if (localPreview.srcObject === mediaStream) {
return;
}
if ((this.fakeVideoName != undefined) && (this.capturingStartTime != undefined)) {
let width = 640;
let height = 480;
let duration = Date.now() - this.capturingStartTime;
this.drawFakeVideo(this.canvasContext, width, height, this.fakeVideoName, duration);
const image = this.canvasContext.getImageData(0, 0, width, height);
this.sender.sendVideoFrame(image.width, image.height, image.data.buffer);
return;
}
if (this.localPreview && this.localPreview.current) {
if (!this.localPreview.current.srcObject && !!this.mediaStream) {
this.setLocalPreviewSourceObject(this.mediaStream);
if (mediaStream) {
localPreview.srcObject = mediaStream;
if (localPreview.width === 0) {
localPreview.width = this.captureOptions!.maxWidth;
}
const width = this.localPreview.current.videoWidth;
const height = this.localPreview.current.videoHeight;
if (width === 0 || height === 0) {
return;
if (localPreview.height === 0) {
localPreview.height = this.captureOptions!.maxHeight;
}
this.canvasContext.drawImage(
this.localPreview.current,
0,
0,
width,
height
);
const image = this.canvasContext.getImageData(0, 0, width, height);
this.sender.sendVideoFrame(image.width, image.height, image.data.buffer);
} else {
localPreview.srcObject = null;
}
}
private drawFakeVideo(context: OffscreenCanvasRenderingContext2D, width: number, height: number, name: string, time: number): void {
function fill(style: string, draw: () => void) {
context.fillStyle = style;
context.beginPath();
draw();
context.fill();
}
function stroke(style: string, draw: () => void) {
context.strokeStyle = style;
context.beginPath();
draw();
context.stroke();
}
function arc(x: number, y: number, radius: number, start: number, end: number) {
const twoPi = 2 * Math.PI;
context.arc(x, y, radius, start * twoPi, end * twoPi);
}
function circle(x: number, y: number, radius: number) {
arc(x, y, radius, 0, 1);
}
function fillFace(x: number, y: number, faceRadius: number) {
const eyeRadius = faceRadius/5;
const eyeOffsetX = faceRadius/2;
const eyeOffsetY = -faceRadius/4;
const smileRadius = faceRadius/2;
const smileOffsetY = -eyeOffsetY;
fill("yellow", () => circle(x, y, faceRadius));
fill("black", () => circle(x - eyeOffsetX, y + eyeOffsetY, eyeRadius));
fill("black", () => circle(x + eyeOffsetX, y + eyeOffsetY, eyeRadius));
stroke("black", () => arc(x, y + smileOffsetY, smileRadius, 0, 0.5));
}
function fillText(x: number, y: number, fillStyle: string, fontSize: number, fontName: string, align: CanvasTextAlign, text: string) {
context.font = `${fontSize}px ${fontName}`;
context.textAlign = align;
context.fillStyle = fillStyle;
context.fillText(text, x, y);
}
function fillLabeledFace(x: number, y: number, faceRadius: number, label: string) {
const labelSize = faceRadius*.3;
const labelOffsetY = faceRadius*1.5;
fillFace(x, y, faceRadius);
fillText(x, y + labelOffsetY, "black", labelSize, "monospace", "center", label);
}
context.fillStyle = 'white';
context.fillRect(0, 0, width, height);
fillLabeledFace(width/2, height/2, height/3, `${name} ${time}`);
}
}
// We add 10% in each dimension to allow for things that are slightly wider or taller than 1080p.
const MAX_VIDEO_CAPTURE_MULTIPLIER = 1.0;
export const MAX_VIDEO_CAPTURE_WIDTH = 1920 * MAX_VIDEO_CAPTURE_MULTIPLIER;
export const MAX_VIDEO_CAPTURE_HEIGHT = 1080 * MAX_VIDEO_CAPTURE_MULTIPLIER;
export const MAX_VIDEO_CAPTURE_AREA =
MAX_VIDEO_CAPTURE_WIDTH * MAX_VIDEO_CAPTURE_HEIGHT;
export const MAX_VIDEO_CAPTURE_BUFFER_SIZE = MAX_VIDEO_CAPTURE_AREA * 4;
export class CanvasVideoRenderer {
private canvas?: Ref<HTMLCanvasElement>;
private buffer: ArrayBuffer;
private buffer: Buffer;
private imageData?: ImageData;
private source?: VideoFrameSource;
private rafId?: any;
constructor() {
// The max size video frame we'll support (in RGBA)
this.buffer = new ArrayBuffer(1920 * 1080 * 4);
this.buffer = Buffer.alloc(MAX_VIDEO_CAPTURE_BUFFER_SIZE);
}
setCanvas(canvas: Ref<HTMLCanvasElement> | undefined) {
@ -303,8 +395,9 @@ export class CanvasVideoRenderer {
if (!!this.source) {
// If we're replacing an existing source, make sure we stop the
// current rAF loop before starting another one.
// And blanking the video is nice as well.
this.disable();
if (this.rafId) {
window.cancelAnimationFrame(this.rafId);
}
}
this.source = source;
this.requestAnimationFrameCallback();
@ -320,7 +413,9 @@ export class CanvasVideoRenderer {
private requestAnimationFrameCallback() {
this.renderVideoFrame();
this.rafId = window.requestAnimationFrame(this.requestAnimationFrameCallback.bind(this));
this.rafId = window.requestAnimationFrame(
this.requestAnimationFrameCallback.bind(this)
);
}
private renderBlack() {
@ -356,10 +451,14 @@ export class CanvasVideoRenderer {
if (!frame) {
return;
}
const [ width, height ] = frame;
const [width, height] = frame;
if (canvas.clientWidth <= 0 || width <= 0 ||
canvas.clientHeight <= 0 || height <= 0) {
if (
canvas.clientWidth <= 0 ||
width <= 0 ||
canvas.clientHeight <= 0 ||
height <= 0
) {
return;
}
@ -389,10 +488,10 @@ export class CanvasVideoRenderer {
context.fillRect(0, 0, canvas.width, canvas.height);
}
context.putImageData(
new ImageData(new Uint8ClampedArray(this.buffer, 0, width * height * 4), width, height),
dx,
dy
);
if (this.imageData?.width !== width || this.imageData?.height !== height) {
this.imageData = new ImageData(width, height);
}
this.imageData.data.set(this.buffer.subarray(0, width * height * 4));
context.putImageData(this.imageData, dx, dy);
}
}

3356
yarn.lock

File diff suppressed because it is too large Load Diff