-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ssh): graceful disconnect session record websocket
- Loading branch information
1 parent
37e67c9
commit 7857c3b
Showing
3 changed files
with
40 additions
and
4 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,37 @@ | ||
package session | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/gorilla/websocket" | ||
"github.com/shellhub-io/shellhub/pkg/models" | ||
) | ||
|
||
type Camera struct { | ||
conn *websocket.Conn | ||
} | ||
|
||
// Close closes the camera's WebSocket connections normally. | ||
func (c *Camera) Close() error { | ||
if err := c.conn.WriteControl( | ||
websocket.CloseMessage, | ||
websocket.FormatCloseMessage(websocket.CloseNormalClosure, "session record connection done"), | ||
time.Now().Add(time.Minute), | ||
); err != nil { | ||
return err | ||
} | ||
|
||
return c.conn.Close() | ||
} | ||
|
||
// WriteFrame writes a session's frame into the WebSocket connection. | ||
func (c *Camera) WriteFrame(frame *models.SessionRecorded) error { | ||
return c.conn.WriteJSON(frame) | ||
} | ||
|
||
// NewCamera creates a new camera, using a WebSocket connections. | ||
func NewCamera(conn *websocket.Conn) *Camera { | ||
return &Camera{ | ||
conn: conn, | ||
} | ||
} |
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