kentaro / vrchat_osc

Elixir implementation of the VRChat OpenSoundControl Specification

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

VRChatOSC

Hex.pm Version

VRChatOSC is a library for sending and receiving messages to/from VRChat that supports the OpenSoundControl 1.0 protocol.

This library was forked from ex_osc and made some modifications to support VRChat OSC protocol.

Installation

VRChatOSC requires Elixir v1.14. To use it, add :vrchat_osc to your list of dependencies in mix.exs:

def deps do
  [
    {:vrchat_osc, github: "kentaro/vrchat_osc", branch: :main}
  ]
end

Usage

Here's an example of using VRChatOSC.OSC to send a message and receives messages to/from VRChat.

defmodule MyConsumer do
  use GenStage

  def init(:ok) do
    {:consumer, nil}
  end

  def handle_events(events, {_, _}, state) do
    events |> Enum.each(&IO.inspect/1)
    {:noreply, [], state}
  end
end

{:ok, osc} = VRChatOSC.OSC.start_link(
  vrchat: [
    ip: {127, 0, 0, 1},
    port: 9000
  ],
  client: [
    port: 9001
  ],
  consumer: [
    module: MyConsumer,
    args: :ok,
    opts: []
  ]
)

VRChatOSC.send_message(
  osc,
  path: "/chatbox/input",
  args: ["Hello, world!", true]
)
Process.sleep(:infinity)

Output:

You can see the message sent to VRChat and the messages received from VRChat.

The message sent to VRChat

%VRChatOSC.OSC.Message{
  path: "/avatar/parameters/scarf_Angle",
  args: [5.154856480658054e-4]
}
%VRChatOSC.OSC.Message{
  path: "/avatar/parameters/scarf_Angle",
  args: [3.2970565371215343e-4]
}
%VRChatOSC.OSC.Message{
  path: "/avatar/parameters/scarf_Angle",
  args: [6.501884781755507e-4]
}
...

Documentation

Full documentation can be found at https://hexdocs.pm/vrchat_osc.

Legal stuff

Copyright © 2023 Kentaro Kuribayashi

Copyright © 2023 Adrian Irving-Beer (the original author of ex_osc)

VRChatOSC is released under the MIT license and is provided with no warranty.

About

Elixir implementation of the VRChat OpenSoundControl Specification

License:MIT License


Languages

Language:Elixir 100.0%