Elixir Pheonix通道(FunctionClauseError)ProjectName.ModuleName.handle_in / 3中没有匹配的功能子句

时间:2019-03-15 05:54:49

标签: reactjs typescript websocket elixir phoenix-framework

通过Typescript连接到Elixir通道时,出现此错误

  

({FunctionClauseErrorProjectName.ModuleName.handle_in/3中没有匹配的功能子句

  1. 为什么会发生错误?
  2. 我该如何解决?

这是我的代码。

打字稿 chatView.tsx

import React, { Component } from 'react'
import { Socket} from 'phoenix'

type MyProps = {  };
type MyState = { message: string  };

export class Chat extends Component <MyProps, MyState> {

    static readonly sockets = new Socket("ws://127.0.0.1:4000/socket");
    static channel = Chat.sockets.channel("groups_forums:lobby", {})

    constructor(props: any) {
        super(props);

        Chat.sockets.connect()

        //bind
        this.handleChange = this.handleChange.bind(this);
        this.handleClick = this.handleClick.bind(this);
        this.handleLoad = this.handleLoad.bind(this);
        this.keyPress = this.keyPress.bind(this);

    }


    componentDidMount() {
        window.addEventListener('load', this.handleLoad);
    }

    handleLoad() {
        console.log("component loaded");

        Chat.channel.join()
            .receive("ok", (resp: any) => { console.log("Joined successfully", resp) })
            .receive("error", (resp: any) => { console.log("Unable to join", resp) })
            .receive("ignore", (resp: any) => {console.log("auth error", resp)})

        Chat.channel.onClose((close: any) => { console.log("closing bye  ", close) });


       Chat.channel.on("new:msg", msg => {
            scrollTo(0, document.body.scrollHeight)
          })

    }


    handleChange(e:any) {
        this.setState({ message: e.target.value });
   }

    keyPress(e:any){
        if (e.keyCode == 13) {
         Chat.channel.push("new:msg",{message: this.state.message},2000)   
        }
      }

    handleClick(e: any) {
        e.preventDefault();
       Chat.channel.push("new:msg", {message: this.state.message})
    }


    render() {
        return (
            <div style={{ position: "absolute", bottom: 0 }}>
                <form>
                    <p className="form-group row">
                        <input style={{ marginLeft: 20, width: 200 }} defaultValue={''} onKeyPress={this.keyPress} onChange={ this.handleChange } id="message" type="text"></input>

                        <input style={{ marginLeft: 20, marginRight: 20 }} type="button" value="send" id="button" onClick={this.handleClick}></input>
                    </p>
                </form>
            </div>
        )
    }
}

export default Chat

elixir phoenix user_socket.ex

channel "groups_forums:lobby", ChatSample.GroupsForumsChannel
ChatSample.GroupsForumsChannel中的

模块groups_forums_channel.ex是自动生成的默认模板。

我要完成的任务的简要摘要是,用户消息应广播给连接到该频道的所有成员。

1 个答案:

答案 0 :(得分:1)

错误出在我的药剂代码中,class Property(object): "Emulate PyProperty_Type() in Objects/descrobject.c" def __init__(self, fget=None, fset=None, fdel=None, doc=None): self.fget = fget self.fset = fset self.fdel = fdel if doc is None and fget is not None: doc = fget.__doc__ self.__doc__ = doc def __get__(self, obj, objtype=None): if obj is None: return self if self.fget is None: raise AttributeError("unreadable attribute") return self.fget(obj) def __set__(self, obj, value): if self.fset is None: raise AttributeError("can't set attribute") self.fset(obj, value) def __delete__(self, obj): if self.fdel is None: raise AttributeError("can't delete attribute") self.fdel(obj) def getter(self, fget): return type(self)(fget, self.fset, self.fdel, self.__doc__) def setter(self, fset): return type(self)(self.fget, fset, self.fdel, self.__doc__) def deleter(self, fdel): return type(self)(self.fget, self.fset, fdel, self.__doc__) 我应该已经包含了这段代码来处理传入的消息

group_forums_channel.ex