wshub

package module
v0.0.0-...-dd2057b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2013 License: Apache-2.0 Imports: 7 Imported by: 2

README

Golang Websocket Chat

This is a websocket-based chat library with examples; it uses Garyburd's websocket library, and is deeply inspired by his examples. Please see http://gary.beagledreams.com/page/go-websocket-chat.html for more details.

Usage

Connections represent websocket connections from individual users. Those users can register with hubs, which are, in essence, chat rooms. Messages sent to a hub will be received by every user subscribed to a hub (i.e., to every user who has connected via a websocket which has not timed out or been closed).

See the "examples" section for working usage examples.

Documentation

Overview

Websocket-Hub is heavily derived from Gary Burd's example chat service, and much of this is copyright Gary Burd, used under the Apache License, Version 2.0 ( https://github.com/garyburd/go-websocket#license )

The remainder is copyright 2013 James Pirruccello. The entire work is offered under the Apache License, Version 2.0.

Websocket-Hub is heavily derived from Gary Burd's example chat service, and much of this is copyright Gary Burd, used under the Apache License, Version 2.0 ( https://github.com/garyburd/go-websocket#license )

The remainder is copyright 2013 James Pirruccello. The entire work is offered under the Apache License, Version 2.0.

Websocket-Hub is heavily derived from Gary Burd's example chat service, and much of this is copyright Gary Burd, used under the Apache License, Version 2.0 ( https://github.com/garyburd/go-websocket#license )

The remainder is copyright 2013 James Pirruccello. The entire work is offered under the Apache License, Version 2.0.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastAll

func BroadcastAll(input []byte)

BroadcastAll sends a message to every client on every hub

func GetHub

func GetHub(id string) *hub

GetHub retrieves the hub with a given ID from the hubMap. If no such hub exists, it creates it.

func Initialize

func Initialize(writeWait, readWait, pingPeriod time.Duration, maxMessageSize, broadcastMessageSize int64)

func Launch

func Launch(ws *websocket.Conn, id string)

TODO(james): When registering the handler, pull out the ID that they registered on. That will be the channel ID, which determines which hub they register upon. Each hub will exist as a separate goroutine. Thus, each page will have a different non-blocking hub, but all messages on a given page will be in order. TODO(james): When sending new data over the socket, look up all parent IDs in an ancestry cache; if that's empty then check DB. Finally, send the data to anyone registered to any ancestor channels. Launch handles all transactions over a websocket connection for a given hub

func Multicast

func Multicast(message []byte, ids []string)

Multicast sends a message to all hubs listed in []ids. If no such hub exists, nothing happens.

func NewConnection

func NewConnection(ws *websocket.Conn, send chan []byte) *connection

func Packetize

func Packetize(event string, data interface{}) ([]byte, error)

Packetize takes in an event name and arbitrary data and returns a stringified json object converted to a bite slice.

Types

type Packet

type Packet struct {
	Event string
	Data  interface{}
}

Packet provides structure for applying json callbacks

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL