Skip to content

Commit

Permalink
handle explicit remote unmute, removed mute status match (#40)
Browse files Browse the repository at this point in the history
* handle explicit remote unmute, removed mute status match

* missed yarn.lock
  • Loading branch information
davidzhao authored Sep 6, 2021
1 parent 8c23dbc commit 96305c0
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 924 deletions.
7 changes: 2 additions & 5 deletions example/sample.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
connect, createLocalScreenTracks, CreateVideoTrackOptions,
LocalAudioTrack,
connect, createLocalScreenTracks, CreateVideoTrackOptions, DataPacket_Kind, LocalAudioTrack,
LocalTrack,
LocalVideoTrack,
LogLevel,
Expand All @@ -10,10 +9,8 @@ import {
RemoteTrack,
Room,
RoomEvent,
Track,
VideoPresets,
Track, VideoPresets,
} from '../src/index';
import { DataPacket_Kind } from '../src/proto/livekit_rtc';

const $ = (id: string) => document.getElementById(id);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"eslint-plugin-import": "^2.22.0",
"gh-pages": "^3.2.3",
"ts-loader": "^8.1.0",
"ts-proto": "1.79.1",
"ts-proto": "1.82.5",
"typedoc": "^0.20.35",
"typedoc-plugin-no-inherit": "^1.2.0",
"typescript": "~4.2.3",
Expand Down
19 changes: 10 additions & 9 deletions src/api/SignalClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import log from 'loglevel';
import 'webrtc-adapter';
import { ParticipantInfo } from '../proto/livekit_models';
import { ParticipantInfo, SpeakerInfo } from '../proto/livekit_models';
import {
AddTrackRequest,
JoinResponse,
SessionDescription,
SignalRequest,
SignalResponse,
SignalTarget,
SpeakerInfo,
TrackPublishedResponse,
UpdateSubscription,
UpdateTrackSettings,
Expand All @@ -21,7 +20,6 @@ import { protocolVersion } from '../version';
// internal options
interface ConnectOpts {
autoSubscribe?: boolean;
usePlanB?: boolean;
/** internal */
reconnect?: boolean;
}
Expand All @@ -36,7 +34,7 @@ export interface SignalOptions {
* so that it
*/
export interface SignalClient {
join(url: string, token: string, usePlanB?: boolean, opts?: SignalOptions): Promise<JoinResponse>;
join(url: string, token: string, opts?: SignalOptions): Promise<JoinResponse>;
reconnect(url: string, token: string): Promise<void>;
sendOffer(offer: RTCSessionDescriptionInit): void;
sendAnswer(answer: RTCSessionDescriptionInit): void;
Expand Down Expand Up @@ -65,6 +63,8 @@ export interface SignalClient {
onLocalTrackPublished?: (res: TrackPublishedResponse) => void;
// when active speakers changed
onActiveSpeakersChanged?: (res: SpeakerInfo[]) => void;
// when track was muted/unmuted by the server
onRemoteMuteChanged?: (trackSid: string, muted: boolean) => void;
onLeave?: () => void;
}

Expand All @@ -90,6 +90,8 @@ export class WSSignalClient {

onActiveSpeakersChanged?: (res: SpeakerInfo[]) => void;

onRemoteMuteChanged?: (trackSid: string, muted: boolean) => void;

onLeave?: () => void;

ws?: WebSocket;
Expand All @@ -102,11 +104,9 @@ export class WSSignalClient {
async join(
url: string,
token: string,
planB: boolean = false,
opts?: SignalOptions,
): Promise<JoinResponse> {
const res = await this.connect(url, token, {
usePlanB: planB,
autoSubscribe: opts?.autoSubscribe,
});
return res as JoinResponse;
Expand All @@ -130,9 +130,6 @@ export class WSSignalClient {
if (opts.reconnect) {
params += '&reconnect=1';
}
if (opts.usePlanB) {
params += '&planb=1';
}
if (opts.autoSubscribe !== undefined) {
params += `&auto_subscribe=${opts.autoSubscribe ? '1' : '0'}`;
}
Expand Down Expand Up @@ -322,6 +319,10 @@ export class WSSignalClient {
if (this.onLeave) {
this.onLeave();
}
} else if (msg.mute) {
if (this.onRemoteMuteChanged) {
this.onRemoteMuteChanged(msg.mute.sid, msg.mute.muted);
}
} else {
log.warn('unsupported message', msg);
}
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DataPacket_Kind, VideoQuality } from './proto/livekit_rtc';
import { DataPacket_Kind } from './proto/livekit_models';
import { VideoQuality } from './proto/livekit_rtc';
import LocalParticipant from './room/participant/LocalParticipant';
import Participant from './room/participant/Participant';
import RemoteParticipant from './room/participant/RemoteParticipant';
Expand Down
Loading

0 comments on commit 96305c0

Please sign in to comment.