openfire广播消息_利用Broadcast插件实现广播消息发送

2013年1月4日,新年第一篇~~

技术研究的过程充满了惊喜,今天深深的就这么感受到了,仅仅试验了一次,就收获到了成功。

第一步:安装broadcast插件


管理员身份登录控制台,Broadcast插件在Available Plugins中,选中安装即可。

第二步:查看使用说明

http://www.igniterealtime.org/projects/openfire/plugins/broadcast/readme.html

Broadcast Plugin Readme 
Overview
The broadcast plugin broadcasts messages to all users in the system or to specific groups. It's primarily useful for sending announcements or notifications. 

Installation
Copy broadcast.jar into the plugins directory of your Openfire installation. The plugin will then be automatically deployed. To upgrade to a new version, copy the new broadcast.jar file over the existing file.

Configuration
The broadcast plugin is configured via Openfire system properties. These can be configured under Server/Server Manager/System Properties: 
plugin.broadcast.serviceName -- the name of the broadcast service. If no value is set, the default is "broadcast". 
plugin.broadcast.disableGroupPermissions -- true to allow any user to broadcast a message to a group. When false, only group members or administrators can broadcast messages to a group. The default value is false. 
plugin.broadcast.groupMembersAllowed -- true to also allow group members to send broadcast messages to groups they belong to. When false, only administrators can send broadcast messages to a group. The default value is true. Note that the property value of plugin.broadcast.disableGroupPermissions can effectively override this value by letting anyone send broadcast messages to groups. 
plugin.broadcast.allowedUsers -- the comma-delimitted list of users allowed to broadcast messages to all connected users at once. When this property isn't set, anyone is allowed to broadcast messages to all users. Users should be specified by their bare JID (e.g. john@myserver.com) 
plugin.broadcast.all2offline -- true to deliver broadcast messages sent to all@[serviceName].[serverName] to online and offline users. When false or not set only online users get the messages as described below. 
plugin.broadcast.messagePrefix -- Add a prefix for all broadcast messages. Set this to "(broadcast)" to prepend "(broadcast) ". 
Using the Plugin
To send a broadcast message, send a message to all@[serviceName].[serverName] or [group]@[serviceName].[serverName]. For example, if your server is called foo and the default service name is being used, a message to all@broadcast.foo would be broadcast to all users connected to the server. For the group staff, a message to staff@broadcast.foo would be sent to all users in the group staff that are currently online or offline. 
Note: for maximum compatability between group implementations, it's recommended that you use lower-case group names in conjunction with the broadcast plugin. 
讲述的很细致,通读一遍应该就懂该怎么弄了。

第三步:引入jsjac.js文件,编写广播消息方法(查看jsjac.js说明,请点击这里)

//send broadcast message dml@2013.1.4
	function sendBCMsg() {
		var body = document.getElementById("broadcastMsg").value;
		body = body.replace(/\'/ig, "\"");

		if (body.length > 2048) {
			alert("发送消息内容超长,请分条发送。");
			return;
		}
		if (body == '') // don't send empty message
			return false;
		var aMessage = new JSJaCMessage();
		aMessage.setType('chat');
		aMessage.setTo('all@broadcast.xjtu');//all@[serviceName].[serverName]
		aMessage.setBody(body);

		var jwcMain = opener.top;
		jwcMain.con.send(aMessage);
		window.close();
		return false;
	}
将发送目标更改为all@服务名.服务器名即可,如果需要按照组广播,只需将all更改为具体的组名。

第四步:执行sendBCMsg方法,测试


p.s.元旦放假这几天,试做了OCP JAVA SE 6 Programmer认证考试的试题,感觉对自己帮助很大,如果哪位朋友也感兴趣,请添加QQ280587412,共同进步~~

dml@2013.1.4



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值