// Blocks on callbacks from the core. // TODO: trigger a close meta callback when connection is lost func (a *App) Receive() { Debug("Starting receive") for { cb := a.conn.app.CallbackListen() core.Debug("Have callback: %v", cb) if cb.Id == 0 { // Trigger onLeave for all domains core.Info("Terminating receive loop") return } if fn, ok := a.subscriptions[cb.Id]; ok { fn.Invoke(cb.Args) } if fn, ok := a.registrations[cb.Id]; ok { core.Debug("Invocation: %v", cb.Args) ret := fn.Invoke(cb.Args[1:]...) a.conn.app.Yield(cb.Args[0].(uint64), []interface{}{ret.Interface()}) } } }
func (c Conn) Close(reason string) error { core.Debug("Asked to close: ", reason) //TODO: Use appropriate error codes c.wrapper.Get("conn").Call("close", 1000, reason) return nil }
func Open(url string) (*WebsocketConnection, error) { core.Debug("Opening ws connection to %s", url) dialer := websocket.Dialer{Subprotocols: []string{"wamp.2.json"}} if conn, _, err := dialer.Dial(url, nil); err != nil { core.Debug("Cant dial connection: %e", err) return nil, err } else { connection := &WebsocketConnection{ conn: conn, lock: &sync.Mutex{}, payloadType: websocket.TextMessage, } go connection.run() return connection, nil } }
func Debug(s string) { core.Debug("%s", s) }
//export Debug func Debug(s *C.char) { core.Debug("%s", C.GoString(s)) }