|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionMicrosoft has made it possible for developers to write their own MSN Messenger Activities. These activities are peer to peer since each user is connected through the MSN Messenger network. They can also be client to server at the same time since the activity web page is hosted on your own server. In this article, I will discuss some of the code that is specific to MSN Messenger peer to peer communication as well as a trick or two I used in my own activity (CodeTalk) to overcome some of the restrictions that Microsoft set on these web pages by default, i.e. no ActiveX. BackgroundPeer to peer software is where an application allows people on the Internet to communicate with each other (usually in real time) rather than simply communicating with a server. Examples of these types of applications would include chat, file sharing, and white boarding. The MSN Messenger system is a peer to peer application that offers all of these abilities and a lot more. To enable the peer to peer capability to activity authors, MSN Messenger provides some objects that can be called to gather information about the session as well as send/receive data between the peers. Using the codeMSN Messenger is an Internet Explorer host. As such, it can expose an additional object model to any code (JavaScript) running inside a web page within MSN Messenger. At present, the objects exposed are...
Sending information to a peer is as simple as the following code snippet ... window.external.Channel.SendData("Some data");
and receiving data requires implementing an event handler like this... function Channel_OnDataReceived()
{
var myData;
myData=window.external.Channel.Data;
}
That is really the meat of communicating back and forth between peers. You can get as complex as you want in deciding what data to send and how to parse it out on the other end of the connection, then taking an action based on the data received. There are a lot of possibilities here. Games and various kinds of collaboration tools such as shared searching or web browsing come quickly to mind. Microsoft puts a limit on how much data you can send over their network within a specific period of time. Currently, this is 1,664 bytes per packet and a maximum bandwidth of 120 packets per minute (two per second). This may not sound like a lot of data, however, it actually is quite a bit of data, and with a little creativity, you can find ways to enhance your performance using techniques such as caching or look up tables. In the case of my activity, CodeTalk, I wanted to incorporate the MSN Search Webservice to do on-the-fly searching based on what text the user currently had highlighted. My first attempt used the
This trick implements an asynchronous web service call without using any ActiveX and without any real web service! Here are the main points...
This is the HTML + JavaScript that your ASPX page wraps your web method results with before sending it up to the <HTML><body id=bdy
onload=window.parent.document.all.myTextArea.innerText=bdy.innerHTML;>
YOUR_RESULTS</body></HTML>
When the Your <TEXTAREA id="myTextArea"
onpropertychange="AfterWebMethod();" style=display:none;></TEXTAREA>
And your function AfterWebMethod()
{
if(myTextArea.innerText.length>0)
{
//Do something with the innerText contents
//Be sure to reset the innerText for next time
myTextArea.innerText = "";
}
}
More tipsAnother useful trick when making MSN Messenger Activities can be the ability to simulate a mouse pointer on the other user's screen. The technology used to do this is built right into Internet Explorer. This technology is called VML (Vector Markup Language). The following code will show how to create a function that will draw what looks like a mouse pointer on screen at any point you want. In the document.body.onmousemove = MouseMoved;
Now, you will get alerted each time the mouse moves over the body of your page. If you prefer, you can limit this event to a smaller part of your page such as a The function MouseMoved()
{
//Get the X and Y with a small adjustment
//to get the actual tip of the pointer
var mLeft = event.clientX-2;
var mTop = event.clientY-7;
//Create a pipe (|) delimited string that
//will hold all the data needed to recreate
//the mouse pointer on the other peers
var data = "";
data += mLeft + "|" + mTop;
data += "|" + document.body.clientWidth + "|" +
document.body.clientHeight;
//Send this data to other peers
window.external.Channel.SendData(data);
}
Now, you need to capture this data on the peers and parse out the data. function Channel_OnDataReceived()
{
var myData;
myData=window.external.Channel.Data;
//Split on the pipe (|) delimiter into an array
var mouseData = myData.split("|");
//Call MoveMouse to draw the mouse in the correct location
MoveMouse(parseInt(mouseData[0]), parseInt(mouseData[1]),
parseInt(mouseData[2]), parseInt(mouseData[3]));
}
Finally, let's take a look at the function MoveMouse(x, y, clientWidth, clientHeight)
{
var xRatio = 0;
var yRatio = 0;
var prevX = 0;
var prevY = 0;
var myWidth = parseInt(document.body.clientWidth);
var myHeight = parseInt(document.body.clientHeight);
//Reposition the pointer to take into account
//different screen sizes between peers
//find the ratio between the incoming peers
//client area and my client area
xRatio = myWidth/clientWidth;
yRatio = myHeight/clientHeight;
//Move the incoming X and Y
x = (x + ((myWidth)-(clientWidth*xRatio))*xRatio);
y = (y + ((myHeight)-(clientHeight*yRatio))*yRatio);
//Arrange the VML lines into a mouse pointer
//and move to the x,y
line1.from = x + "," + y;
line1.to = x + 12 + "," + (y + 11);
prevX = x + 15;
prevY = y + 12;
line2.from = line1.to;
prevX -= 8;
prevY -= 1;
line2.to = prevX + "," + prevY;
line3.from = line2.to;
prevX += 4;
prevY += 8;
line3.to = prevX + "," + prevY;
line4.from = line3.to;
prevX -= 3;
prevY += 1;
line4.to = prevX + "," + prevY;
line5.from = line4.to;
prevX -= 4;
prevY -= 8;
line5.to = prevX + "," + prevY;
line6.from = line5.to;
prevX -= 4;
prevY += 5;
line6.to = prevX + "," + prevY;
line7.from = line6.to;
line7.to = line1.from;
}
Don't forget to include the VML tags for the lines that make up the pointer... <!--[if !mso]>
<STYLE>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</STYLE>
<![endif]-->
<v:line id="line1" from="7500pt,7500pt" to="7500pt,7500pt"></v:line>
<v:line id="line2" from="7500pt,7500pt" to="7500pt,7500pt"></v:line>
<v:line id="line3" from="7500pt,7500pt" to="7500pt,7500pt"></v:line>
<v:line id="line4" from="7500pt,7500pt" to="7500pt,7500pt"></v:line>
<v:line id="line5" from="7500pt,7500pt" to="7500pt,7500pt"></v:line>
<v:line id="line6" from="7500pt,7500pt" to="7500pt,7500pt"></v:line>
<v:line id="line7" from="7500pt,7500pt" to="7500pt,7500pt"></v:line>
And put this at the top of your page instead of a regular <html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office">
Points of Interest
|
||||||||||||||||||||||