@livekit/rtc-node
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -18,2 +18,18 @@ "use strict"; | ||
super(); | ||
this.onEvent = (ev) => { | ||
if (ev.message.case != 'audioStreamEvent' || | ||
ev.message.value.streamHandle != this.ffiHandle.handle) { | ||
return; | ||
} | ||
let streamEvent = ev.message.value.message; | ||
switch (streamEvent.case) { | ||
case 'frameReceived': | ||
let frame = audio_frame_1.AudioFrame.fromOwnedInfo(streamEvent.value.frame); | ||
this.emit(AudioStreamEvent.FrameReceived, frame); | ||
break; | ||
case 'eos': | ||
ffi_client_1.FfiClient.instance.off(ffi_client_1.FfiClientEvent.FfiEvent, this.onEvent); | ||
break; | ||
} | ||
}; | ||
this.track = track; | ||
@@ -34,18 +50,2 @@ let req = new audio_frame_pb_1.NewAudioStreamRequest({ | ||
} | ||
onEvent(ev) { | ||
if (ev.message.case != 'audioStreamEvent' || | ||
ev.message.value.streamHandle != this.ffiHandle.handle) { | ||
return; | ||
} | ||
let streamEvent = ev.message.value.message; | ||
switch (streamEvent.case) { | ||
case 'frameReceived': | ||
let frame = audio_frame_1.AudioFrame.fromOwnedInfo(streamEvent.value.frame); | ||
this.emit(AudioStreamEvent.FrameReceived, frame); | ||
break; | ||
case 'eos': | ||
ffi_client_1.FfiClient.instance.off(ffi_client_1.FfiClientEvent.FfiEvent, this.onEvent); | ||
break; | ||
} | ||
} | ||
close() { | ||
@@ -52,0 +52,0 @@ this.ffiHandle.dispose(); |
import TypedEmitter from 'typed-emitter'; | ||
import { FfiEvent } from './proto/ffi_pb'; | ||
import { LocalParticipant, Participant, RemoteParticipant } from './participant'; | ||
@@ -37,3 +36,3 @@ import { ConnectionQuality, ConnectionState, ContinualGatheringPolicy, DataPacketKind, IceServer, IceTransportType } from './proto/room_pb'; | ||
disconnect(): Promise<void>; | ||
onFfiEvent(ffiEvent: FfiEvent): void; | ||
private onFfiEvent; | ||
private retrieveParticipant; | ||
@@ -40,0 +39,0 @@ private createRemoteParticipant; |
264
dist/room.js
@@ -31,2 +31,134 @@ "use strict"; | ||
this.participants = new Map(); | ||
this.onFfiEvent = (ffiEvent) => { | ||
if (ffiEvent.message.case != 'roomEvent' || | ||
ffiEvent.message.value.roomHandle != this.ffiHandle.handle) { | ||
return; | ||
} | ||
let ev = ffiEvent.message.value.message; | ||
if (ev.case == 'participantConnected') { | ||
let participant = this.createRemoteParticipant(ev.value.info); | ||
this.participants.set(participant.sid, participant); | ||
this.emit(RoomEvent.ParticipantConnected, participant); | ||
} | ||
else if (ev.case == 'participantDisconnected') { | ||
let participant = this.participants.get(ev.value.participantSid); | ||
this.participants.delete(ev.value.participantSid); | ||
this.emit(RoomEvent.ParticipantDisconnected, participant); | ||
} | ||
else if (ev.case == 'localTrackPublished') { | ||
let publication = this.localParticipant.tracks.get(ev.value.trackSid); | ||
this.emit(RoomEvent.LocalTrackPublished, publication, publication.track); | ||
} | ||
else if (ev.case == 'localTrackUnpublished') { | ||
let publication = this.localParticipant.tracks.get(ev.value.publicationSid); | ||
this.localParticipant.tracks.delete(ev.value.publicationSid); | ||
this.emit(RoomEvent.LocalTrackUnpublished, publication); | ||
} | ||
else if (ev.case == 'trackPublished') { | ||
let participant = this.participants.get(ev.value.participantSid); | ||
let publication = new track_publication_1.RemoteTrackPublication(ev.value.publication); | ||
participant.tracks.set(publication.sid, publication); | ||
this.emit(RoomEvent.TrackPublished, publication, participant); | ||
} | ||
else if (ev.case == 'trackUnpublished') { | ||
let participant = this.participants.get(ev.value.participantSid); | ||
let publication = participant.tracks.get(ev.value.publicationSid); | ||
participant.tracks.delete(ev.value.publicationSid); | ||
this.emit(RoomEvent.TrackUnpublished, publication, participant); | ||
} | ||
else if (ev.case == 'trackSubscribed') { | ||
let ownedTrack = ev.value.track; | ||
let participant = this.participants.get(ev.value.participantSid); | ||
let publication = participant.tracks.get(ownedTrack.info.sid); | ||
publication.subscribed = true; | ||
if (ownedTrack.info.kind == track_pb_1.TrackKind.KIND_VIDEO) { | ||
publication.track = new track_1.RemoteVideoTrack(ownedTrack); | ||
} | ||
else if (ownedTrack.info.kind == track_pb_1.TrackKind.KIND_AUDIO) { | ||
publication.track = new track_1.RemoteAudioTrack(ownedTrack); | ||
} | ||
this.emit(RoomEvent.TrackSubscribed, publication.track, publication, participant); | ||
} | ||
else if (ev.case == 'trackUnsubscribed') { | ||
let participant = this.participants.get(ev.value.participantSid); | ||
let publication = participant.tracks.get(ev.value.trackSid); | ||
publication.track = undefined; | ||
publication.subscribed = false; | ||
this.emit(RoomEvent.TrackUnsubscribed, publication.track, publication, participant); | ||
} | ||
else if (ev.case == 'trackSubscriptionFailed') { | ||
let participant = this.participants.get(ev.value.participantSid); | ||
this.emit(RoomEvent.TrackSubscriptionFailed, participant, ev.value.trackSid, ev.value.error); | ||
} | ||
else if (ev.case == 'trackMuted') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
let publication = participant.tracks.get(ev.value.trackSid); | ||
publication.info.muted = true; | ||
if (publication.track) { | ||
publication.track.info.muted = true; | ||
} | ||
this.emit(RoomEvent.TrackMuted, participant, publication); | ||
} | ||
else if (ev.case == 'trackUnmuted') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
let publication = participant.tracks.get(ev.value.trackSid); | ||
publication.info.muted = false; | ||
if (publication.track) { | ||
publication.track.info.muted = false; | ||
} | ||
this.emit(RoomEvent.TrackUnmuted, participant, publication); | ||
} | ||
else if (ev.case == 'activeSpeakersChanged') { | ||
let activeSpeakers = ev.value.participantSids.map((sid) => this.participants.get(sid)); | ||
this.emit(RoomEvent.ActiveSpeakersChanged, activeSpeakers); | ||
} | ||
else if (ev.case == 'roomMetadataChanged') { | ||
let oldMetadata = this.info.metadata; | ||
this.info.metadata = ev.value.metadata; | ||
this.emit(RoomEvent.RoomMetadataChanged, oldMetadata, this.info.metadata); | ||
} | ||
else if (ev.case == 'participantMetadataChanged') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
let oldMetadata = participant.metadata; | ||
participant.info.metadata = ev.value.metadata; | ||
this.emit(RoomEvent.ParticipantMetadataChanged, participant, oldMetadata, participant.metadata); | ||
} | ||
else if (ev.case == 'participantNameChanged') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
let oldName = participant.name; | ||
participant.info.name = ev.value.name; | ||
this.emit(RoomEvent.ParticipantNameChanged, participant, oldName, participant.name); | ||
} | ||
else if (ev.case == 'connectionQualityChanged') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
this.emit(RoomEvent.ConnectionQualityChanged, participant, ev.value.quality); | ||
} | ||
else if (ev.case == 'dataReceived') { | ||
// Can be undefined if the data is sent from a Server SDK | ||
let participant = this.participants.get(ev.value.participantSid); | ||
let info = ev.value.data; | ||
let buffer = ffi_client_1.FfiClient.instance.copyBuffer(info.data.dataPtr, Number(info.data.dataLen)); | ||
new ffi_client_1.FfiHandle(info.handle.id).dispose(); | ||
this.emit(RoomEvent.DataReceived, buffer, ev.value.kind, participant); | ||
} | ||
else if (ev.case == 'e2eeStateChanged') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
this.emit(RoomEvent.E2EEStateChanged, participant, ev.value.state); | ||
} | ||
else if (ev.case == 'connectionStateChanged') { | ||
this.connection_state = ev.value.state; | ||
this.emit(RoomEvent.ConenctionStateChanged, this.connection_state); | ||
/*} else if (ev.case == 'connected') { | ||
this.emit(RoomEvent.Connected);*/ | ||
} | ||
else if (ev.case == 'disconnected') { | ||
this.emit(RoomEvent.Disconnected); | ||
} | ||
else if (ev.case == 'reconnecting') { | ||
this.emit(RoomEvent.Reconnecting); | ||
} | ||
else if (ev.case == 'reconnected') { | ||
this.emit(RoomEvent.Reconnected); | ||
} | ||
}; | ||
ffi_client_1.FfiClient.instance.addListener(ffi_client_1.FfiClientEvent.FfiEvent, this.onFfiEvent); | ||
@@ -104,134 +236,2 @@ } | ||
} | ||
onFfiEvent(ffiEvent) { | ||
if (ffiEvent.message.case != 'roomEvent' || | ||
ffiEvent.message.value.roomHandle != this.ffiHandle.handle) { | ||
return; | ||
} | ||
let ev = ffiEvent.message.value.message; | ||
if (ev.case == 'participantConnected') { | ||
let participant = this.createRemoteParticipant(ev.value.info); | ||
this.participants.set(participant.sid, participant); | ||
this.emit(RoomEvent.ParticipantConnected, participant); | ||
} | ||
else if (ev.case == 'participantDisconnected') { | ||
let participant = this.participants.get(ev.value.participantSid); | ||
this.participants.delete(ev.value.participantSid); | ||
this.emit(RoomEvent.ParticipantDisconnected, participant); | ||
} | ||
else if (ev.case == 'localTrackPublished') { | ||
let publication = this.localParticipant.tracks.get(ev.value.trackSid); | ||
this.emit(RoomEvent.LocalTrackPublished, publication, publication.track); | ||
} | ||
else if (ev.case == 'localTrackUnpublished') { | ||
let publication = this.localParticipant.tracks.get(ev.value.publicationSid); | ||
this.localParticipant.tracks.delete(ev.value.publicationSid); | ||
this.emit(RoomEvent.LocalTrackUnpublished, publication); | ||
} | ||
else if (ev.case == 'trackPublished') { | ||
let participant = this.participants.get(ev.value.participantSid); | ||
let publication = new track_publication_1.RemoteTrackPublication(ev.value.publication); | ||
participant.tracks.set(publication.sid, publication); | ||
this.emit(RoomEvent.TrackPublished, publication, participant); | ||
} | ||
else if (ev.case == 'trackUnpublished') { | ||
let participant = this.participants.get(ev.value.participantSid); | ||
let publication = participant.tracks.get(ev.value.publicationSid); | ||
participant.tracks.delete(ev.value.publicationSid); | ||
this.emit(RoomEvent.TrackUnpublished, publication, participant); | ||
} | ||
else if (ev.case == 'trackSubscribed') { | ||
let ownedTrack = ev.value.track; | ||
let participant = this.participants.get(ev.value.participantSid); | ||
let publication = participant.tracks.get(ownedTrack.info.sid); | ||
publication.subscribed = true; | ||
if (ownedTrack.info.kind == track_pb_1.TrackKind.KIND_VIDEO) { | ||
publication.track = new track_1.RemoteVideoTrack(ownedTrack); | ||
} | ||
else if (ownedTrack.info.kind == track_pb_1.TrackKind.KIND_AUDIO) { | ||
publication.track = new track_1.RemoteAudioTrack(ownedTrack); | ||
} | ||
this.emit(RoomEvent.TrackSubscribed, publication.track, publication, participant); | ||
} | ||
else if (ev.case == 'trackUnsubscribed') { | ||
let participant = this.participants.get(ev.value.participantSid); | ||
let publication = participant.tracks.get(ev.value.trackSid); | ||
publication.track = undefined; | ||
publication.subscribed = false; | ||
this.emit(RoomEvent.TrackUnsubscribed, publication.track, publication, participant); | ||
} | ||
else if (ev.case == 'trackSubscriptionFailed') { | ||
let participant = this.participants.get(ev.value.participantSid); | ||
this.emit(RoomEvent.TrackSubscriptionFailed, participant, ev.value.trackSid, ev.value.error); | ||
} | ||
else if (ev.case == 'trackMuted') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
let publication = participant.tracks.get(ev.value.trackSid); | ||
publication.info.muted = true; | ||
if (publication.track) { | ||
publication.track.info.muted = true; | ||
} | ||
this.emit(RoomEvent.TrackMuted, participant, publication); | ||
} | ||
else if (ev.case == 'trackUnmuted') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
let publication = participant.tracks.get(ev.value.trackSid); | ||
publication.info.muted = false; | ||
if (publication.track) { | ||
publication.track.info.muted = false; | ||
} | ||
this.emit(RoomEvent.TrackUnmuted, participant, publication); | ||
} | ||
else if (ev.case == 'activeSpeakersChanged') { | ||
let activeSpeakers = ev.value.participantSids.map((sid) => this.participants.get(sid)); | ||
this.emit(RoomEvent.ActiveSpeakersChanged, activeSpeakers); | ||
} | ||
else if (ev.case == 'roomMetadataChanged') { | ||
let oldMetadata = this.info.metadata; | ||
this.info.metadata = ev.value.metadata; | ||
this.emit(RoomEvent.RoomMetadataChanged, oldMetadata, this.info.metadata); | ||
} | ||
else if (ev.case == 'participantMetadataChanged') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
let oldMetadata = participant.metadata; | ||
participant.info.metadata = ev.value.metadata; | ||
this.emit(RoomEvent.ParticipantMetadataChanged, participant, oldMetadata, participant.metadata); | ||
} | ||
else if (ev.case == 'participantNameChanged') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
let oldName = participant.name; | ||
participant.info.name = ev.value.name; | ||
this.emit(RoomEvent.ParticipantNameChanged, participant, oldName, participant.name); | ||
} | ||
else if (ev.case == 'connectionQualityChanged') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
this.emit(RoomEvent.ConnectionQualityChanged, participant, ev.value.quality); | ||
} | ||
else if (ev.case == 'dataReceived') { | ||
// Can be undefined if the data is sent from a Server SDK | ||
let participant = this.participants.get(ev.value.participantSid); | ||
let info = ev.value.data; | ||
let buffer = ffi_client_1.FfiClient.instance.copyBuffer(info.data.dataPtr, Number(info.data.dataLen)); | ||
new ffi_client_1.FfiHandle(info.handle.id).dispose(); | ||
this.emit(RoomEvent.DataReceived, buffer, ev.value.kind, participant); | ||
} | ||
else if (ev.case == 'e2eeStateChanged') { | ||
let participant = this.retrieveParticipant(ev.value.participantSid); | ||
this.emit(RoomEvent.E2EEStateChanged, participant, ev.value.state); | ||
} | ||
else if (ev.case == 'connectionStateChanged') { | ||
this.connection_state = ev.value.state; | ||
this.emit(RoomEvent.ConenctionStateChanged, this.connection_state); | ||
/*} else if (ev.case == 'connected') { | ||
this.emit(RoomEvent.Connected);*/ | ||
} | ||
else if (ev.case == 'disconnected') { | ||
this.emit(RoomEvent.Disconnected); | ||
} | ||
else if (ev.case == 'reconnecting') { | ||
this.emit(RoomEvent.Reconnecting); | ||
} | ||
else if (ev.case == 'reconnected') { | ||
this.emit(RoomEvent.Reconnected); | ||
} | ||
} | ||
retrieveParticipant(sid) { | ||
@@ -238,0 +238,0 @@ if (this.localParticipant.sid == sid) { |
@@ -18,2 +18,20 @@ "use strict"; | ||
super(); | ||
this.onEvent = (ev) => { | ||
if (ev.message.case != 'videoStreamEvent' || | ||
ev.message.value.streamHandle != this.ffiHandle.handle) { | ||
return; | ||
} | ||
let streamEvent = ev.message.value.message; | ||
switch (streamEvent.case) { | ||
case 'frameReceived': | ||
let frameInfo = streamEvent.value.frame; | ||
let buffer = video_frame_1.VideoFrameBuffer.fromOwnedInfo(streamEvent.value.buffer); | ||
let frame = new video_frame_1.VideoFrame(Number(frameInfo.timestampUs), frameInfo.rotation, buffer); | ||
this.emit(VideoStreamEvent.FrameReceived, frame); | ||
break; | ||
case 'eos': | ||
ffi_client_1.FfiClient.instance.off(ffi_client_1.FfiClientEvent.FfiEvent, this.onEvent); | ||
break; | ||
} | ||
}; | ||
this.track = track; | ||
@@ -34,20 +52,2 @@ let req = new video_frame_pb_1.NewVideoStreamRequest({ | ||
} | ||
onEvent(ev) { | ||
if (ev.message.case != 'videoStreamEvent' || | ||
ev.message.value.streamHandle != this.ffiHandle.handle) { | ||
return; | ||
} | ||
let streamEvent = ev.message.value.message; | ||
switch (streamEvent.case) { | ||
case 'frameReceived': | ||
let frameInfo = streamEvent.value.frame; | ||
let buffer = video_frame_1.VideoFrameBuffer.fromOwnedInfo(streamEvent.value.buffer); | ||
let frame = new video_frame_1.VideoFrame(Number(frameInfo.timestampUs), frameInfo.rotation, buffer); | ||
this.emit(VideoStreamEvent.FrameReceived, frame); | ||
break; | ||
case 'eos': | ||
ffi_client_1.FfiClient.instance.off(ffi_client_1.FfiClientEvent.FfiEvent, this.onEvent); | ||
break; | ||
} | ||
} | ||
close() { | ||
@@ -54,0 +54,0 @@ this.ffiHandle.dispose(); |
@@ -5,3 +5,3 @@ { | ||
"license": "Apache-2.0", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "dist/index.js", | ||
@@ -52,8 +52,8 @@ "types": "dist/index.d.ts", | ||
"optionalDependencies": { | ||
"@livekit/rtc-node-darwin-arm64": "0.0.5", | ||
"@livekit/rtc-node-darwin-x64": "0.0.5", | ||
"@livekit/rtc-node-linux-arm64-gnu": "0.0.5", | ||
"@livekit/rtc-node-linux-x64-gnu": "0.0.5", | ||
"@livekit/rtc-node-win32-x64-msvc": "0.0.5" | ||
"@livekit/rtc-node-darwin-arm64": "0.0.6", | ||
"@livekit/rtc-node-darwin-x64": "0.0.6", | ||
"@livekit/rtc-node-linux-arm64-gnu": "0.0.6", | ||
"@livekit/rtc-node-linux-x64-gnu": "0.0.6", | ||
"@livekit/rtc-node-win32-x64-msvc": "0.0.6" | ||
} | ||
} |
@@ -51,3 +51,3 @@ import { AudioFrame } from './audio_frame'; | ||
private onEvent(ev: FfiEvent) { | ||
private onEvent = (ev: FfiEvent) => { | ||
if ( | ||
@@ -54,0 +54,0 @@ ev.message.case != 'audioStreamEvent' || |
@@ -159,3 +159,3 @@ import { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client'; | ||
onFfiEvent(ffiEvent: FfiEvent) { | ||
private onFfiEvent = (ffiEvent: FfiEvent) => { | ||
if ( | ||
@@ -162,0 +162,0 @@ ffiEvent.message.case != 'roomEvent' || |
@@ -51,3 +51,3 @@ import { FfiClient, FfiClientEvent, FfiEvent, FfiHandle, FfiRequest } from './ffi_client'; | ||
private onEvent(ev: FfiEvent) { | ||
private onEvent = (ev: FfiEvent) => { | ||
if ( | ||
@@ -54,0 +54,0 @@ ev.message.case != 'videoStreamEvent' || |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1708436
29160