2013-10-20 19 views
1

Hye Geeks。我正在为我的项目中的实时通知模块编码。我打算从一个函数调用WebSocket Action方法将通知数据通过连接传递给客户端。
这里是我的代码..WebSocket动作调用在运行时忽略

def liveNotification(data: String) = WebSocket.using[JsValue] { implicit request => 
    val iteratee = Iteratee.ignore[JsValue] 
    val enumerator = Enumerator[JsValue](Json.toJson(data)) 
    (iteratee,enumerator) 
} 

def createNotification(notificationTo: BigInteger, notiParams:Tuple5[String,String,BigInteger,BigInteger,BigInteger]) = {  
    val retData = NotificationModel.createNotification(notificationTo,notiParams) 
    val strData = write(retData) 
    liveNotification(strData) 
} 

的问题是, 'liveNotification()' 呼叫会被忽略。请帮我提供一些我在做什么错误的建议?

回答

0

一定要用一个Json值,至少一个空对象来调用它。解析器只能匹配它识别为Json的东西。

+0

但我的功能是采取'字符串'参数。由于我对传入消息不感兴趣,我忽略了'Iteratee'并通过枚举器将'data'作为'JsValue'发送出去。编译器不会给出任何错误,即使在运行时也不会出现任何错误,但函数不会被调用。 –

相关问题