mirror of
https://github.com/thegatesbrowser/godot-multiplayer.git
synced 2025-10-16 02:03:43 -04:00
switch to two voip addon
This commit is contained in:
parent
cf11ceffc4
commit
9ce4caa073
39 changed files with 193 additions and 52 deletions
|
@ -8,18 +8,23 @@ var speak_action: StringName = "speak"
|
|||
|
||||
func _process(_delta: float) -> void:
|
||||
if not Input.is_action_pressed(speak_action) or EditMode.is_enabled:
|
||||
is_speaking = false
|
||||
set_speaking(false)
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if EditMode.is_enabled: return
|
||||
|
||||
if event.is_action_pressed(speak_action):
|
||||
is_speaking = true
|
||||
set_speaking(true)
|
||||
|
||||
if event.is_action_released(speak_action):
|
||||
is_speaking = false
|
||||
set_speaking(false)
|
||||
|
||||
|
||||
func set_speaking(speaking: bool) -> void:
|
||||
if speaking == is_speaking: return
|
||||
is_speaking = speaking
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
is_speaking = false
|
||||
set_speaking(false)
|
||||
|
|
|
@ -3,7 +3,7 @@ extends Node
|
|||
@export var user_scn: PackedScene
|
||||
@export var player_spawner: PlayerSpawner
|
||||
|
||||
var mic_capture: VOIPInputCapture
|
||||
var opuschunked: AudioEffectOpusChunked
|
||||
var users = {} # {Peer ID: VoipUser}
|
||||
|
||||
|
||||
|
@ -15,8 +15,7 @@ func _ready() -> void:
|
|||
player_spawner.player_spawned.connect(player_spawned)
|
||||
|
||||
var mic_bus = AudioServer.get_bus_index("Record")
|
||||
mic_capture = AudioServer.get_bus_effect(mic_bus, 0)
|
||||
mic_capture.packet_ready.connect(voice_packet_ready)
|
||||
opuschunked = AudioServer.get_bus_effect(mic_bus, 0)
|
||||
|
||||
|
||||
func peer_connected(id: int) -> void:
|
||||
|
@ -44,22 +43,22 @@ func player_spawned(id: int, player: Player) -> void:
|
|||
if users.has(id): users[id].set_anchor(player)
|
||||
|
||||
|
||||
func voice_packet_ready(packet: PackedByteArray) -> void:
|
||||
if not Microphone.is_speaking: return
|
||||
if Connection.is_peer_connected:
|
||||
rpc("voice_packet_received", packet)
|
||||
|
||||
|
||||
@rpc("any_peer", "call_remote", "unreliable_ordered", 1)
|
||||
func voice_packet_received(packet: PackedByteArray) -> void:
|
||||
if multiplayer.is_server(): return
|
||||
|
||||
var sender_id = multiplayer.get_remote_sender_id()
|
||||
users[sender_id].stream.push_packet(packet)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not Connection.is_peer_connected: return
|
||||
if multiplayer.is_server(): return
|
||||
|
||||
mic_capture.send_test_packets()
|
||||
var prepend = PackedByteArray()
|
||||
while opuschunked.chunk_available():
|
||||
var opusdata: PackedByteArray = opuschunked.read_opus_packet(prepend)
|
||||
opuschunked.drop_chunk()
|
||||
|
||||
if not Microphone.is_speaking: continue
|
||||
rpc("opus_data_received", opusdata)
|
||||
|
||||
|
||||
@rpc("any_peer", "call_remote", "unreliable_ordered", 1)
|
||||
func opus_data_received(opusdata: PackedByteArray) -> void:
|
||||
if multiplayer.is_server(): return
|
||||
|
||||
var sender_id = multiplayer.get_remote_sender_id()
|
||||
users[sender_id].opuspacketsbuffer.append(opusdata)
|
||||
|
|
|
@ -8,9 +8,18 @@ class_name VoipUser
|
|||
var user_id: int
|
||||
var anchor: Node3D
|
||||
|
||||
var audiostreamopuschunked : AudioStreamOpusChunked
|
||||
var opuspacketsbuffer: Array[PackedByteArray] = []
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
user_data_events.user_volume_changed.connect(change_volume)
|
||||
audiostreamopuschunked = stream as AudioStreamOpusChunked
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
while audiostreamopuschunked.chunk_space_available() and not opuspacketsbuffer.is_empty():
|
||||
audiostreamopuschunked.push_opus_packet(opuspacketsbuffer.pop_front(), 0, 0)
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
[ext_resource type="Script" path="res://voip/voip_user.gd" id="1_wo4b3"]
|
||||
[ext_resource type="Resource" uid="uid://rclnl7v8k722" path="res://user_data/user_data_events.res" id="2_mt25f"]
|
||||
|
||||
[sub_resource type="AudioStreamVOIP" id="AudioStreamVOIP_mku04"]
|
||||
resource_local_to_scene = true
|
||||
[sub_resource type="AudioStreamOpusChunked" id="AudioStreamOpusChunked_ess21"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_q0foc"]
|
||||
bake_resolution = 1000
|
||||
|
@ -12,7 +11,7 @@ _data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.142241, 0.010989), 0.0, 0.0, 0
|
|||
point_count = 5
|
||||
|
||||
[node name="VoipUser" type="AudioStreamPlayer3D"]
|
||||
stream = SubResource("AudioStreamVOIP_mku04")
|
||||
stream = SubResource("AudioStreamOpusChunked_ess21")
|
||||
attenuation_model = 1
|
||||
volume_db = -12.0
|
||||
unit_size = 15.0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue