当广播实际上是一个对象时,为什么在文档中将广播描述为标志? [英] Why is the broadcast described as flag in the docs when it is actually an object?

查看:102
本文介绍了当广播实际上是一个对象时,为什么在文档中将广播描述为标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

广播消息部分中 http://socket.io/docs/#broadcasting-messages 有以下说明

要广播,只需添加广播标志以发出和发送方法 电话.广播意味着向其他人发送消息 用于启动它的套接字.服务器

To broadcast, simply add a broadcast flag to emit and send method calls. Broadcasting means sending a message to everyone else except for the socket that starts it. Server

var io = require('socket.io').listen(80);

io.sockets.on('connection', function (socket) {
  socket.broadcast.emit('user connected');
});

广播是一个对象.为什么文档说明将其称为标记

The broadcast is an object. Why does the doc description refers it as flag

推荐答案

在socket.io实现的内部,broadcast是一个标志,该标志随emit发送,告诉底层基础结构该怎么做.请参阅该标记的来源,您可以在此处在源中查看为套接字上的该标志确定是否应广播给定的emit.

Internally in the socket.io implementation, broadcast is a flag that is sent with an emit that tells the underlying infrastructure what to do. See the source for that flag here and you can see here in the source where it tests for that flag on a socket to decide if a given emit should be broadcast.

socket.broadcast.emit()中的broadcast确实是一个对象.

The broadcast in socket.broadcast.emit() is indeed an object.

broadcast也是socket.io内部使用的适配器对象上的方法.因此,他们几乎将所有术语(标志,对象,方法)都使用了该术语.在您引用的情况下,该文档有一些不同的用法.

broadcast is also a method on the adapter object which is used internally by socket.io. So, they've used the term for just about everything (flag, object, method). The doc has a few of the different uses confused in the case you reference.

socket.io文档就是它的样子(不尽如人意).我发现在Github上不断引用源代码,甚至在调试器中追溯执行对于理解事物的工作方式都是必不可少的.

The socket.io doc is what it is (not nearly as good as it could be). I find constant references to the source code on Github or even tracing into the execution in a debugger to be essential for understanding how things work.

这篇关于当广播实际上是一个对象时,为什么在文档中将广播描述为标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆