ortc

package module
v0.0.0-...-3a80498 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2015 License: MIT Imports: 16 Imported by: 2

README

Realtime Cloud Messaging Go SDK

Part of the The Realtime® Framework, Realtime Cloud Messaging (aka ORTC) is a secure, fast and highly scalable cloud-hosted Pub/Sub real-time message broker for web and mobile apps.

If your application has data that needs to be updated in the user’s interface as it changes (e.g. real-time stock quotes or ever changing social news feed) Realtime Cloud Messaging is the reliable, easy, unbelievably fast, “works everywhere” solution.

API Reference

http://godoc.org/github.com/realtime-framework/RealtimeMessaging-Go

Authors

Realtime.co

Documentation

Overview

Copyright 2015 Realtime Framework.

The ortc package implements the Go lang version of the Realtime Messaging protocol,

If your application has data that needs to be updated in the user’s interface as it changes (e.g. real-time stock quotes or ever changing social news feed) Realtime Messaging is the reliable, easy, unbelievably fast, “works everywhere” solution.

Installation:

go get github.com/realtime-framework/RealtimeMessaging-Go

Below are examples of use of the ortc package:

- Create a new instance of ortc client:

client, onConnected, onDisconnected, onException, onMessage, onReconnected, onReconnecting, onSubscribed, onUnsubscribed := ortc.NewOrtcClient()

- Using the channels received on the ortc client:

	//Create a go routine that start listening from the Ortc events channels.
	go func() {
		for {
		select {
			case sender := <-onConnected:
				fmt.Println("CLIENT CONNECTED TO: " + sender.GetUrl())
			case sender := <-onDisconnected:
				fmt.Println("CLIENT DISCONNECTED FROM: " + sender.GetUrl())
			case sender := <-onException:
				fmt.Println("CLIENT EXCEPTION: " + sender.Err)
			case msgObj := <-onMessage:
				fmt.Println("RECEIVED MESSAGE: " + msgObj.Message + " ON CHANNEL: " + msgObj.Channel)
			case sender := <-onReconnected:
				fmt.Println("CLIENT RECONNECTED TO: " + sender.GetUrl())
			case sender := <-onReconnecting:
				fmt.Println("CLIENT RECONNECTING TO: " + sender.GetUrl())
			case sender := <-onSubscribed:
				fmt.Println("CLIENT SUBSCRIBED TO: " + sender.Channel)
			case sender := <-onUnsubscribed:
				fmt.Println("CLIENT UNSUBSCRIBED FROM: " + sender.Channel)
			}
 		}
	}()

- Connect to a ortc server:

client.Connect("YOUR_APPLICATION_KEY", "myToken", "GoApp", "http://ortc-developers.realtime.co/server/2.1", true, false)

- Disconnect from ortc server:

client.Disconnect()

- Disable presence on a channel:

ch := make(chan ortc.PresenceType)

go func() {
		msg := <-ch
		if msg.Err != nil {
			fmt.Println(msg.Err.Error())
		} else {
			fmt.Println(msg.Response)
		}
		channelConsole <- true
	}()

	ortc.DisablePresence("http://ortc-developers.realtime.co/server/2.1", true, "YOUR_APPLICATION_KEY", "YOUR_PRIVATE_KEY", "my_channel", ch)

- Enable presence on a channel:

 ch := make(chan ortc.PresenceType)
	go func() {
		msg := <-ch
		if msg.Err != nil {
			fmt.Println(msg.Err.Error())
		} else {
			fmt.Println(msg.Response)
		}
	}()

	ortc.EnablePresence("http://ortc-developers.realtime.co/server/2.1", true, "YOUR_APPLICATION_KEY", "YOUR_PRIVATE_KEY", "my_channel", ch)

- Get presence on channel:

 ch := make(chan ortc.PresenceStruct)
 go func() {
	 msg := <-ch
	 if msg.Err != nil {
		fmt.Println(msg.Err.Error())
	 } else {
		fmt.Println("Subscriptions - ", msg.Result.Subscriptions)

		for key, value := range msg.Result.Metadata {
			fmt.Println(key + " - " + strconv.Itoa(value))
		}
	  }
  }()

 ortc.GetPresence("http://ortc-developers.realtime.co/server/2.1", true, "YOUR_APPLICATION_KEY", "myToken", "my_channel", ch)

- Save Authentication:

permissions := make(map[string][]authentication.ChannelPermissions)

yellowPermissions := []authentication.ChannelPermissions{} yellowPermissions = append(yellowPermissions, authentication.Write) yellowPermissions = append(yellowPermissions, authentication.Presence)

testPermissions := []authentication.ChannelPermissions{} testPermissions = append(testPermissions, authentication.Read) testPermissions = append(testPermissions, authentication.Presence)

permissions["yellow:*"] = yellowPermissions permissions["test:*"] = testPermissions

if ortc.SaveAuthentication("http://ortc-developers.realtime.co/server/2.1", true, "myToken", false, "YOUR_APPLICATION_KEY", 14000, "YOUR_PRIVATE_KEY", permissions) {
	fmt.Println("Authentication successful")
} else {
	fmt.Println("Unable to authenticate")
}

- Send message to a channel:

client.Send("my_channel", "Hello World!")

- Subscribe to a channel:

client.Subscribe("my_channel", true)

- Unsubscribe from a channel:

client.Unsubscribe("my_channel")

More documentation about the Realtime Messaging service (ORTC) can be found at: http://messaging-public.realtime.co/documentation/starting-guide/overview.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisablePresence

func DisablePresence(url string, isCluster bool, applicationKey string, privateKey string, channel string, callback chan<- PresenceType)

DisablePresence disables presence for the specified channel. If success writes the result to the callback channel. An error is returned if there was an error on the request.

func EnablePresence

func EnablePresence(url string, isCluster bool, applicationKey string, privateKey string, channel string, metadata bool, callback chan<- PresenceType)

EnablePresence enables presence for the specified channel. If success writes the result to the callback channel. An error is returned if there was an error on the request.

func GetPresence

func GetPresence(url string, isCluster bool, applicationKey string, authenticationToken string, channel string, callback chan<- PresenceStruct)

Gets the subscriptions in the specified channel and if active the first 100 unique metadata. If success writes the result to the callback channel. An error is returned if there was an error on the request.

func SaveAuthentication

func SaveAuthentication(url1 string, isCluster bool, authenticationToken string, authenticationTokenIsPrivate bool, applicationKey string,
	timeToLive int, privateKey string, permissions map[string][]authentication.ChannelPermissions) bool

SaveAuthentication saves the authentication token channels permissions in the ORTC server. It returns true if authentication succeeds, otherwise false.

Types

type OrtcClient

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

func NewOrtcClient

func NewOrtcClient() (c *OrtcClient, onConnected <-chan *OrtcClient, onDisconnected <-chan *OrtcClient, onException <-chan exceptionOrtc,
	onMessage <-chan onMessageChannel, onReconnected <-chan *OrtcClient, onReconnecting <-chan *OrtcClient, onSubscribed <-chan subsOrtc,
	onUnsubscribed <-chan subsOrtc)

NewOrtcClient creates a new instance of OrtcClient. It returns the client instance and the correspondant ortc callback event channels for the client.

func (*OrtcClient) Connect

func (client *OrtcClient) Connect(applicationKey, authenticationToken, metadata, serverUrl string, isCluster, needsAuthentication bool)

Connect connects the ortc client to the url previously specified.

func (*OrtcClient) Disconnect

func (c *OrtcClient) Disconnect()

Disconnect closes the current connection of the ortc client.

func (*OrtcClient) GetUrl

func (client *OrtcClient) GetUrl() string

GetUrl returns the url of the ortc client connection.

func (*OrtcClient) Send

func (client *OrtcClient) Send(channel, message string)

Send sends a message to the specified channel.

func (*OrtcClient) Subscribe

func (c *OrtcClient) Subscribe(channel string, subscribeOnReconnect bool) <-chan onMessageChannel

Subscribe subscribes the specified channel in order to receive messages in that channel.

func (*OrtcClient) Unsubscribe

func (c *OrtcClient) Unsubscribe(channel string)

Stop receiving messages in the specified channel.

type PresenceStruct

type PresenceStruct struct {
	Err    error
	Result presence
}

PresenceStruct is the callback channel type of GetPresence() method. It contains the field Err of type error and Result of with the number of subscriptions and the map of metadata. If there was an error Err is not nil and Result empty, otherwise Err is nil and Result not empty.

type PresenceType

type PresenceType struct {
	Err      error
	Response string
}

PresenceType is the callback channel type of Disable/EnablePresence() methods. It contains the field Err of type error and a Response string. If there was an error Err is not nil and Response empty, otherwise Err is nil and Response is not empty.

Directories

Path Synopsis
authentication channelpermissions
authentication channelpermissions
examples
OrtcConsole
OrtcConsole document OrtcConsole project main.go
OrtcConsole document OrtcConsole project main.go
Sample
Sample document Sample project main.go
Sample document Sample project main.go

Jump to

Keyboard shortcuts

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