Skip to main content

OdinRoom

public class OdinRoom: Hashable, ObservableObject

Class to handle ODIN rooms.

A room is the virtual space where clients can communicate with each other.

Properties

roomHandle

public internal(set) var roomHandle: OdinRoomHandle

The underlying room handle to interact with.

ownPeer

public let ownPeer: OdinPeer = .init()

An instance of your own peer in the room.

gateway

public private(set) var gateway: String = ""

The gateway URL used for authentication.

audioAutopilot

public private(set) var audioAutopilot: OdinAudioAutopilotMode = .room

Indicates how and if medias will be added to the capture/playback mix automatically.

audioNode

public internal(set) var audioNode: AVAudioSourceNode!

The underlying object that receives mixed audio data from remote medias in the room.

audioConfig

public private(set) var audioConfig: OdinApmConfig = .init(
voice_activity_detection: true,
voice_activity_detection_attack_probability: 0.9,
voice_activity_detection_release_probability: 0.8,
volume_gate: false,
volume_gate_attack_loudness: -30,
volume_gate_release_loudness: -40,
echo_canceller: false,
high_pass_filter: false,
pre_amplifier: false,
noise_suppression_level: OdinNoiseSuppressionLevel_Moderate,
transient_suppressor: false
)

The audio processing module settings of the room.

id

@Published public private(set) var id: String = ""

The name of the room.

customer

@Published public private(set) var customer: String = ""

The identifier of the customer the room is assigned to.

userData

@Published public private(set) var userData: [UInt8] = []

A byte array with arbitrary user data attached to the room.

connectionStatus

@Published public private(set) var connectionStatus = (
state: OdinRoomConnectionState_Disconnected,
reason: OdinRoomConnectionStateChangeReason_ClientRequested
)

A tuple with current connection status of the room including a reason identifier for the last update.

peers

@Published public private(set) var peers: [UInt64: OdinPeer] = [:]

An array of current peers in the room.

medias

@Published public private(set) var medias: [OdinMediaStreamHandle: OdinMedia] = [:]

An array of current medias in the room.

delegate

public weak var delegate: OdinRoomDelegate?

An optional delegate with custom event callbacks.

remotePeers

public var remotePeers: [UInt64: OdinPeer]

An array of current remote peers in the room.

localMedias

public var localMedias: [OdinMediaStreamHandle: OdinMedia]

An array of current local medias in the room, which can be used for capture.

remoteMedias

public var remoteMedias: [OdinMediaStreamHandle: OdinMedia]

An array of current remote medias in the room, which can be used for playback.

isConnected

public var isConnected: Bool

Indicates wether or not the room handle is connected.

isConnecting

public var isConnecting: Bool

Indicates wether or not the room handle is connecting.

isDisconnected

public var isDisconnected: Bool

Indicates wether or not the room handle is disconnected.

Methods

init()

public convenience init()

Initializes a new room instance.

init(gateway:)

public init(gateway: String) throws

Initializes a new room instance using a custom gateway URL.

deinit

deinit

Destroys the room handle and closes the connection to the server if needed.

join(token:)

public func join(token: String) throws -> UInt64

Joins a room on an ODIN server and returns the ID of your own peer on success. This function takes a signed room token obtained externally that authorizes the client to establish the connection.

join(token:)

public func join(token: OdinToken) throws -> UInt64

Joins a room on an ODIN server and returns the ID of your own peer on success. This function takes a signed room token obtained externally that authorizes the client to establish the connection.

leave()

public func leave() throws

Leaves the room and closes the connection to the server if needed.

updateAudioConfig(_:)

public func updateAudioConfig(_ config: OdinApmConfig) throws

Updates the settings of the audio processing module for the room. This includes everything from noise reduction to smart voice activity detection.

updateGatewayUrl(_:)

public func updateGatewayUrl(_ gateway: String) throws

Updates the gateway URL used for authentication.

setAudioAutopilotMode(_:)

public func setAudioAutopilotMode(_ mode: OdinAudioAutopilotMode) throws

Enables or disables the audio autopilot. This is a simple flag to control whether or not medias in the room will be added to the default capture/playback mix automatically.

updateUserData(userData:target:)

public func updateUserData(userData: [UInt8], target: OdinUserDataTarget) throws

Updates the custom user data for either your own peer or the specified room itself. This data is synced between clients automatically, which allows storing of arbitrary information for each individual peer and even globally for the room if needed.

Note: Use this with target peer before calling OdinRoom.join to set initial peer user data upon connect.

updatePeerUserData(userData:)

public func updatePeerUserData(userData: [UInt8]) throws

Updates the custom user data for your own peer. This data is synced between clients automatically.

Note: Use this before calling OdinRoom.join to set initial peer user data upon connect.

updateRoomUserData(userData:)

public func updateRoomUserData(userData: [UInt8]) throws

Updates the custom user data for the current room. This data is synced between clients automatically.

updatePosition(x:y:)

public func updatePosition(x: Float, y: Float) throws

Updates the two-dimensional position of your own peer. The server will use the specified coordinates for each peer in the same room to apply automatic culling based on unit circles with a radius of 1.0. This is ideal for any scenario, where you want to put a large numbers of peers into the same room and make them only 'see' each other while being in proximity. Additionally, you can use setPositionScale to adjust the distance multiplier for position updates if needed.

Note: Use this before calling OdinRoom.join to set the initial peer position upon connect.

setPositionScale(scale:)

public func setPositionScale(scale: Float) throws

Sets the scaling used for all coordinates passed to updatePosition. This allows adapting to the individual needs of your game coorinate system if necessary. Only peers within a unit circle with a radius of 1.0 are able to 'see' each other. When changing the position of a peer, the position must be scaled such as that the maximum distance is one or less. The scaling can be done either manually or by setting the multiplicative scale here.

Note: Please make sure that all of your client apps use the same scaling.

addMedia(type:)

public func addMedia(type: OdinMediaStreamType) throws -> OdinMediaStreamHandle

Creates a new input stream of the specified type, adds it to the room and returns the media ID on success.

addMedia(audioConfig:)

public func addMedia(audioConfig: OdinAudioStreamConfig) throws -> OdinMediaStreamHandle

Creates new audio input stream using the specified config, adds it to the room and returns the media ID on success. The new audio media can be used to transmit audio samples captured from a local microphone.

removeMedia(streamHandle:)

public func removeMedia(streamHandle: OdinMediaStreamHandle) throws

Removes the media instance matching the specified ID from the room and destroys it.

removeMedia(media:)

public func removeMedia(media: OdinMedia) throws

Removes the specified media instance from the room and destroys it.

sendMessage(data:targetIds:)

public func sendMessage(data: [UInt8], targetIds: [UInt64] = []) throws

Sends a message with arbitrary data to all other peers in the same room. Optionally, you can provide a list of target IDs to send the message to specific peers only.

hash(into:)

public func hash(into hasher: inout Hasher)

Hashes the essential components of the room by feeding them into the given hasher.

==(_:_:)

public static func ==(lhs: OdinRoom, rhs: OdinRoom) -> Bool

Returns a value indicating whether two type-erased hashable instances wrap the same room.