trait Communication extends ErrorSupport
Communication provides convenience functionality to communicate between a client and server (two-way) via WebSockets. The supported mechanisms are methods and shared variables.
Method Example:
@server def time: Future[Long]
Notice the
@serverannotation. This represents that this method will be defined in the server implementation allowing the client to call the method and it is invoked on the server and the result is received on the client. To create a method in the client that is called from the server simply use the
@clientannotation instead. The return type of the method must be of
Futureor it will be ignored.
Shared Var Example:
val name: reactify.Var[String] = shared[String]("Default")
This represents a variable that is shared between the client and server. Either can change the value and it will be reflected in the other asynchronously. We use Reactify's
Varbecause it allows functional reactive observing of changes.
Note that three traits must be defined for a
Communication: 1. Shared Interface (defined as the definition of each method and shared variable):
trait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):1. Shared Interface (defined as the definition of each method and shared variable):trait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. Communicationtrait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):observing of changes. Note that three traits must be defined for atrait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. VarCommunication: 1. Shared Interface (defined as the definition of each method and shared variable):trait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):1. Shared Interface (defined as the definition of each method and shared variable):trait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. Communicationtrait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):Shared Var Example:trait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. Futureval name: reactify.Var[String] = shared[String]("Default")This represents a variable that is shared between the client and server. Either can change the value and it will be reflected in the other asynchronously. We use Reactify'sVarbecause it allows functional reactive observing of changes. Note that three traits must be defined for aCommunication: 1. Shared Interface (defined as the definition of each method and shared variable):trait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):1. Shared Interface (defined as the definition of each method and shared variable):trait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. Communicationtrait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):observing of changes. Note that three traits must be defined for atrait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. VarCommunication: 1. Shared Interface (defined as the definition of each method and shared variable):trait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):1. Shared Interface (defined as the definition of each method and shared variable):trait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. Communicationtrait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):implementation allowing the client to call the method and it is invoked on the server and the result is received on the client. To create a method in the client that is called from the server simply use thetrait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. @server@clientannotation instead. The return type of the method must be ofFutureor it will be ignored. Shared Var Example:val name: reactify.Var[String] = shared[String]("Default")This represents a variable that is shared between the client and server. Either can change the value and it will be reflected in the other asynchronously. We use Reactify'sVarbecause it allows functional reactive observing of changes. Note that three traits must be defined for aCommunication: 1. Shared Interface (defined as the definition of each method and shared variable):trait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):1. Shared Interface (defined as the definition of each method and shared variable):trait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. Communicationtrait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):observing of changes. Note that three traits must be defined for atrait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. VarCommunication: 1. Shared Interface (defined as the definition of each method and shared variable):trait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):1. Shared Interface (defined as the definition of each method and shared variable):trait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. Communicationtrait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):Shared Var Example:trait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. Futureval name: reactify.Var[String] = shared[String]("Default")This represents a variable that is shared between the client and server. Either can change the value and it will be reflected in the other asynchronously. We use Reactify'sVarbecause it allows functional reactive observing of changes. Note that three traits must be defined for aCommunication: 1. Shared Interface (defined as the definition of each method and shared variable):trait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):1. Shared Interface (defined as the definition of each method and shared variable):trait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. Communicationtrait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):observing of changes. Note that three traits must be defined for atrait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. VarCommunication: 1. Shared Interface (defined as the definition of each method and shared variable):trait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):1. Shared Interface (defined as the definition of each method and shared variable):trait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time. Communicationtrait ExampleCommunication extends Communication { @server def time: Future[Long] @client def url: Future[String] val name: Var[String] = shared[String]("Default") }2. Client Interface (defined in Scala.js code):trait ClientExampleCommunication extends ExampleCommunication { override def url: Future[String] = Future.successful(document.url.href) }3. Server Interface (defined in JVM code):trait ServerExampleCommunication extends ExampleCommunication { override def time: Future[Long] = Future.successful(System.currentTimeMillis()) }Notice that only the methods that need to be implemented on the client or server are defined. The rest are generated at compile-time.
- See also
io.youi.app.YouIApplication for usage examples
Linear Supertypes
Ordering
- Alphabetic
- By Inheritance
Inherited
- Communication
- ErrorSupport
- AnyRef
- Any
- Hide All
- Show All
Visibility
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
- val comm: CommunicationInternal
- def connection: Connection
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
error(t: Throwable): Unit
- Definition Classes
- ErrorSupport
-
def
errorSupport[R](f: ⇒ R): R
- Definition Classes
- ErrorSupport
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- macro def shared[T](default: T): Var[T]
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )