Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Add update metadata api (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
graszka22 authored Sep 8, 2022
1 parent ec20688 commit a271308
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 3 deletions.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,43 @@ An object containing:
- `quality: ScreencastQuality` - resolution + fps of screencast track, one of: `VGA`, `HD5`, `HD15`, `FHD15`, `FHD30`. Note that quality might be worse than specified due to device capabilities, internet connection etc. Default: `HD15`.
- `screencastMetadata: Metadata` - a map `string -> string` containing screencast track metadata to be sent to the server.

Under the hood the screencast is just given participant's another video track. However for convenience the library creates a fake screencasting participant. The library recognizes a screencast track by `type: "screencasting"` metadata in screencasting video track.
- `updateScreencastTrackMetadata(metatada: Metadata)` - a function that updates screencast track metadata on the server. Arguments:
- `metatada: Metadata` - a map `string -> string` containing screencast track metadata to be sent to the server.

Under the hood the screencast is just given participant's another video track. However for convenience the library creates a fake screencasting participant. The library recognizes a screencast track by `type: "screencasting"` metadata in screencasting video track.

## `usePeerMetadata()`

This hook manages user's metadata. Use it to for example update when user is muted etc.

### Returns

An object containing:

- `updatePeerMetadata(metatada: Metadata)` - a function that updates user's metadata on the server. Arguments:
- `metatada: Metadata` - a map `string -> string` containing user's track metadata to be sent to the server.

## `useVideoTrackMetadata()`

This hook manages video track metadata.

### Returns

An object containing:

- `updateVideoTrackMetadata(metatada: Metadata)` - a function that updates video metadata on the server. Arguments:
- `metatada: Metadata` - a map `string -> string` containing video track metadata to be sent to the server.

## `useAudioTrackMetadata()`

This hook manages audio track metadata.

### Returns

An object containing:

- `updateAudioTrackMetadata(metatada: Metadata)` - a function that updates audio metadata on the server. Arguments:
- `metatada: Metadata` - a map `string -> string` containing audio track metadata to be sent to the server.

## `<VideoRendererView />`

Expand Down
27 changes: 27 additions & 0 deletions android/src/main/java/com/reactnativemembrane/MembraneModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,33 @@ class MembraneModule(reactContext: ReactApplicationContext) :
promise.resolve(getParticipantsAsRNMap())
}

@ReactMethod
fun updatePeerMetadata(metadata: ReadableMap, promise: Promise) {
room?.updatePeerMetadata(metadata.toMetadata())
promise.resolve(null)
}

@ReactMethod
fun updateVideoTrackMetadata(metadata: ReadableMap, promise: Promise) {
val trackId = localVideoTrack?.rtcTrack()?.id() ?: return
room?.updateTrackMetadata(trackId, metadata.toMetadata())
promise.resolve(null)
}

@ReactMethod
fun updateAudioTrackMetadata(metadata: ReadableMap, promise: Promise) {
val trackId = localAudioTrack?.rtcTrack()?.id() ?: return
room?.updateTrackMetadata(trackId, metadata.toMetadata())
promise.resolve(null)
}

@ReactMethod
fun updateScreencastTrackMetadata(metadata: ReadableMap, promise: Promise) {
val trackId = localScreencastTrack?.rtcTrack()?.id() ?: return
room?.updateTrackMetadata(trackId, metadata.toMetadata())
promise.resolve(null)
}

@ReactMethod
fun addListener(eventName: String?) {}

Expand Down
4 changes: 4 additions & 0 deletions ios/Membrane.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ @interface RCT_EXTERN_MODULE(Membrane, RCTEventEmitter <RCTBridgeModule>)
RCT_EXTERN_METHOD(isMicrophoneOn:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(toggleScreencast:(NSDictionary)screencastOptions withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(flipCamera:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(updatePeerMetadata:(NSDictionary)metadata withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(updateVideoTrackMetadata:(NSDictionary)metadata withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(updateAudioTrackMetadata:(NSDictionary)metadata withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(updateScreencastTrackMetadata:(NSDictionary)metadata withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
@end
44 changes: 43 additions & 1 deletion ios/Membrane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class ParticipantVideo: Identifiable, ObservableObject {
}
}

extension LocalAudioTrack{
public func trackId() -> String {
return track.trackId
}
}

@objc(Membrane)
class Membrane: RCTEventEmitter, MembraneRTCDelegate {
var localVideoTrack: LocalVideoTrack?
Expand Down Expand Up @@ -173,7 +179,7 @@ class Membrane: RCTEventEmitter, MembraneRTCDelegate {
var screencastMetadata = (screencastOptions["screencastMetadata"] as? NSDictionary)?.toMetadata() ?? Metadata()
screencastMetadata["type"] = "screensharing"

room.createScreencastTrack(appGroup: appGroupName, videoParameters: videoParameters, metadata: screencastMetadata, onStart: { [weak self] screencastTrack in
self.localScreencastTrack = room.createScreencastTrack(appGroup: appGroupName, videoParameters: videoParameters, metadata: screencastMetadata, onStart: { [weak self] screencastTrack in
guard let self = self else {
DispatchQueue.main.async {
RPSystemBroadcastPickerView.show(for: screencastExtensionBundleId)
Expand Down Expand Up @@ -288,6 +294,42 @@ class Membrane: RCTEventEmitter, MembraneRTCDelegate {
}
resolve(nil)
}

@objc(updatePeerMetadata:withResolver:withRejecter:)
func updatePeerMetadata(metadata:NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
room?.updatePeerMetadata(peerMetadata: metadata.toMetadata())
resolve(nil)
}

@objc(updateVideoTrackMetadata:withResolver:withRejecter:)
func updateVideoTrackMetadata(metadata:NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
guard let room = room, let trackId = localVideoTrack?.trackId() else {
return
}

room.updateTrackMetadata(trackId: trackId, trackMetadata: metadata.toMetadata())
resolve(nil)
}

@objc(updateAudioTrackMetadata:withResolver:withRejecter:)
func updateAudioTrackMetadata(metadata:NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
guard let room = room, let trackId = localAudioTrack?.trackId() else {
return
}

room.updateTrackMetadata(trackId: trackId, trackMetadata: metadata.toMetadata())
resolve(nil)
}

@objc(updateScreencastTrackMetadata:withResolver:withRejecter:)
func updateScreencastTrackMetadata(metadata:NSDictionary, resolve:RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
guard let room = room, let trackId = localScreencastTrack?.trackId() else {
return
}

room.updateTrackMetadata(trackId: trackId, trackMetadata: metadata.toMetadata())
resolve(nil)
}

override func supportedEvents() -> [String]! {
return [
Expand Down
30 changes: 29 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,35 @@ export function useScreencast() {
[]
);

return { isScreencastOn, toggleScreencast };
const updateScreencastTrackMetadata = useCallback(
async (metadata: Metadata) => {
await Membrane.updateScreencastTrackMetadata(metadata);
},
[]
);

return { isScreencastOn, toggleScreencast, updateScreencastTrackMetadata };
}

export function usePeerMetadata() {
const updatePeerMetadata = useCallback(async (metadata: Metadata) => {
await Membrane.updatePeerMetadata(metadata);
}, []);
return { updatePeerMetadata };
}

export function useVideoTrackMetadata() {
const updateVideoTrackMetadata = useCallback(async (metadata: Metadata) => {
await Membrane.updateVideoTrackMetadata(metadata);
}, []);
return { updateVideoTrackMetadata };
}

export function useAudioTrackMetadata() {
const updateAudioTrackMetadata = useCallback(async (metadata: Metadata) => {
await Membrane.updateAudioTrackMetadata(metadata);
}, []);
return { updateAudioTrackMetadata };
}

type VideoRendererProps = {
Expand Down

0 comments on commit a271308

Please sign in to comment.