Session

When a client creates a connection to a server, a Session interface is created for that connection.This interface is used to interact with the client.You can get the current Session interface by calling the Session() method of the View interface.

When a session is created, it gets a custom implementation of the SessionContent interface.

type SessionContent interface {
	CreateRootView(session rui.Session) rui.View
}

This interface is created by the function passed as a parameter when creating an application by the NewApplication function.

In addition to the mandatory CreateRootView() function, SessionContent can have several optional functions:

OnStart(session rui.Session)
OnFinish(session rui.Session)
OnResume(session rui.Session)
OnPause(session rui.Session)
OnDisconnect(session rui.Session)
OnReconnect(session rui.Session)

Immediately after creating a session, the CreateRootView function is called. After creating the root View, the OnStart function is called (if implemented)

The OnFinish function (if implemented) is called when the user closes the application page in the browser

The OnPause function is called when the application page in the client's browser becomes inactive.This happens if the user switches to a different browser tab / window, minimizes the browser, or switches to another application.

The OnResume function is called when the application page in the client's browser becomes active. Also, this function is called immediately after OnStart

The OnDisconnect function is called if the server loses connection with the client. This happens either when the connection is broken.

The OnReconnect function is called after the server reconnects with the client.

The Session interface provides the following methods:

  • DarkTheme() bool returns true if a dark theme is used. Determined by client-side settings
  • TouchScreen() bool returns true if client supports touch screen
  • PixelRatio() float64 returns the size of a logical pixel, i.e. how many physical pixels form a logical. For example, for iPhone, this value will be 2 or 3
  • TextDirection() int returns the direction of the letter: LeftToRightDirection (1) or RightToLeftDirection (2)
  • Constant(tag string) (string, bool) returns the value of a constant
  • Color(tag string) (Color, bool) returns the value of the color constant
  • SetCustomTheme(name string) bool sets the theme with the given name as the current one.Returns false if no topic with this name was found. Themes named "" are the default theme.
  • Language() string returns the current interface language, for example: "en", "ru", "ptBr"
  • SetLanguage(lang string) sets the current interface language (see "Support for multiple languages")
  • GetString(tag string) (string, bool) returns a textual text value for the current language(see "Support for multiple languages")
  • Content() SessionContent returns the current SessionContent instance
  • RootView() View returns the root View of the session
  • SetTitle(title string) sets the text of the browser title/tab
  • SetTitleColor(color Color) sets the color of the browser navigation bar. Supported only in Safari and Chrome for android
  • Get(viewID, tag string) any returns the value of the View property named tag. Equivalent to
rui.Get(session.RootView(), viewID, tag)
  • Set(viewID, tag string, value interface {}) bool sets the value of the View property named tag.
rui.Set(session.RootView(), viewID, tag, value)
  • DownloadFile(path string) downloads (saves) on the client side the file located at the specified path on the server.It is used when the client needs to transfer a file from the server.
  • DownloadFileData(filename string, data [] byte) downloads (saves) on the client side a filewith a specified name and specified content. Typically used to transfer a file generated in server memory.
  • SetHotKey(keyCode KeyCode, controlKeys ControlKeyMask, fn func(Session)) - sets the function that will be calledwhen the given hotkey is pressed.