upnp

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

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

Go to latest
Published: Oct 26, 2016 License: MIT Imports: 6 Imported by: 3

README

upnp

upnp library for go

##Documentation See godoc

##Installation

go get github.com/go-home-iot/upnp

##Package

import "github.com/go-home-iot/upnp"

##Usage See upnp_test.go for detailed examples of how to use this library.

server := upnp.NewSubServer()

// Start the server, this will listen for upnp events
go func() {
	err := s.Start("127.0.0.1:9001")
	fmt.Println(err)
}()

// Subscriber who will get the notification events
sub := &MockSubscriber{}

// Subscribe to the devices events
sid, err := s.Subscribe(
	"http://127.0.0.1:9002/upnp/event/basicevent1",  //URL of devices event service
	"", //SID - pass in to renew a subscription
	50, //Time in seconds to maintain the subscription
	false, // Autorenew subscription
	sub, // Instance who will receive notifications, implementing upnp.Subscriber interface
)

type MockSubscriber struct {
	NotifyCount int
	Event       upnp.NotifyEvent
}

func (s *MockSubscriber) UPNPNotify(e upnp.NotifyEvent) {
	s.NotifyCount++
	s.Event = e
}

##Version History ###0.1.0 Initial release - support SUBSCRIBE/UNSUBSCRIBE/NOTIFY for devices

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NotifyEvent

type NotifyEvent struct {
	// SID is the unique ID returned to the called when they subscribed to the event
	SID string

	// Body is the response from the server, the caller is responsible for parsing it
	Body string
}

NotifyEvent contains information about a notify event instance

type SubServer

type SubServer struct {
	// contains filtered or unexported fields
}

SubServer is a upnp subscription server. Do not create directly, you must call NewSubServer to return a working instance of this type

func NewSubServer

func NewSubServer() *SubServer

NewSubServer returns a new an inited SubServer instance

func (*SubServer) RefreshSubscription

func (s *SubServer) RefreshSubscription(sid string, autoRefresh bool) error

RefreshSubscription refreshes the subscription to the service.

func (*SubServer) Start

func (s *SubServer) Start(listenAddr string) error

Start starts a web server at the specified address which listens for upnp NOTIFY events. listenAddr is the address the upnp type uses to listen for notifications as the callback to the SUBSCRIBE call. e.g. 192.168.0.9:9000

func (*SubServer) Subscribe

func (s *SubServer) Subscribe(serviceURL, sid string, timeoutInSeconds int, autoRefresh bool, sub Subscriber) (string, error)

Subscribe signs up to receive events when there are new NOTIFY messages from the device. The function returns the SID returned by the device, once it has been successfully subscribed to. You will need to keep the SID to unsubscribe.

func (*SubServer) Unsubscribe

func (s *SubServer) Unsubscribe(sid string) error

Unsubscribe unsubscribes from the events associated with the specified sid

type Subscriber

type Subscriber interface {
	UPNPNotify(e NotifyEvent)
}

Subscriber is an interface for types that want to get events from a device

Jump to

Keyboard shortcuts

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