Skip to content
This repository was archived by the owner on May 8, 2023. It is now read-only.
Open
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
25 changes: 25 additions & 0 deletions pagecall/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package pagecall

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -73,6 +75,11 @@ type PageCallClient interface {
Terminate the room.
*/
TerminateRoom(roomID string) (*room, error)

/*
Using the post action to sessions feature, the according script can be executed within the connected session client.
*/
PostActionToSessions(sessionIDs []string, script string) error
}

type pageCallClient struct {
Expand Down Expand Up @@ -121,3 +128,21 @@ func (p pageCallClient) request(method string, path string, payload io.Reader) (
func (p pageCallClient) BuildURLToJoinRoom(roomID string, accessToken string) string {
return fmt.Sprintf("%s/%s?access_token=%s", AppDomain, roomID, accessToken)
}

func (p pageCallClient) PostActionToSessions(sessionIDs []string, script string) error {
reqBody := make(map[string]interface{})
reqBody["type"] = "run_script"
reqBody["session_ids"] = sessionIDs
reqBody["script"] = script

ubytes, _ := json.Marshal(reqBody)
payload := bytes.NewBuffer(ubytes)

_, err := p.request("POST", "/post_action_to_sessions", payload)

if err != nil {
return err
}

return nil
}
4 changes: 4 additions & 0 deletions pagecall/pagecall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func TestPageCallSDK(t *testing.T) {

assert.NoError(t, err)

err = client.PostActionToSessions([]string{}, "console.log(\"Hello, World!\")")

assert.NoError(t, err)

terminatedRoom, err := client.TerminateRoom(room.ID)

assert.NoError(t, err)
Expand Down