-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add spaces high level audio methods (#993)
* feat(spaces): add high level audio methods * fix: socket url fix (#995) * feat(spaces-highlevel-audio-methods): add media function in Spaces class --------- Co-authored-by: Mohammed S <[email protected]>
- Loading branch information
1 parent
2330355
commit c26e62e
Showing
4 changed files
with
170 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { SPACE_INVITE_ROLES } from '../payloads/constants'; | ||
import { SpaceInfoDTO } from '../types'; | ||
import Space from './Space'; | ||
import { ChatUpdateSpaceType } from './update'; | ||
|
||
export class SpaceV2 { | ||
private spaceV1Instance: Space; | ||
private spaceInfo: SpaceInfoDTO; | ||
|
||
constructor({ | ||
spaceV1Instance, | ||
spaceInfo, | ||
}: { | ||
spaceV1Instance: Space; | ||
spaceInfo: SpaceInfoDTO; | ||
}) { | ||
this.spaceV1Instance = spaceV1Instance; | ||
this.spaceInfo = spaceInfo; | ||
} | ||
|
||
async activateUserAudio() { | ||
await this.spaceV1Instance.createAudioStream(); | ||
} | ||
|
||
async start() { | ||
await this.spaceV1Instance.start(); | ||
} | ||
|
||
async join() { | ||
await this.spaceV1Instance.join(); | ||
} | ||
|
||
async update(updateSpaceOptions: ChatUpdateSpaceType) { | ||
await this.spaceV1Instance.update(updateSpaceOptions); | ||
} | ||
|
||
async leave() { | ||
await this.spaceV1Instance.leave(); | ||
} | ||
|
||
async stop() { | ||
await this.spaceV1Instance.stop(); | ||
} | ||
|
||
async requestForMic() { | ||
await this.spaceV1Instance.requestToBePromoted({ | ||
role: SPACE_INVITE_ROLES.SPEAKER, | ||
promotorAddress: this.spaceInfo.spaceCreator, | ||
}); | ||
} | ||
|
||
async acceptMicRequest({ | ||
address, | ||
signal, | ||
}: { | ||
address: string; | ||
signal: any; | ||
}) { | ||
await this.spaceV1Instance.acceptPromotionRequest({ | ||
promoteeAddress: address, | ||
spaceId: this.spaceInfo.spaceId, | ||
role: SPACE_INVITE_ROLES.SPEAKER, | ||
signalData: signal, | ||
}); | ||
} | ||
|
||
async rejectMicRequest({ address }: { address: string }) { | ||
await this.spaceV1Instance.rejectPromotionRequest({ | ||
promoteeAddress: address, | ||
}); | ||
} | ||
|
||
async inviteToPromote({ address }: { address: string }) { | ||
await this.spaceV1Instance.inviteToPromote({ | ||
inviteeAddress: address, | ||
role: SPACE_INVITE_ROLES.SPEAKER, | ||
}); | ||
} | ||
|
||
async acceptPromotionInvite({ signal }: { signal: any }) { | ||
await this.spaceV1Instance.acceptPromotionInvite({ | ||
invitorAddress: this.spaceInfo.spaceCreator, | ||
spaceId: this.spaceInfo.spaceId, | ||
signalData: signal, | ||
}); | ||
} | ||
|
||
async rejectPromotionInvite() { | ||
await this.spaceV1Instance.rejectPromotionInvite({ | ||
invitorAddress: this.spaceInfo.spaceCreator, | ||
}); | ||
} | ||
|
||
media({ video, audio }: { video?: boolean; audio?: boolean }) { | ||
if (typeof video === 'boolean') { | ||
this.spaceV1Instance.enableVideo({ state: video }); | ||
} | ||
|
||
if (typeof audio === 'boolean') { | ||
this.spaceV1Instance.enableAudio({ state: audio }); | ||
} | ||
} | ||
} |