From 3c2778e8f0f3fa204ce429fa112b476aa7d8ce24 Mon Sep 17 00:00:00 2001 From: Matthew Nelson - Silverark Date: Wed, 14 Oct 2020 12:22:20 +0100 Subject: [PATCH] Update Readme to show how to edit the PingInterval Took me some time to figure this out, although fairly obvious once I found it. Also added examples of receiving data as a client and switching based on the type of data received, this took me a while to work out too. --- README.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dde3d87..f5354cc 100644 --- a/README.md +++ b/README.md @@ -149,12 +149,38 @@ var socket = io('ws://yourdomain.com', {transports: ['websocket']}); transport.GetDefaultWebsocketTransport(), ) - //do something, handlers and functions are same as server ones + //do something, handlers and functions are same as server ones. Example showing data poassed through and a switch on the data type being received. + _ = s.Client.On("callEventFromServer", func(c *gosocketio.Channel, j *interface{}) { + + switch dataType := (*j).(type) { + case map[string]interface{}: + fmt.Println("received a map[string]interface:", dataType) + default: + fmt.Printf("Unknown data type received in websocket: %v data: %v", dataType, *j) + } + + }) + + _ = s.Client.On("getFaceCount", func(c *gosocketio.Channel) { + log.Printf("on getFaceCount with no message:\n") + }) //close connection c.Close() ``` +To configure custom transport settings, like changing the default PingInterval: +``` + tr := transport.GetDefaultWebsocketTransport() + tr.PingInterval = 20 * time.Second + + c, err := gosocketio.Dial( + connectionUrl, + tr, + ) +``` + + ### Roadmap 1. Tests