-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added examples for RoomCallback usage (#599)
also changed: - moved data defs to data.go - added a few additional DisconnectReason
- Loading branch information
Showing
4 changed files
with
108 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package lksdk_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/livekit/protocol/livekit" | ||
lksdk "github.com/livekit/server-sdk-go/v2" | ||
) | ||
|
||
// ExampleRoomCallback demonstrates usage of RoomCallback to handle various room events | ||
func ExampleRoomCallback() { | ||
// Create a new callback handler | ||
cb := lksdk.NewRoomCallback() | ||
|
||
// Handle data packets received from other participants | ||
cb.OnDataPacket = func(data lksdk.DataPacket, params lksdk.DataReceiveParams) { | ||
// handle DTMF | ||
switch val := data.(type) { | ||
case *livekit.SipDTMF: | ||
fmt.Printf("Received DTMF from %s: %s (%d)\n", params.SenderIdentity, val.Digit, val.Code) | ||
case *lksdk.UserDataPacket: | ||
fmt.Printf("Received user data from %s: %s\n", params.SenderIdentity, string(val.Payload)) | ||
} | ||
} | ||
|
||
// Handle participant metadata changes | ||
cb.OnAttributesChanged = func(changed map[string]string, p lksdk.Participant) { | ||
fmt.Printf("Participant %s attributes changed: %v\n", p.Identity(), changed) | ||
} | ||
|
||
// Handle when current participant becomes disconnected | ||
cb.OnDisconnectedWithReason = func(reason lksdk.DisconnectionReason) { | ||
fmt.Printf("Disconnected from room: %s\n", reason) | ||
} | ||
|
||
// Create a new room with the callback | ||
room := lksdk.NewRoom(cb) | ||
room.JoinWithToken("wss://myproject.livekit.cloud", "my-token") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters