Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send and receive DTMF in join command. #393

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/lk/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import (
"github.com/pion/webrtc/v3"
"github.com/urfave/cli/v3"

provider2 "github.com/livekit/livekit-cli/pkg/provider"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
lksdk "github.com/livekit/server-sdk-go/v2"

provider2 "github.com/livekit/livekit-cli/pkg/provider"
)

var (
Expand Down
46 changes: 41 additions & 5 deletions cmd/lk/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ var (
"Can be used multiple times to publish multiple files. " +
"Can publish from Unix or TCP socket using the format '<codec>://<socket_name>' or '<codec>://<host:address>' respectively. Valid codecs are \"h264\", \"vp8\", \"opus\"",
},
&cli.StringFlag{
Name: "publish-data",
Usage: "Publish user data to the room.",
},
&cli.StringFlag{
Name: "publish-dtmf",
Usage: "Publish DTMF digits to the room. Character 'w' adds 0.5 sec delay.",
},
&cli.FloatFlag{
Name: "fps",
Usage: "If video files are published, indicates `FPS` of video",
Expand Down Expand Up @@ -737,9 +745,16 @@ func joinRoom(ctx context.Context, cmd *cli.Command) error {
done := make(chan os.Signal, 1)
roomCB := &lksdk.RoomCallback{
ParticipantCallback: lksdk.ParticipantCallback{
OnDataReceived: func(data []byte, params lksdk.DataReceiveParams) {
OnDataPacket: func(p lksdk.DataPacket, params lksdk.DataReceiveParams) {
identity := params.SenderIdentity
logger.Infow("received data", "data", data, "participant", identity)
switch p := p.(type) {
case *lksdk.UserDataPacket:
logger.Infow("received data", "data", p.Payload, "participant", identity)
case *livekit.SipDTMF:
logger.Infow("received dtmf", "digits", p.Digit, "participant", identity)
default:
logger.Infow("received unsupported data", "data", p, "participant", identity)
}
},
OnConnectionQualityChanged: func(update *livekit.ConnectionQualityInfo, p lksdk.Participant) {
logger.Debugw("connection quality changed", "participant", p.Identity(), "quality", update.Quality)
Expand Down Expand Up @@ -820,11 +835,12 @@ func joinRoom(ctx context.Context, cmd *cli.Command) error {
}
}

if cmd.StringSlice("publish") != nil {
exitAfterPublish := cmd.Bool("exit-after-publish")
if publish := cmd.StringSlice("publish"); publish != nil {
rektdeckard marked this conversation as resolved.
Show resolved Hide resolved
fps := cmd.Float("fps")
for _, pub := range cmd.StringSlice("publish") {
for _, pub := range publish {
onPublishComplete := func(pub *lksdk.LocalTrackPublication) {
if cmd.Bool("exit-after-publish") {
if exitAfterPublish {
close(done)
return
}
Expand All @@ -839,6 +855,26 @@ func joinRoom(ctx context.Context, cmd *cli.Command) error {
}
}

publishPacket := func(p lksdk.DataPacket) error {
if err = room.LocalParticipant.PublishDataPacket(p, lksdk.WithDataPublishReliable(true)); err != nil {
return err
}
if exitAfterPublish {
close(done)
}
return nil
}
if data := cmd.String("publish-data"); data != "" {
if err = publishPacket(&lksdk.UserDataPacket{Payload: []byte(data)}); err != nil {
return err
}
}
if dtmf := cmd.String("publish-dtmf"); dtmf != "" {
if err = publishPacket(&livekit.SipDTMF{Digit: dtmf}); err != nil {
return err
}
}

<-done
return nil
}
Expand Down
Loading