Trait/Object

io.youi.communication

Communication

Related Docs: object Communication | package communication

Permalink

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

@server
annotation. 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
@client
annotation instead. The return type of the method must be of
Future
or 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

Var
because 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):
  
    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. 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):
  
    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. Var
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):
  
    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. 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):
  
    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. Future
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
Var
because 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):
  
    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. 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):
  
    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. Var
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):
  
    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. 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):
  
    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. @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
@client
annotation instead. The return type of the method must be of
Future
or 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
Var
because 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):
  
    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. 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):
  
    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. Var
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):
  
    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. 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):
  
    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. Future
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
Var
because 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):
  
    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. 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):
  
    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. Var
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):
  
    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. 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):
  
    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
ErrorSupport, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Communication
  2. ErrorSupport
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def connection: Connection

    Permalink

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. val comm: CommunicationInternal

    Permalink
  7. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def error(t: Throwable): Unit

    Permalink
    Definition Classes
    ErrorSupport
  10. def errorSupport[R](f: ⇒ R): R

    Permalink
    Definition Classes
    ErrorSupport
  11. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  15. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. macro def shared[T](default: T): Var[T]

    Permalink
  19. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  20. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  21. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from ErrorSupport

Inherited from AnyRef

Inherited from Any

Ungrouped