-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
52 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,41 @@ | ||
package handler | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
|
||
"github.com/tockn/singo/model" | ||
) | ||
|
||
type ReceiveMessageType string | ||
|
||
var ( | ||
ReceiveMessageTypeJoinRoom ReceiveMessageType = "join" | ||
ReceiveMessageTypeOffer ReceiveMessageType = "offer" | ||
ReceiveMessageTypeAnswer ReceiveMessageType = "answer" | ||
) | ||
|
||
type ReceiveMessage struct { | ||
Type ReceiveMessageType `json:"type"` | ||
Payload json.RawMessage `json:"payload"` | ||
} | ||
|
||
type ErrorMessage string | ||
|
||
func (e ErrorMessage) Error() string { | ||
return string(e) | ||
} | ||
|
||
var ( | ||
ErrMsgInvalidType ErrorMessage = "invalid type" | ||
ErrMsgInvalidPayload ErrorMessage = "invalid payload" | ||
ErrMsgInternalError ErrorMessage = "internal error" | ||
) | ||
|
||
func newErrorMessage(msg error) *model.Message { | ||
log.Println("error:", msg) | ||
return &model.Message{ | ||
Type: model.MessageTypeError, | ||
Payload: []byte(msg.Error()), | ||
} | ||
} |
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