Skip to content

Commit

Permalink
feat: add join as speaker (#705)
Browse files Browse the repository at this point in the history
* feat: add join as speaker

* refactor: add file level comment

* refactor: eOF

* refactor: rm speaker check logic

* fix: getPlain added

* fix: rm updation
  • Loading branch information
arn4b authored Sep 11, 2023
1 parent 53180e6 commit cddc7fa
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/restapi/src/lib/spaceV2/helpers/sendMetaMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @file sendMetaMessage helper function
* This module provides a function for sending metadata-related messages within a live space.
*/

import { send } from '../../chat';
import { MessageType } from '../../constants';
import { EnvOptionsType, LiveSpaceData, SignerType } from '../../types';
import { META_ACTION } from '../../types/messageTypes';

interface ISendMetaMessage extends EnvOptionsType {
liveSpaceData?: LiveSpaceData;
action: META_ACTION;
spaceId: string;
pgpPrivateKey: string;
signer: SignerType;
}

const sendMetaMessage = async ({
liveSpaceData,
action,
spaceId,
pgpPrivateKey,
signer,
env,
}: ISendMetaMessage) => {
await send({
receiverAddress: spaceId,
pgpPrivateKey,
env,
signer,
messageType: MessageType.META,
messageObj: {
content: 'PUSH SPACE V2 META MESSAGE',
action,
info: {
affected: [],
arbitrary: liveSpaceData,
},
},
});
};

export default sendMetaMessage;
28 changes: 28 additions & 0 deletions packages/restapi/src/lib/spaceV2/joinAsSpeaker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @file joinAsSpeaker
* defines a function that allows a user to join a space as a speaker in the SpaceV2 implmentation
*/

import { SpaceV2 } from './SpaceV2';
import sendMetaMessage from './helpers/sendMetaMessage'

import { META_ACTION } from '../types';

export async function joinAsSpeaker(this: SpaceV2) {
try {
// send meta message to host
await sendMetaMessage({
pgpPrivateKey: this.pgpPrivateKey,
env: this.env,
spaceId: this.data.spaceInfo.spaceId,
signer: this.signer,
// TODO: add relevant meta message later
action: META_ACTION.ADD_MEMBER,
});

/* rest logic to be implemented here after host has called the approve/reject call */
} catch (err) {
console.error(`[Push SDK] - API - Error - API ${joinAsSpeaker.name} -: `, err);
throw Error(`[Push SDK] - API - Error - API ${joinAsSpeaker.name} -: ${err}`);
}
};

0 comments on commit cddc7fa

Please sign in to comment.