本文整理汇总了TypeScript中sockets.comm_socket类的典型用法代码示例。如果您正苦于以下问题:TypeScript comm_socket类的具体用法?TypeScript comm_socket怎么用?TypeScript comm_socket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了comm_socket类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
comm_socket.on("connect", () => {
let list = [];
for (let id in state) {
list.push(id);
}
if (list.length) {
comm_socket.send("user/monitor", list);
}
});
示例2: setTimeout
setTimeout(() => {
comm_socket.send("user/monitor", subscribe_queue);
subscribe_queue = null;
}, 1);
示例3:
send: (event, data) => {
comm_socket.send("itc", {"event": event, "data": data});
}
示例4: EventEmitter
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {comm_socket} from "sockets";
import {EventEmitter} from "eventemitter3";
let listeners: {[id: number]: Array<any>} = {};
let state = {};
let event_emitter = new EventEmitter();
comm_socket.on("connect", () => {
let list = [];
for (let id in state) {
list.push(id);
}
if (list.length) {
comm_socket.send("user/monitor", list);
}
});
comm_socket.on("user/state", (states) => {
let i;
for (let id in states) {
state[id] = states[id];
for (i = 0; i < listeners[id].length; ++i) {
listeners[id][i](id, state[id]);
}
}
event_emitter.emit("users-online-updated");
});