This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define webwire client implementation interface
Define an abstract implementation interface for a webwire client. Adjust tests and examples to use the new client interface.
- Loading branch information
Showing
57 changed files
with
743 additions
and
504 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
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 was deleted.
Oops, something went wrong.
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,21 @@ | ||
package client | ||
|
||
import webwire "github.com/qbeon/webwire-go" | ||
|
||
// Implementation defines a webwire client implementation interface | ||
type Implementation interface { | ||
// OnDisconnected is invoked when the client is disconnected | ||
// from the server for any reason. | ||
OnDisconnected() | ||
|
||
// OnSignal is invoked when the client receives a signal | ||
// from the server | ||
OnSignal(payload webwire.Payload) | ||
|
||
// OnSessionCreated is invoked when the client was assigned a new session | ||
OnSessionCreated(*webwire.Session) | ||
|
||
// OnSessionClosed is invoked when the client's session was closed | ||
// either by the server or the client itself | ||
OnSessionClosed() | ||
} |
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
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,42 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
|
||
webwire "github.com/qbeon/webwire-go" | ||
"github.com/qbeon/webwire-go/examples/chatroom/shared" | ||
) | ||
|
||
// OnSessionCreated implements the webwireClient.Implementation interface | ||
// it's invoked when a new session is assigned to the client | ||
func (clt *ChatroomClient) OnSessionCreated(newSession *webwire.Session) { | ||
username := newSession.Info["username"].(string) | ||
log.Printf("Authenticated as %s", username) | ||
} | ||
|
||
// OnSignal implements the webwireClient.Implementation interface. | ||
// it's invoked when the client receives a signal from the server | ||
// containing a chatroom message | ||
func (clt *ChatroomClient) OnSignal(message webwire.Payload) { | ||
var msg shared.ChatMessage | ||
|
||
// Interpret the message as UTF8 encoded JSON | ||
jsonString, err := message.Utf8() | ||
if err != nil { | ||
log.Printf("Couldn't decode incoming message: %s\n", err) | ||
} | ||
|
||
if err := json.Unmarshal([]byte(jsonString), &msg); err != nil { | ||
panic(fmt.Errorf("Failed parsing chat message: %s", err)) | ||
} | ||
|
||
log.Printf("%s: %s\n", msg.User, msg.Msg) | ||
} | ||
|
||
// OnDisconnected implements the wwrclt.Implementation interface | ||
func (clt *ChatroomClient) OnDisconnected() {} | ||
|
||
// OnSessionClosed implements the wwrclt.Implementation interface | ||
func (clt *ChatroomClient) OnSessionClosed() {} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.