在Agora Web SDK中添加声音效果

发布于 2025-01-23 17:36:09 字数 1453 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷遇一生 2025-01-30 17:36:09

假设您是最新版本的 agoraappbuilder core(2.1.0)

是您可以实现用例的方法

用户加入,用户disconnect

在应用程序中导航到{app-name}/src/pages/videocall.tsx

导航到您的<<<代码> propsprovider 组件。

它可能看起来像这样,

<PropsProvider
    value={{
        rtcProps: {
            ...rtcProps,
            callActive,
        },
        callbacks, // --> callbacks for events
        ...restProps
}}>

寻找回调 props,
回调 props采用对象类型:

export interface CallbacksInterface {    
  UserJoined: () => {};
  UserOffline: () => {};
  ...otherCallbacks

如果要注册用户jojo的回调或离线(断开连接),则可以将回调传递到您的propsprovider

const playSound = () => {
    let src ='http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/explosion.mp3';
    let audio = new Audio(src);
    audio.play();
}

<PropsProvider
    value={{
        .
        .
        callbacks= {
              UserOffline: () =>{
                  console.log('User offline')
                  playSound()
              },
              UserJoined: () => {
                  console.log('User Joined')
                  playSound()
              }
            .
        }
        .
    }}
}}>

与接收到的消息相似,您可以使用事件对象。
在您的videocall组件中使用:

const {events} = useContext(ChatContext);

一旦您访问事件对象,请注册您的自定义事件publicprivate 消息。

events.on(
  messageChannelType.Public,
  'onPublicMessageReceived',
  (data: any, error: any) => {
    if (!data) return;
    playSound()
  },
);
events.on(
  messageChannelType.Private,
  'onPrivateMessageReceived',
  .
  .
  .

有计划发布较新版本的Agora App Builder Core,新版本将可以访问Agora AppBuilder Extension API。 Extension API将使您无需触摸核心代码库来增强/添加新功能。

Assuming you are on the latest version of AgoraAppBuilder Core (2.1.0)

Here are the ways you can achieve your use cases

user join, user disconnect

In your app navigate to {APP-Name}/src/pages/VideoCall.tsx

Navigate to your PropsProvider component.

It might look something like this,

<PropsProvider
    value={{
        rtcProps: {
            ...rtcProps,
            callActive,
        },
        callbacks, // --> callbacks for events
        ...restProps
}}>

look for the callbacks props,
callbacks props take an object type:

export interface CallbacksInterface {    
  UserJoined: () => {};
  UserOffline: () => {};
  ...otherCallbacks

If you want to register callbacks for userJoined or offline(disconnect), you can pass the callbacks to your PropsProvider

const playSound = () => {
    let src ='http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/explosion.mp3';
    let audio = new Audio(src);
    audio.play();
}

<PropsProvider
    value={{
        .
        .
        callbacks= {
              UserOffline: () =>{
                  console.log('User offline')
                  playSound()
              },
              UserJoined: () => {
                  console.log('User Joined')
                  playSound()
              }
            .
        }
        .
    }}
}}>

Similarly for message received notifications, you can use the events object.
Within your VideoCall component use:

const {events} = useContext(ChatContext);

Once you have access to the events object, register your custom events for handling public and private messages.

events.on(
  messageChannelType.Public,
  'onPublicMessageReceived',
  (data: any, error: any) => {
    if (!data) return;
    playSound()
  },
);
events.on(
  messageChannelType.Private,
  'onPrivateMessageReceived',
  .
  .
  .

There are plans for releasing a newer version of the Agora App Builder Core, with the new release you'll have access to Agora AppBuilder Extension API's. Extension API's will enable to enhance/add newer functionalities to your app without ever touching the core code base.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文