Compare commits

..

1 Commits

Author SHA1 Message Date
Evan Hahn
65fbea6729 Update to RingRTC v2.8.2-RC.6 (macOS and Linux only) 2020-11-17 12:06:14 -06:00
20 changed files with 2178 additions and 6551 deletions

157
LICENSE
View File

@ -1,21 +1,29 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
This software is provided under:
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
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/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
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 GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
the GNU General Public License is 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.
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.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
@ -24,34 +32,44 @@ 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.
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.
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.
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.
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.
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.
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.
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.
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.
The precise terms and conditions for copying, distribution and
modification follow.
@ -60,7 +78,7 @@ modification follow.
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
@ -537,45 +555,35 @@ 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. 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.
13. Use with the GNU Affero General Public License.
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 General Public License into a single
under version 3 of the GNU Affero 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 work with which it is combined will remain governed by version
3 of the GNU General Public License.
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.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
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
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
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 Affero General
Program specifies that a certain numbered version of the GNU 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 Affero General Public License, you may choose any version ever published
GNU 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 Affero General Public License can be used, that proxy's
versions of the GNU 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.
@ -618,44 +626,3 @@ 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,27 +1,16 @@
# 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/).
## Building
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/).
For building RingRTC see [BUILDING.md](BUILDING.md).
## Contributing
Contributions to this project are welcome. Pull requests should be tested across all supported platforms.
<br/>
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.
-----------------
Signing a [CLA (Contributor License Agreement)](https://signal.org/cla/) is required for all contributions.
Copyright (C) 2020 Signal Messenger, LLC.<br/>
All rights reserved.
# 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.
Licensed under [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) only.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

4
dist/index.d.ts vendored
View File

@ -1,4 +1,4 @@
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';
export { AudioDevice, BandwidthMode, Call, CallId, CallEndedReason, CallLogLevel, CallState, CallingMessage, CallSettings, ConnectionState, DeviceId, GroupCall, GroupCallEndReason, GroupCallObserver, GroupMemberInfo, HangupMessage, HangupType, HttpMethod, JoinState, LocalDeviceState, OfferType, OpaqueMessage, RemoteDeviceState, RingRTCType, UserId, VideoCapturer, VideoRenderer, VideoRequest } from './ringrtc/Service';
export { CanvasVideoRenderer, GumVideoCapturer, VideoFrameSource, } from './ringrtc/VideoSupport';
import { RingRTCType } from './ringrtc/Service';
export declare const RingRTC: RingRTCType;

59
dist/index.js vendored
View File

@ -1,41 +1,34 @@
"use strict";
//
// Copyright 2019-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2020 Signal Messenger, LLC.
// All rights reserved.
//
// SPDX-License-Identifier: GPL-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");
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; } });
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.RingRTCType = Service_1.RingRTCType;
exports.VideoRequest = Service_1.VideoRequest;
var VideoSupport_1 = require("./ringrtc/VideoSupport");
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; } });
exports.CanvasVideoRenderer = VideoSupport_1.CanvasVideoRenderer;
exports.GumVideoCapturer = VideoSupport_1.GumVideoCapturer;
const Service_2 = require("./ringrtc/Service");
exports.RingRTC = new Service_2.RingRTCType();

View File

@ -1,110 +1,60 @@
/// <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);
}
declare type GroupCallUserId = ArrayBuffer;
export declare class PeekInfo {
devices: Array<PeekDeviceInfo>;
joinedMembers: Array<GroupCallUserId>;
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: ((callId: CallId, remoteUserId: UserId, reason: CallEndedReason, ageSec: number, wasVideoCall: boolean, receivedAtCounter: number | undefined) => void) | null;
handleAutoEndedIncomingCallRequest: ((remoteUserId: UserId, reason: CallEndedReason) => 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: 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;
}, body: ArrayBuffer | undefined) => void) | null;
handleSendCallMessage: ((recipientUuid: ArrayBuffer, message: ArrayBuffer) => void) | null;
constructor();
setConfig(config: Config): void;
setSelfUuid(uuid: Buffer): void;
private pollEvery;
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, callId: CallId, reason: CallEndedReason, ageSec: number): void;
onCallEnded(remoteUserId: UserId, reason: CallEndedReason): void;
onRemoteVideoEnabled(remoteUserId: UserId, enabled: boolean): 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;
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;
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: Buffer): void;
receivedHttpResponse(requestId: number, status: number, body: ArrayBuffer): void;
httpRequestFailed(requestId: number, debugInfo: string | undefined): void;
getGroupCall(groupId: Buffer, sfuUrl: string, hkdfExtraInfo: Buffer, audioLevelsIntervalMillis: number | undefined, observer: GroupCallObserver): GroupCall | undefined;
peekGroupCall(sfuUrl: string, membershipProof: Buffer, groupMembers: Array<GroupMemberInfo>): Promise<PeekInfo>;
getGroupCall(groupId: ArrayBuffer, sfuUrl: string, observer: GroupCallObserver): GroupCall | undefined;
peekGroupCall(sfu_url: string, membership_proof: ArrayBuffer, group_members: Array<GroupMemberInfo>): Promise<PeekInfo>;
requestMembershipProof(clientId: GroupCallClientId): void;
requestGroupMembers(clientId: GroupCallClientId): void;
handleConnectionStateChanged(clientId: GroupCallClientId, connectionState: ConnectionState): 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;
handleJoinStateChanged(clientId: GroupCallClientId, joinState: JoinState): void;
handleRemoteDevicesChanged(clientId: GroupCallClientId, remoteDeviceStates: Array<RemoteDeviceState>): 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;
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;
handleCallingMessage(remoteUserId: UserId, remoteUuid: ArrayBuffer | null, remoteDeviceId: DeviceId, localDeviceId: DeviceId, messageAgeSec: number, message: CallingMessage, senderIdentityKey: ArrayBuffer, receiverIdentityKey: ArrayBuffer): void;
sendHttpRequest(requestId: number, url: string, method: HttpMethod, headers: {
[name: string]: string;
}, body: Buffer | undefined): void;
sendCallMessage(recipientUuid: Buffer, message: Buffer, urgency: CallMessageUrgency): void;
sendCallMessageToGroup(groupId: Buffer, message: Buffer, urgency: CallMessageUrgency): void;
}, body: ArrayBuffer | undefined): void;
sendCallMessage(recipientUuid: ArrayBuffer, message: ArrayBuffer): void;
get call(): Call | null;
getCall(callId: CallId): Call | null;
accept(callId: CallId, asVideoCall: boolean): void;
@ -113,7 +63,6 @@ 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[];
@ -124,8 +73,6 @@ export declare class RingRTCType {
export interface CallSettings {
iceServer: IceServer;
hideIp: boolean;
bandwidthMode: BandwidthMode;
audioLevelsIntervalMillis?: number;
}
interface IceServer {
username?: string;
@ -140,7 +87,7 @@ export interface AudioDevice {
}
export interface VideoCapturer {
enableCapture(): void;
enableCaptureAndSend(call: Call, captureOptions?: GumVideoCaptureOptions): void;
enableCaptureAndSend(call: Call): void;
disable(): void;
}
export interface VideoRenderer {
@ -157,28 +104,19 @@ 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;
handleRemoteSharingScreen?: () => void;
handleNetworkRouteChanged?: () => void;
handleAudioLevels?: () => void;
renderVideoFrame?: (width: number, height: number, buffer: Buffer) => void;
renderVideoFrame?: (width: number, height: number, buffer: ArrayBuffer) => 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;
@ -189,14 +127,13 @@ 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, format: VideoPixelFormatEnum, buffer: Buffer): void;
receiveVideoFrame(buffer: Buffer): [number, number] | undefined;
sendVideoFrame(width: number, height: number, rgbaBuffer: ArrayBuffer): void;
receiveVideoFrame(buffer: ArrayBuffer): [number, number] | undefined;
private enableOrDisableCapturer;
private setOutgoingVideoEnabled;
updateBandwidthMode(bandwidthMode: BandwidthMode): void;
setLowBandwidthMode(enabled: boolean): void;
private enableOrDisableRenderer;
}
export declare type GroupCallClientId = number;
@ -211,34 +148,25 @@ export declare enum JoinState {
Joining = 1,
Joined = 2
}
export declare enum BandwidthMode {
Low = 0,
Normal = 1
}
export declare enum GroupCallEndReason {
DeviceExplicitlyDisconnected = 0,
ServerExplicitlyDisconnected = 1,
CallManagerIsBusy = 2,
SfuClientFailedToJoin = 3,
FailedToCreatePeerConnectionFactory = 4,
FailedToNegotiateSrtpKeys = 5,
SfuClientFailedToJoin = 2,
FailedToCreatePeerConnectionFactory = 3,
FailedToGenerateCertificate = 4,
FailedToCreateOutgoingAudioTrack = 5,
FailedToCreatePeerConnection = 6,
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
FailedToCreateDataChannel = 7,
FailedToStartPeerConnection = 8,
FailedToUpdatePeerConnection = 9,
FailedToSetMaxSendBitrate = 10,
IceFailedWhileConnecting = 11,
IceFailedAfterConnected = 12,
ServerChangedDemuxId = 13
}
export declare enum HttpMethod {
Get = 0,
@ -249,35 +177,25 @@ export declare enum HttpMethod {
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: Buffer;
userId: ArrayBuffer;
mediaKeysReceived: boolean;
audioMuted: boolean | undefined;
videoMuted: boolean | undefined;
audioLevel: NormalizedAudioLevel;
presenting: boolean | undefined;
sharingScreen: boolean | undefined;
speakerIndex: number | undefined;
videoAspectRatio: number | undefined;
addedTime: string | undefined;
speakerTime: string | undefined;
forwardingVideo: boolean | undefined;
isHigherResolutionPending: boolean;
constructor(demuxId: number, userId: Buffer, mediaKeysReceived: boolean);
audioLevel: number | undefined;
constructor(demuxId: number, userId: ArrayBuffer, mediaKeysReceived: boolean);
}
export declare class GroupMemberInfo {
userId: Buffer;
userIdCipherText: Buffer;
constructor(userId: Buffer, userIdCipherText: Buffer);
userId: ArrayBuffer;
userIdCipherText: ArrayBuffer;
constructor(userId: ArrayBuffer, userIdCipherText: ArrayBuffer);
}
export declare class VideoRequest {
demuxId: number;
@ -291,7 +209,6 @@ export interface GroupCallObserver {
requestGroupMembers(groupCall: GroupCall): void;
onLocalDeviceStateChanged(groupCall: GroupCall): void;
onRemoteDeviceStatesChanged(groupCall: GroupCall): void;
onAudioLevels(groupCall: GroupCall): void;
onPeekChanged(groupCall: GroupCall): void;
onEnded(groupCall: GroupCall, reason: GroupCallEndReason): void;
}
@ -303,7 +220,7 @@ export declare class GroupCall {
private _localDeviceState;
private _remoteDeviceStates;
private _peekInfo;
constructor(callManager: CallManager, groupId: Buffer, sfuUrl: string, hkdfExtraInfo: Buffer, audioLevelsIntervalMillis: number | undefined, observer: GroupCallObserver);
constructor(callManager: CallManager, groupId: ArrayBuffer, sfuUrl: string, observer: GroupCallObserver);
connect(): void;
join(): void;
leave(): void;
@ -313,24 +230,19 @@ export declare class GroupCall {
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;
requestVideo(resolutions: Array<VideoRequest>, activeSpeakerHeight: number): void;
requestVideo(resolutions: Array<VideoRequest>): void;
setGroupMembers(members: Array<GroupMemberInfo>): void;
setMembershipProof(proof: Buffer): void;
setMembershipProof(proof: ArrayBuffer): void;
requestMembershipProof(): void;
requestGroupMembers(): void;
handleConnectionStateChanged(connectionState: ConnectionState): void;
handleJoinStateChanged(joinState: JoinState, demuxId: number | undefined): void;
handleNetworkRouteChanged(localNetworkAdapterType: NetworkAdapterType): void;
handleAudioLevels(capturedLevel: RawAudioLevel, receivedLevels: Array<ReceivedAudioLevel>): void;
handleJoinStateChanged(joinState: JoinState): void;
handleRemoteDevicesChanged(remoteDeviceStates: Array<RemoteDeviceState>): void;
handlePeekChanged(info: PeekInfo): void;
handleEnded(reason: GroupCallEndReason): void;
sendVideoFrame(width: number, height: number, format: VideoPixelFormatEnum, buffer: Buffer): void;
sendVideoFrame(width: number, height: number, rgbaBuffer: ArrayBuffer): void;
getVideoSource(remoteDemuxId: number): GroupCallVideoFrameSource;
setRemoteAspectRatio(remoteDemuxId: number, aspectRatio: number): void;
}
@ -339,9 +251,9 @@ declare class GroupCallVideoFrameSource {
private readonly _groupCall;
private readonly _remoteDemuxId;
constructor(callManager: CallManager, groupCall: GroupCall, remoteDemuxId: number);
receiveVideoFrame(buffer: Buffer): [number, number] | undefined;
receiveVideoFrame(buffer: ArrayBuffer): [number, number] | undefined;
}
declare type ProtobufBuffer = Buffer | {
declare type ProtobufArrayBuffer = ArrayBuffer | {
toArrayBuffer: () => ArrayBuffer;
};
export declare type UserId = string;
@ -361,7 +273,7 @@ export declare class CallingMessage {
export declare class OfferMessage {
callId?: CallId;
type?: OfferType;
opaque?: ProtobufBuffer;
opaque?: ProtobufArrayBuffer;
sdp?: string;
}
export declare enum OfferType {
@ -370,14 +282,14 @@ export declare enum OfferType {
}
export declare class AnswerMessage {
callId?: CallId;
opaque?: ProtobufBuffer;
opaque?: ProtobufArrayBuffer;
sdp?: string;
}
export declare class IceCandidateMessage {
callId?: CallId;
mid?: string;
line?: number;
opaque?: ProtobufBuffer;
opaque?: ProtobufArrayBuffer;
sdp?: string;
}
export declare class BusyMessage {
@ -389,7 +301,7 @@ export declare class HangupMessage {
deviceId?: DeviceId;
}
export declare class OpaqueMessage {
data?: ProtobufBuffer;
data?: ProtobufArrayBuffer;
}
export declare enum HangupType {
Normal = 0,
@ -398,41 +310,28 @@ 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, bandwidthMode: BandwidthMode, audioLevelsIntervalMillis: number): void;
proceed(callId: CallId, iceServerUsername: string, iceServerPassword: string, iceServerUrls: Array<string>, hideIp: boolean): 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;
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;
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;
receivedHangup(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId, hangupType: HangupType, hangupDeviceId: DeviceId | null): void;
receivedBusy(remoteUserId: UserId, remoteDeviceId: DeviceId, callId: CallId): void;
receivedCallMessage(remoteUserId: Buffer, remoteDeviceId: DeviceId, localDeviceId: DeviceId, data: Buffer, messageAgeSec: number): void;
receivedHttpResponse(requestId: number, status: number, body: Buffer): void;
receivedCallMessage(remoteUserId: ArrayBuffer, remoteDeviceId: DeviceId, localDeviceId: DeviceId, data: ArrayBuffer, messageAgeSec: number): void;
receivedHttpResponse(requestId: number, status: number, body: ArrayBuffer): void;
httpRequestFailed(requestId: number, debugInfo: string | undefined): void;
createGroupCallClient(groupId: Buffer, sfuUrl: string, hkdfExtraInfo: Buffer, audioLevelsIntervalMillis: number): GroupCallClientId;
createGroupCallClient(groupId: ArrayBuffer, sfuUrl: string): GroupCallClientId;
deleteGroupCallClient(clientId: GroupCallClientId): void;
connect(clientId: GroupCallClientId): void;
join(clientId: GroupCallClientId): void;
@ -440,42 +339,39 @@ 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;
requestVideo(clientId: GroupCallClientId, resolutions: Array<VideoRequest>, activeSpeakerHeight: number): void;
requestVideo(clientId: GroupCallClientId, resolutions: Array<VideoRequest>): void;
setGroupMembers(clientId: GroupCallClientId, members: Array<GroupMemberInfo>): void;
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>;
setMembershipProof(clientId: GroupCallClientId, proof: ArrayBuffer): void;
receiveGroupCallVideoFrame(clientId: GroupCallClientId, remoteDemuxId: number, buffer: ArrayBuffer): [number, number] | undefined;
peekGroupCall(requestId: number, sfu_url: string, membership_proof: ArrayBuffer, 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, callId: CallId, endedReason: CallEndedReason, ageSec: number): void;
onCallEnded(remoteUserId: UserId, endedReason: CallEndedReason): void;
onRemoteVideoEnabled(remoteUserId: UserId, enabled: boolean): 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;
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;
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: Buffer, message: Buffer, urgency: CallMessageUrgency): void;
sendCallMessageToGroup(groupId: Buffer, message: Buffer, urgency: CallMessageUrgency): void;
sendCallMessage(recipientUuid: ArrayBuffer, message: ArrayBuffer): void;
sendHttpRequest(requestId: number, url: string, method: HttpMethod, headers: {
[name: string]: string;
}, body: Buffer | undefined): void;
}, body: ArrayBuffer | undefined): void;
requestMembershipProof(clientId: GroupCallClientId): void;
requestGroupMembers(clientId: GroupCallClientId): void;
handleConnectionStateChanged(clientId: GroupCallClientId, connectionState: ConnectionState): void;
handleJoinStateChanged(clientId: GroupCallClientId, joinState: JoinState, demuxId: number | undefined): void;
handleJoinStateChanged(clientId: GroupCallClientId, joinState: JoinState): void;
handleRemoteDevicesChanged(clientId: GroupCallClientId, remoteDeviceStates: Array<RemoteDeviceState>): void;
handlePeekChanged(clientId: GroupCallClientId, info: PeekInfo): void;
handlePeekResponse(request_id: number, info: PeekInfo): void;
@ -483,7 +379,7 @@ export interface CallManagerCallbacks {
onLogMessage(level: number, fileName: string, line: number, message: string): void;
}
export declare enum CallState {
Prering = "idle",
Prering = "init",
Ringing = "ringing",
Accepted = "connected",
Reconnecting = "connecting",
@ -496,18 +392,17 @@ 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"
BusyOnAnotherDevice = "BusyOnAnotherDevice",
CallerIsNotMultiring = "CallerIsNotMultiring"
}
export declare enum CallLogLevel {
Off = 0,

File diff suppressed because it is too large Load Diff

View File

@ -1,58 +1,44 @@
/// <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: Buffer): [number, number] | undefined;
receiveVideoFrame(buffer: ArrayBuffer): [number, number] | undefined;
}
interface VideoFrameSender {
sendVideoFrame(width: number, height: number, format: VideoPixelFormatEnum, buffer: Buffer): void;
}
export declare class GumVideoCaptureOptions {
maxWidth: number;
maxHeight: number;
maxFramerate: number;
preferredDeviceId?: string;
screenShareSourceId?: string;
sendVideoFrame(width: number, height: number, rgbaBuffer: ArrayBuffer): void;
}
export declare class GumVideoCapturer {
private defaultCaptureOptions;
private readonly maxWidth;
private readonly maxHeight;
private readonly maxFramerate;
private localPreview?;
private captureOptions?;
private capturing;
private sender?;
private mediaStream?;
private spawnedSenderRunning;
private canvas?;
private canvasContext?;
private intervalId?;
private preferredDeviceId?;
private updateLocalPreviewIntervalId?;
constructor(defaultCaptureOptions: GumVideoCaptureOptions);
capturing(): boolean;
private capturingStartTime;
fakeVideoName: string | undefined;
constructor(maxWidth: number, maxHeight: number, maxFramerate: number);
setLocalPreview(localPreview: Ref<HTMLVideoElement> | undefined): void;
enableCapture(): void;
enableCaptureAndSend(sender: VideoFrameSender, options?: GumVideoCaptureOptions): void;
enableCaptureAndSend(sender: VideoFrameSender): void;
disable(): void;
setPreferredDevice(deviceId: string): Promise<void>;
enumerateDevices(): Promise<MediaDeviceInfo[]>;
private getUserMedia;
private startCapturing;
private stopCapturing;
private startSending;
private spawnSender;
private stopSending;
private updateLocalPreviewSourceObject;
private setLocalPreviewSourceObject;
private captureAndSendOneVideoFrame;
private drawFakeVideo;
}
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,7 +1,9 @@
"use strict";
//
// Copyright 2019-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2020 Signal Messenger, LLC.
// All rights reserved.
//
// SPDX-License-Identifier: GPL-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); }); }
@ -13,195 +15,93 @@ 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(defaultCaptureOptions) {
this.spawnedSenderRunning = false;
this.defaultCaptureOptions = defaultCaptureOptions;
}
capturing() {
return this.captureOptions != undefined;
constructor(maxWidth, maxHeight, maxFramerate) {
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
this.maxFramerate = maxFramerate;
this.capturing = false;
}
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.defaultCaptureOptions);
this.startCapturing();
}
enableCaptureAndSend(sender, options) {
enableCaptureAndSend(sender) {
// tslint:disable no-floating-promises
this.startCapturing(options !== null && options !== void 0 ? options : this.defaultCaptureOptions);
this.startCapturing();
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.captureOptions) {
const captureOptions = this.captureOptions;
const sender = this.sender;
this.disable();
this.startCapturing(captureOptions);
if (sender) {
this.startSending(sender);
}
if (this.capturing) {
// Restart capturing to start using the new device
yield this.stopCapturing();
yield this.startCapturing();
}
});
}
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;
});
}
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) {
startCapturing() {
return __awaiter(this, void 0, void 0, function* () {
if (this.capturing()) {
index_1.RingRTC.logWarn('startCapturing(): already capturing');
if (this.capturing) {
return;
}
index_1.RingRTC.logInfo(`startCapturing(): ${options.maxWidth}x${options.maxHeight}@${options.maxFramerate}`);
this.captureOptions = options;
this.capturing = true;
this.capturingStartTime = Date.now();
try {
// 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()');
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) {
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 (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;
}
catch (_a) {
// We couldn't open the camera. Oh well.
}
});
}
stopCapturing() {
if (!this.capturing()) {
index_1.RingRTC.logWarn('stopCapturing(): not capturing');
if (!this.capturing) {
return;
}
index_1.RingRTC.logInfo('stopCapturing()');
this.captureOptions = undefined;
this.capturing = false;
if (!!this.mediaStream) {
for (const track of this.mediaStream.getVideoTracks()) {
// Make the light turn off faster
@ -209,75 +109,34 @@ class GumVideoCapturer {
}
this.mediaStream = undefined;
}
this.updateLocalPreviewSourceObject();
if (this.localPreview && !!this.localPreview.current) {
this.localPreview.current.srcObject = null;
}
}
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;
if (!this.spawnedSenderRunning && this.mediaStream != undefined) {
this.spawnSender(this.mediaStream, this.sender);
}
}
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;
}))();
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() {
// The spawned sender should stop
this.sender = undefined;
this.canvas = undefined;
this.canvasContext = undefined;
if (!!this.intervalId) {
clearInterval(this.intervalId);
}
}
updateLocalPreviewSourceObject() {
setLocalPreviewSourceObject(mediaStream) {
if (!this.localPreview) {
return;
}
@ -285,34 +144,95 @@ class GumVideoCapturer {
if (!localPreview) {
return;
}
const { mediaStream = null } = this;
if (localPreview.srcObject === mediaStream) {
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) {
return;
}
if (mediaStream) {
localPreview.srcObject = mediaStream;
if (localPreview.width === 0) {
localPreview.width = this.captureOptions.maxWidth;
}
if (localPreview.height === 0) {
localPreview.height = this.captureOptions.maxHeight;
}
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;
}
else {
localPreview.srcObject = null;
if (this.localPreview && this.localPreview.current) {
if (!this.localPreview.current.srcObject && !!this.mediaStream) {
this.setLocalPreviewSourceObject(this.mediaStream);
}
const width = this.localPreview.current.videoWidth;
const height = this.localPreview.current.videoHeight;
if (width === 0 || height === 0) {
return;
}
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();
}
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() {
this.buffer = Buffer.alloc(exports.MAX_VIDEO_CAPTURE_BUFFER_SIZE);
// The max size video frame we'll support (in RGBA)
this.buffer = new ArrayBuffer(1920 * 1080 * 4);
}
setCanvas(canvas) {
this.canvas = canvas;
@ -358,7 +278,6 @@ class CanvasVideoRenderer {
context.fillRect(0, 0, canvas.width, canvas.height);
}
renderVideoFrame() {
var _a, _b;
if (!this.source || !this.canvas) {
return;
}
@ -375,10 +294,8 @@ 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;
@ -406,11 +323,7 @@ class CanvasVideoRenderer {
context.fillStyle = 'black';
context.fillRect(0, 0, canvas.width, canvas.height);
}
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);
context.putImageData(new ImageData(new Uint8ClampedArray(this.buffer, 0, width * height * 4), width, height), dx, dy);
}
}
exports.CanvasVideoRenderer = CanvasVideoRenderer;

View File

@ -1,51 +1,45 @@
//
// Copyright 2019-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2020 Signal Messenger, LLC.
// All rights reserved.
//
// SPDX-License-Identifier: GPL-3.0-only
//
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,
AudioDevice,
BandwidthMode,
Call,
CallId,
CallEndedReason,
CallLogLevel,
CallState,
CallingMessage,
CallSettings,
ConnectionState,
DeviceId,
GroupCall,
GroupCallEndReason,
GroupCallObserver,
GroupMemberInfo,
HangupMessage,
HangupType,
HttpMethod,
JoinState,
LocalDeviceState,
OfferType,
OpaqueMessage,
RemoteDeviceState,
RingRTCType,
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,
CanvasVideoRenderer,
GumVideoCapturer,
VideoFrameSource,
} from './ringrtc/VideoSupport';
import { RingRTCType } from './ringrtc/Service';

1812
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,47 +1,45 @@
{
"name": "ringrtc",
"version": "2.22.0",
"version": "2.8.1",
"description": "Signal Messenger voice and video calling library.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/ringrtc/*",
"build/*"
"dist/index.d.ts"
],
"scripts": {
"build": "tsc",
"clean": "rimraf dist",
"test": "electron-mocha --recursive dist/test",
"eslint": "eslint --cache .",
"lint": "yarn format --list-different && yarn eslint",
"eslint": "eslint .",
"lint": "yarn eslint && yarn tslint",
"tslint": "tslint --format stylish --project .",
"format": "prettier --write \"*.{css,js,json,md,scss,ts,tsx}\" \"./**/*.{css,js,json,md,scss,ts,tsx}\""
},
"author": "",
"license": "AGPL-3.0-only",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"@types/chai": "4.2.18",
"@types/chai-as-promised": "^7.1.3",
"@types/dom-mediacapture-transform": "0.1.2",
"@types/chai": "4.2.7",
"@types/mocha": "5.2.7",
"@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"
"@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"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,10 @@
//
// Copyright 2019-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (C) 2020 Signal Messenger, LLC.
// All rights reserved.
//
// SPDX-License-Identifier: GPL-3.0-only
//
import { RingRTC } from '../index';
import { Call } from './Service';
// Match a React.RefObject without relying on React.
@ -11,210 +12,102 @@ 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: Buffer): [number, number] | undefined;
receiveVideoFrame(buffer: ArrayBuffer): [number, number] | undefined;
}
// Sends frames (after getting them from something like GumVideoCapturer, for example).
// The way a GumVideoCapturer sends frames
interface VideoFrameSender {
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;
sendVideoFrame(width: number, height: number, rgbaBuffer: ArrayBuffer): void;
}
export class GumVideoCapturer {
private defaultCaptureOptions: GumVideoCaptureOptions;
private readonly maxWidth: number;
private readonly maxHeight: number;
private readonly maxFramerate: number;
private localPreview?: Ref<HTMLVideoElement>;
private captureOptions?: GumVideoCaptureOptions;
private capturing: boolean;
private sender?: VideoFrameSender;
private mediaStream?: MediaStream;
private spawnedSenderRunning: boolean = false;
private canvas?: OffscreenCanvas;
private canvasContext?: OffscreenCanvasRenderingContext2D;
private intervalId?: any;
private preferredDeviceId?: string;
private updateLocalPreviewIntervalId?: any;
private capturingStartTime: number | undefined;
// Set this if you want fake video
public fakeVideoName: string | undefined;
constructor(defaultCaptureOptions: GumVideoCaptureOptions) {
this.defaultCaptureOptions = defaultCaptureOptions;
}
capturing() {
return this.captureOptions != undefined;
constructor(maxWidth: number, maxHeight: number, maxFramerate: number) {
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
this.maxFramerate = maxFramerate;
this.capturing = false;
}
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.defaultCaptureOptions);
this.startCapturing();
}
enableCaptureAndSend(
sender: VideoFrameSender,
options?: GumVideoCaptureOptions
): void {
enableCaptureAndSend(sender: VideoFrameSender): void {
// tslint:disable no-floating-promises
this.startCapturing(options ?? this.defaultCaptureOptions);
this.startCapturing();
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.captureOptions) {
const captureOptions = this.captureOptions;
const sender = this.sender;
this.disable();
this.startCapturing(captureOptions);
if (sender) {
this.startSending(sender);
}
if (this.capturing) {
// Restart capturing to start using the new device
await this.stopCapturing();
await this.startCapturing();
}
}
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 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');
private async startCapturing(): Promise<void> {
if (this.capturing) {
return;
}
RingRTC.logInfo(
`startCapturing(): ${options.maxWidth}x${options.maxHeight}@${options.maxFramerate}`
);
this.captureOptions = options;
this.capturing = true;
this.capturingStartTime = Date.now();
try {
// 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()'
);
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) {
for (const track of mediaStream.getVideoTracks()) {
// Make the light turn off faster
track.stop();
@ -222,36 +115,20 @@ export class GumVideoCapturer {
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 (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;
}
} catch {
// We couldn't open the camera. Oh well.
}
}
private stopCapturing(): void {
if (!this.capturing()) {
RingRTC.logWarn('stopCapturing(): not capturing');
if (!this.capturing) {
return;
}
RingRTC.logInfo('stopCapturing()');
this.captureOptions = undefined;
this.capturing = false;
if (!!this.mediaStream) {
for (const track of this.mediaStream.getVideoTracks()) {
// Make the light turn off faster
@ -259,84 +136,40 @@ export class GumVideoCapturer {
}
this.mediaStream = undefined;
}
this.updateLocalPreviewSourceObject();
if (this.localPreview && !!this.localPreview.current) {
this.localPreview.current.srcObject = null;
}
}
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;
if (!this.spawnedSenderRunning && this.mediaStream != undefined) {
this.spawnSender(this.mediaStream, this.sender);
}
}
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;
})();
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 {
// The spawned sender should stop
this.sender = undefined;
this.canvas = undefined;
this.canvasContext = undefined;
if (!!this.intervalId) {
clearInterval(this.intervalId);
}
}
private updateLocalPreviewSourceObject(): void {
private setLocalPreviewSourceObject(mediaStream: MediaStream): void {
if (!this.localPreview) {
return;
}
@ -345,43 +178,118 @@ export class GumVideoCapturer {
return;
}
const { mediaStream = null } = this;
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;
}
}
if (localPreview.srcObject === mediaStream) {
private captureAndSendOneVideoFrame(): void {
if (!this.canvas || !this.canvasContext || !this.sender) {
return;
}
if (mediaStream) {
localPreview.srcObject = mediaStream;
if (localPreview.width === 0) {
localPreview.width = this.captureOptions!.maxWidth;
}
if (localPreview.height === 0) {
localPreview.height = this.captureOptions!.maxHeight;
}
} else {
localPreview.srcObject = null;
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);
}
const width = this.localPreview.current.videoWidth;
const height = this.localPreview.current.videoHeight;
if (width === 0 || height === 0) {
return;
}
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);
}
}
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: Buffer;
private imageData?: ImageData;
private buffer: ArrayBuffer;
private source?: VideoFrameSource;
private rafId?: any;
constructor() {
this.buffer = Buffer.alloc(MAX_VIDEO_CAPTURE_BUFFER_SIZE);
// The max size video frame we'll support (in RGBA)
this.buffer = new ArrayBuffer(1920 * 1080 * 4);
}
setCanvas(canvas: Ref<HTMLCanvasElement> | undefined) {
@ -413,9 +321,7 @@ 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() {
@ -451,14 +357,10 @@ 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;
}
@ -488,10 +390,10 @@ export class CanvasVideoRenderer {
context.fillRect(0, 0, canvas.width, canvas.height);
}
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);
context.putImageData(
new ImageData(new Uint8ClampedArray(this.buffer, 0, width * height * 4), width, height),
dx,
dy
);
}
}

3354
yarn.lock

File diff suppressed because it is too large Load Diff