Skip to content

Commit

Permalink
feat: release pr
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 committed Jun 14, 2024
2 parents 7c3716d + c6f0747 commit c088f27
Show file tree
Hide file tree
Showing 26 changed files with 408 additions and 152 deletions.
4 changes: 1 addition & 3 deletions examples/prebuilt-react-integration/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ import { getRoomCodeFromUrl } from './utils';
export default function App() {
const roomCode = getRoomCodeFromUrl();

return (
<HMSPrebuilt roomCode={roomCode} />
);
return <HMSPrebuilt roomCode={roomCode} />;
}
13 changes: 13 additions & 0 deletions packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@ export default class AnalyticsEventFactory {
});
}

static krispStart() {
return new AnalyticsEvent({
name: 'krisp.start',
level: AnalyticsEventLevel.INFO,
});
}

static krispStop() {
return new AnalyticsEvent({
name: 'krisp.stop',
level: AnalyticsEventLevel.INFO,
});
}
private static eventNameFor(name: string, ok: boolean) {
const suffix = ok ? 'success' : 'failed';
return `${name}.${suffix}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { EventBus } from '../../events/EventBus';
import { HMSAudioTrackSettings as IHMSAudioTrackSettings } from '../../interfaces';
import { HMSAudioPlugin, HMSPluginSupportResult } from '../../plugins';
import { HMSAudioPluginsManager } from '../../plugins/audio';
import Room from '../../sdk/models/HMSRoom';
import HMSLogger from '../../utils/logger';
import { isBrowser, isIOS } from '../../utils/support';
import { getAudioTrack, isEmptyTrack } from '../../utils/track';
Expand Down Expand Up @@ -46,6 +47,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack {
source: string,
private eventBus: EventBus,
settings: HMSAudioTrackSettings = new HMSAudioTrackSettingsBuilder().build(),
room?: Room,
) {
super(stream, track, source);
stream.tracks.push(this);
Expand All @@ -56,7 +58,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack {
if (settings.deviceId !== track.getSettings().deviceId && !isEmptyTrack(track)) {
this.settings = this.buildNewSettings({ deviceId: track.getSettings().deviceId });
}
this.pluginsManager = new HMSAudioPluginsManager(this, eventBus);
this.pluginsManager = new HMSAudioPluginsManager(this, eventBus, room);
this.setFirstTrackId(track.id);
if (isIOS() && isBrowser) {
document.addEventListener('visibilitychange', this.handleVisibilityChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { HMSPluginSupportResult, HMSVideoPlugin } from '../../plugins';
import { HMSMediaStreamPlugin, HMSVideoPluginsManager } from '../../plugins/video';
import { HMSMediaStreamPluginsManager } from '../../plugins/video/HMSMediaStreamPluginsManager';
import { LocalTrackManager } from '../../sdk/LocalTrackManager';
import Room from '../../sdk/models/HMSRoom';
import HMSLogger from '../../utils/logger';
import { isBrowser, isMobile } from '../../utils/support';
import { getVideoTrack, isEmptyTrack } from '../../utils/track';
Expand Down Expand Up @@ -69,6 +70,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack {
source: string,
private eventBus: EventBus,
settings: HMSVideoTrackSettings = new HMSVideoTrackSettingsBuilder().build(),
room?: Room,
) {
super(stream, track, source);
stream.tracks.push(this);
Expand All @@ -80,7 +82,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack {
this.settings = this.buildNewSettings({ deviceId: track.getSettings().deviceId });
}
this.pluginsManager = new HMSVideoPluginsManager(this, eventBus);
this.mediaStreamPluginsManager = new HMSMediaStreamPluginsManager(eventBus);
this.mediaStreamPluginsManager = new HMSMediaStreamPluginsManager(eventBus, room);
this.setFirstTrackId(this.trackId);
if (isBrowser && isMobile()) {
document.addEventListener('visibilitychange', this.handleVisibilityChange);
Expand Down
4 changes: 3 additions & 1 deletion packages/hms-video-store/src/media/tracks/HMSVideoTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ export class HMSVideoTrack extends HMSTrack {
if (videoElement.paused) {
// This is needed for safari and firefox to work properly
videoElement.srcObject = stream;
videoElement.play().catch(console.error);
videoElement.play().catch(() => {
//do nothing
});
}
}, 0);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export enum HMSTranscriptionState {
export enum HMSTranscriptionMode {
CAPTION = 'caption',
}
interface PluginPermissions {
export interface WhiteBoardPluginPermissions {
permissions?: {
// list of roles
admin?: Array<string>;
Expand All @@ -86,17 +86,21 @@ interface PluginPermissions {
};
}

interface TranscriptionPluginPermissions {
export interface TranscriptionPluginPermissions {
permissions?: {
// list of roles
admin?: Array<string>;
};
mode: HMSTranscriptionMode;
}

export interface NoiseCancellationPlugin {
enabled?: boolean;
}
export enum Plugins {
WHITEBOARD = 'whiteboard',
TRANSCRIPTIONS = 'transcriptions',
NOISE_CANCELLATION = 'noiseCancellation',
}

export interface PolicyParams {
Expand All @@ -105,8 +109,9 @@ export interface PolicyParams {
[role: string]: HMSRole;
};
plugins: {
[Plugins.WHITEBOARD]?: PluginPermissions;
[Plugins.WHITEBOARD]?: WhiteBoardPluginPermissions;
[Plugins.TRANSCRIPTIONS]?: TranscriptionPluginPermissions[];
[Plugins.NOISE_CANCELLATION]?: NoiseCancellationPlugin;
};
template_id: string;
app_data?: Record<string, string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { AudioPluginsAnalytics } from './AudioPluginsAnalytics';
import { HMSAudioPlugin, HMSPluginUnsupportedTypes } from './HMSAudioPlugin'; //HMSAudioPluginType
import AnalyticsEventFactory from '../../analytics/AnalyticsEventFactory';
import { ErrorFactory } from '../../error/ErrorFactory';
import { HMSAction } from '../../error/HMSAction';
import { EventBus } from '../../events/EventBus';
import { HMSLocalAudioTrack } from '../../media/tracks';
import Room from '../../sdk/models/HMSRoom';
import HMSLogger from '../../utils/logger';

const DEFAULT_SAMPLE_RATE = 48000;
Expand Down Expand Up @@ -40,12 +42,14 @@ export class HMSAudioPluginsManager {
// This will replace the native track in peer connection when plugins are enabled
private outputTrack?: MediaStreamTrack;
private pluginAddInProgress = false;
private room?: Room;

constructor(track: HMSLocalAudioTrack, private eventBus: EventBus) {
constructor(track: HMSLocalAudioTrack, private eventBus: EventBus, room?: Room) {
this.hmsTrack = track;
this.pluginsMap = new Map();
this.analytics = new AudioPluginsAnalytics(eventBus);
this.createAudioContext();
this.room = room;
}

getPlugins(): string[] {
Expand All @@ -69,6 +73,22 @@ export class HMSAudioPluginsManager {
throw err;
}

switch (plugin.getName()) {
case 'HMSKrispPlugin':
if (!this.room?.isNoiseCancellationEnabled) {
const errorMessage = 'Krisp Noise Cancellation is not enabled for this room';
if (this.pluginsMap.size === 0) {
throw Error(errorMessage);
} else {
HMSLogger.w(this.TAG, errorMessage);
return;
}
}
this.eventBus.analytics.publish(AnalyticsEventFactory.krispStart());
break;

default:
}
this.pluginAddInProgress = true;

try {
Expand Down Expand Up @@ -140,6 +160,13 @@ export class HMSAudioPluginsManager {
}

async removePlugin(plugin: HMSAudioPlugin) {
switch (plugin.getName()) {
case 'HMSKrispPlugin':
this.eventBus.analytics.publish(AnalyticsEventFactory.krispStop());
break;
default:
break;
}
await this.removePluginInternal(plugin);
if (this.pluginsMap.size === 0) {
// remove all previous nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,39 @@ import { HMSMediaStreamPlugin } from './HMSMediaStreamPlugin';
import { VideoPluginsAnalytics } from './VideoPluginsAnalytics';
import { EventBus } from '../../events/EventBus';
import { HMSException } from '../../internal';
import Room from '../../sdk/models/HMSRoom';
import HMSLogger from '../../utils/logger';

export class HMSMediaStreamPluginsManager {
private readonly TAG = '[MediaStreamPluginsManager]';
private analytics: VideoPluginsAnalytics;
private plugins: Set<HMSMediaStreamPlugin>;
private room?: Room;

constructor(eventBus: EventBus) {
constructor(eventBus: EventBus, room?: Room) {
this.plugins = new Set<HMSMediaStreamPlugin>();
this.analytics = new VideoPluginsAnalytics(eventBus);
this.room = room;
}

addPlugins(plugins: HMSMediaStreamPlugin[]): void {
plugins.forEach(plugin => this.plugins.add(plugin));
plugins.forEach(plugin => {
switch (plugin.getName()) {
case 'HMSEffectsPlugin':
if (!this.room?.isEffectsEnabled) {
const errorMessage = 'Effects Virtual Background is not enabled for this room';
if (this.plugins.size === 0) {
throw Error(errorMessage);
} else {
HMSLogger.w(this.TAG, errorMessage);
return;
}
}
break;
default:
}
this.plugins.add(plugin);
});
}

removePlugins(plugins: HMSMediaStreamPlugin[]) {
Expand Down
12 changes: 11 additions & 1 deletion packages/hms-video-store/src/sdk/LocalTrackManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,14 @@ export class LocalTrackManager {
const tracks: Array<HMSLocalTrack> = [];
const local = new HMSLocalStream(stream);
const nativeVideoTrack = stream.getVideoTracks()[0];
const videoTrack = new HMSLocalVideoTrack(local, nativeVideoTrack, 'screen', this.eventBus, screenSettings?.video);
const videoTrack = new HMSLocalVideoTrack(
local,
nativeVideoTrack,
'screen',
this.eventBus,
screenSettings?.video,
this.store.getRoom(),
);
videoTrack.setSimulcastDefinitons(this.store.getSimulcastDefinitionsForPeer(this.store.getLocalPeer()!, 'screen'));

try {
Expand All @@ -257,6 +264,7 @@ export class LocalTrackManager {
'screen',
this.eventBus,
screenSettings?.audio,
this.store.getRoom(),
);
tracks.push(audioTrack);
}
Expand Down Expand Up @@ -623,6 +631,7 @@ export class LocalTrackManager {
'regular',
this.eventBus,
settings.audio,
this.store.getRoom(),
);
tracks.push(audioTrack);
}
Expand All @@ -634,6 +643,7 @@ export class LocalTrackManager {
'regular',
this.eventBus,
settings.video,
this.store.getRoom(),
);
videoTrack.setSimulcastDefinitons(
this.store.getSimulcastDefinitionsForPeer(this.store.getLocalPeer()!, 'regular'),
Expand Down
Loading

0 comments on commit c088f27

Please sign in to comment.